/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;
var flashSrcHtml = "";
//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	 
	if(popupStatus==0){
		document.getElementById("backgroundPopup").style.opacity = 0.7;
		document.getElementById("backgroundPopup").style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=50,finishOpacity=100)";
		
		document.getElementById("backgroundPopup").style.display = "block";
		document.getElementById("popupContact").style.display = "block";
		popupStatus = 1;
		if(flashSrcHtml == "")
		{	
			dflashSrcHtml = document.getElementById("popupContact").innserHTML;
		}
		document.getElementById("popupContact").innserHTML = flashSrcHtml;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		document.getElementById("backgroundPopup").style.display = "none";
		document.getElementById("popupContact").style.display = "none";
		popupStatus = 0;
		document.getElementById("popupContact").innserHTML = "";
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	//var popupHeight = document.getElementById("popupContact").style.height;
	//var popupWidth = document.getElementById("popupContact").style.width;
	var popupWidth = 960;
	var popupHeight = 763;
	
	//centering
	var pc = document.getElementById("popupContact");
	pc.style.position = "absolute";
	var newTop ;
	if(windowHeight < popupHeight)
	{
			newTop =  "10px";
	}
	else
	{
		newTop = windowHeight/2-popupHeight/2 + "px";
	}
	var newLeft = windowWidth/2-popupWidth/2 + "px";	
	pc.style.top = newTop;
	pc.style.left = newLeft;	
	//only need force for IE6
	document.getElementById("backgroundPopup").style.height = windowHeight + "px";
	//alert(windowWidth);
	document.getElementById("backgroundPopup").style.width = windowWidth + "px";
	
}

//window.onload = myonload;
if (document.all){
window.attachEvent('onload',myonload)
}
else{
window.addEventListener('load',myonload,false);
}
document.keypress = mykeypress;
//CONTROLLING EVENTS IN jQuery
function openFlash(_subjectid, _styleid)
{
	

	centerPopup();
	//load popup
	loadPopup();

	locked = true;
	subjectid = _subjectid;
    styleid   = _styleid;
    locked = false;
}
function closeFlash()
{
	//flashReady = false;
	disablePopup();
}
function myonload()
{
		
		//LOADING POPUP
		//Click the button event!
		/*document.getElementById("button").onclick = function(){
			//centering with css
			centerPopup();
			//load popup
			loadPopup();
		}*/
		//CLOSING POPUP
		//Click the x event!
		//Click out event!
		var bg = document.getElementById("backgroundPopup");
		if(bg!=null)
		{	
			bg.onclick = function(){
				disablePopup();
			}
		}
		//Press Escape event!

}
function mykeypress(e)
{
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
}	
