/***************************/
//@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;

//loading popup with jQuery magic!


function getWindowMeasurements() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return new Array(myWidth,myHeight);
}

function getScrollsPosition()
{

	var x = 0;
	var y = 0;

	if( typeof( window.pageYOffset ) == 'number' )
	{
		x = window.pageXOffset;
		y = window.pageYOffset;
	}
	else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) )
	{
		x = document.documentElement.scrollLeft;
		y = document.documentElement.scrollTop;
	}
	else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) )
	{
		x = document.body.scrollLeft;
		y = document.body.scrollTop;
	}

	return new Array(x,y);

}





function loadPopup(){

   
    var maxMeasures=getWindowMeasurements();
	var maxWidth=maxMeasures[0];
	var left=Math.floor((maxWidth/2)-(800/2));
    //var left = 0;
    
	var scrollsPosition=new Array();
	scrollsPosition=getScrollsPosition();
	var scrolledDown = scrollsPosition[1];

	scrolledDown+=40;
	scrolledDown=20;
	
	//alert(scrolledDown);
	document.getElementById("popupContact").style.left=left+"px";
	document.getElementById("popupContact").style.top=scrolledDown+"px";
	document.getElementById("popupContact").style.display="block";
	
   
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.6"
		});
		$("#backgroundPopup").fadeIn("fast");
		$("#popupContact").fadeIn("fast");
		popupStatus = 1;
		
		
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	
	//disables popup only if it is enabled

	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("fast");
		$("#popupContact").fadeOut("fast");
		popupStatus = 0;
	}
		
}

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

