/***************************/
// @implementing and optimizing for AT2: Alex Baskov, 2010
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatusShowreel = 0;
var showreelPlayer = 0;

//loading popup with jQuery magic!
function loadPopupShowreel()
{
	//loads popup only if it is disabled
	if(popupStatusShowreel == 0)
	{
		$("#popupShowreelBackground").css({
			"opacity": "0.7" // set to zero, if you don't want to have a background
		});
		$("#popupShowreelBackground").fadeIn("slow");
		$("#popupShowreel").fadeIn("slow");
		popupStatusShowreel = 1;
		
		if (showreelPlayer == 0)
        showreelPlayer = $f("showreel_player", "/swf/flowplayer-3.2.0.swf", {
            clip: {
                autoPlay: false,
                autoBuffering: true,
                fullScreenScriptURL: "http://theresecliffordmanagement.com.au",
                scaling: 'scale'
            },
            canvas: {
                backgroundColor: '#ffffff',
                backgroundGradient: 'none',
                borderRadius: 0
            },
            plugins: {
                controls: {
                    backgroundColor: '#E4E3E3',
                    timeColor: '#aaaaaa',
                    durationColor: '#ffffff',
                    timeBgColor: '#373737',
                    buttonColor: '#5a5a5a',
                    buttonOverColor: '#666666',
                    volumeColor: '#5a5a5a',
                    volumeSliderColor: '#ffffff',
                    sliderColor: '#ffffff',
                    progressGradient: 'medium',
                    bufferColor: '#999999',
                    progressColor: '#5a5a5a',
                    backgroundGradient: [0.6, 0.0, 1.0],
                    fontColor: '#00ffff',
                    timeFontColor: '#ffffff',
                    tooltipColor: '#5a5a5a',
                    tooltipTextColor: '#ffffff',
                    all:false,
                    play: true,
                    stop : false,
                    fullscreen: true,
                    scrubber: true,
                    mute: true,
                    volume: true,

                    playlist: false,
                    tooltips: {
                        buttons: true,
                        fullscreen: 'Enter fullscreen mode'
                    }
                }
            },
            logo: {
                fullscreenOnly: true
            }
        });
	}
}

//disabling popup with jQuery magic!
function disablePopupShowreel()
{
	//disables popup only if it is enabled
	if (popupStatusShowreel == 1)
	{
		$("#popupShowreelBackground").fadeOut("slow");
		$("#popupShowreel").fadeOut("slow");
		popupStatusShowreel = 0;
	}
}

//centering popup
function centerPopupShowreel()
{
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupShowreel").height();
	var popupWidth = $("#popupShowreel").width();

	//
	// we need here to emulate fixed position... so we use offsetHeight and offsetWidth instead
	// (c) Alex Baskov
	//
	var topScrollerPosition = 0;
	
	// we may just scroll to top and see nice popup
	//scroll(0,0);

	// center vertically in the visible area...
	topScrollerPosition = ($.browser.msie) ? document.body.scrollTop : topScrollerPosition = window.pageYOffset;
	
	//centering
	$("#popupShowreel").css({
		"position": "fixed",
		"top": windowHeight/2-popupHeight/2,
		//"top": parseInt((windowHeight-popupHeight)/2) + topScrollerPosition,
		//"top": topScrollerPosition + 60,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#popupShowreelBackground").css({
		"height": windowHeight
	});
	
}

//CONTROLLING EVENTS IN jQuery
$(document).ready(function() {

	//LOADING POPUP
	
	$("#btnShowreelHome, .artistVideo").click(function() {
		centerPopupShowreel();
		loadPopupShowreel();
	});
	
	//Click out event!
	$("#popupShowreelBackground, #popupShowreelClose").click(function() {
		disablePopupShowreel();
        $f("showreel_player").stop();
	});
	
	//Press Escape event!
	$(document).keypress(function(e) {
		if(e.keyCode == 27 && popupStatusShowreel == 1) {
			disablePopupShowreel();
		}
	});

});


