﻿
$(document).ready(function() {
    $('#popupOpenerTVC a.modalOpen').click(function(e) {
        e.preventDefault();
        // load the tvc form using ajax
        $('#popupTVC').modal({
            closeHTML: "<a href='#' title='Close' class='modalCloseX simplemodal-close'>Close X</a>",
            position: ["15%", ],
            minWidth: 640,
            overlayId: 'tvc-overlay',
            opacity: 85,
            containerId: 'tvc-container',
            onOpen: tvc.open,
            onShow: tvc.show,
            onClose: tvc.close
        });
    });

});

var tvc = {
    message: null,
    open: function(dialog) {
        // add padding to the buttons in firefox/mozilla
        if ($.browser.mozilla) {
            $('#tvc-container .tvc-button').css({
                'padding-bottom': '2px'
            });
        }
        var h = 400;
        dialog.overlay.fadeIn(200, function() {
            dialog.container.fadeIn(200, function() {
                dialog.data.fadeIn(200, function() {
                    $('#tvc-container .tvc-content').animate({
                        height: h
                    }, function() {
                        // fix png's for IE 6
                        if ($.browser.msie && $.browser.version < 7) {
                            $('#tvc-container .tvc-button').each(function() {
                                if ($(this).css('backgroundImage').match(/^url[("']+(.*\.png)[)"']+$/i)) {
                                    var src = RegExp.$1;
                                    $(this).css({
                                        backgroundImage: 'none',
                                        filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + src + '", sizingMethod="crop")'
                                    });
                                }
                            });
                        }
                        $('#innerContent').fadeIn(200, function() {
                            flowplayer("player", "swfs/flowplayer-3.1.2.swf");
                        });
                    });
                });
            });
        });
    },
    show: function(dialog) {
        //alert("Show modal tests");
    },
    close: function(dialog) {
        $('#tvc-container .tvc-message').fadeOut();
        $('#innerContent').fadeOut();
        $('#tvc-container .tvc-title').html('Goodbye...');
        $('#tvc-container form').fadeOut(200);
        $('#tvc-container .tvc-content').animate({
            height: 40
        }, function() {
            dialog.data.fadeOut(200, function() {
                dialog.container.fadeOut(200, function() {
                    dialog.overlay.fadeOut(200, function() {
                        $.modal.close();
                    });
                });
            });
        });
    },
    error: function(xhr) {
        alert(xhr.statusText);
    },
    showError: function() {
        $('#tvc-container .tvc-message')
			.html($('<div class="tvc-error">').append(tvc.message))
			.fadeIn(200);
    }
};
