/**********************************************************************/
/* Original code from Adrian "yEnS" Mato Gondelle, www.yensdesign.com */
/* updated by inexos.com		                              */
/**********************************************************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

var tbPopupIframes = new Array("popup_frame");

function loadIframe(iframename)
{
	for(i=0; i<tbPopupIframes.length; i++)
	{
		if (tbPopupIframes[i]==iframename)
		{
			document.getElementById(tbPopupIframes[i]).style.display="block";
		} 
		else
		{
			document.getElementById(tbPopupIframes[i]).style.display="none";
		}
	}
}

// load the popup
function loadPopup(mode)
{
	//loads popup only if it is disabled
	if(popupStatus==0)
	{
		if (mode=="")
		{
			mode="slow"
		}
		// background opacity
		$("#popupBackground").css({"opacity": "0.6"});
		// no fading for background
		$("#popupBackground").fadeIn(mode);
		// slow fading for the pop up
		$("#popupContent").fadeIn(mode);
		// the popup is open
		popupStatus = 1;
	}
}

//disabling popup 
function disablePopup()
{
	//disables popup only if it is enabled
	if(popupStatus==1)
	{
		// slow fading for the popup
		$("#popupContent").fadeOut("slow");
		// no fading for the background
		$("#popupBackground").fadeOut("slow");
		// we can display back the player
		$("#crosstvplayer").css({"visibility":"visible"});
		// we hide every iframe
		loadIframe("none");
		// the popup is close
		popupStatus = 0;
	}
}

// Vertical scrolling position
// http://www.softcomplex.com/docs/get_window_size_and_scrollbar_position.html
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}


//centering popup
function centerPopup()
{
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupWidth = $("#popupContent").width();
	var popupHeight = $("#popupContent").height();
	//centering
	$("#popupContent").css({
		"position": "absolute",
		"top": f_scrollTop()+windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#popupBackground").css({
		"height": windowHeight
	});
	
}

//CONTROLLING EVENTS IN jQuery
$(document).ready(function()
{
	//CLOSING POPUP
	//Click the x event!
	$("#popupContentClose").click(function(){
		disablePopup();
        return false;
	});
	//Click out event!
	$("#popupBackground").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});

