/***************************/
//@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 popupStatus2 = 0;
var popupStatus3 = 0;
//loading popup with jQuery magic!
function getScrollXY() { 
var scrOfX = 0, scrOfY = 0; 
if( typeof( window.pageYOffset ) == 'number' ) { 
  //Netscape compliant 
    scrOfY = window.pageYOffset; 
      scrOfX = window.pageXOffset; 
      } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) { 
        //DOM compliant 
	  scrOfY = document.body.scrollTop; 
	    scrOfX = document.body.scrollLeft; 
	    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) { 
	      //IE6 standards compliant mode 
	        scrOfY = document.documentElement.scrollTop; 
		  scrOfX = document.documentElement.scrollLeft; 
		  } 
		  return {X:scrOfX, Y:scrOfY}; 
		  } 
		  
		  function getWindowSize() { 
		   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{X:myWidth, Y:myHeight} 
						   } 
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
				"opacity": "0.7"
				});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}
function loadPopup2(){
	//loads popup only if it is disabled
	if(popupStatus2==0){
		$("#backgroundPopup").css({
				"opacity": "0.7"
				});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact2").fadeIn("slow");
		popupStatus2 = 1;
	}
}
function loadPopup3(){
	//loads popup only if it is disabled
	if(popupStatus3==0){
		$("#backgroundPopup").css({
				"opacity": "0.7"
				});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact3").fadeIn("slow");
		popupStatus3 = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		popupStatus = 0;
	}
}
function disablePopup2(){
	//disables popup only if it is enabled
	if(popupStatus2==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact2").fadeOut("slow");
		popupStatus2 = 0;
	}
}
function disablePopup3(){
	//disables popup only if it is enabled
	if(popupStatus3==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact3").fadeOut("slow");
		popupStatus3 = 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": "absolute",
			"top": windowHeight/2-popupHeight/2,
			"left": windowWidth/2-popupWidth/2
			});
	//only need force for IE6

	$("#backgroundPopup").css({
			"height": windowHeight
			});

}

function centerPopup2(){

var windowDim = getWindowSize(); 
var popupHeight = $("#popupContact2").height(); 
var popupWidth = $("#popupContact2").width(); 
var scroll = getScrollXY(); 

	$("#popupContact2").css({
			"position": "absolute",
			"top": windowDim.Y/2-popupHeight/2 + scroll.Y-5, 
			"left": windowDim.X/2-popupWidth/2 + scroll.X-15

			});
	//only need force for IE6

	$("#backgroundPopup").css({
			"height": windowDim.Y
			});

}

function centerPopup3(){
var windowDim = getWindowSize(); 
var popupHeight = $("#popupContact3").height(); 
var popupWidth = $("#popupContact3").width(); 
var scroll = getScrollXY(); 
	$("#popupContact3").css({
			"position": "absolute",
			"top": windowDim.Y/2-popupHeight/2 + scroll.Y-15, 
			"left": windowDim.X/2-popupWidth/2 + scroll.X-15
			});
			//"top": windowHeight/2-popupHeight/2,
	//only need force for IE6

	$("#backgroundPopup").css({
			"height": windowDim.Y
			});
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){

		//LOADING POPUP
		//Click the button event!
		$("#button").click(function(){
			centerPopup();
			loadPopup();
			});
		$("#button2").click(function(){
			centerPopup2();
			loadPopup2();
			});
		$("#button3").click(function(){
			centerPopup3();
			loadPopup3();
			});

		//CLOSING POPUP
		//Click the x event!
		$("#popupContactClose").click(function(){
			disablePopup();
			});
		$("#popupContactClose2").click(function(){
			disablePopup2();
			});
		$("#popupContactClose3").click(function(){
			disablePopup3();
			});

		//Click out event!
		$("#backgroundPopup").click(function(){
			disablePopup();
			});
		$("#backgroundPopup").click(function(){
			disablePopup2();
			});			
		$("#backgroundPopup").click(function(){
			disablePopup3();
			});			

		//Press Escape event!
		$(document).keypress(function(e){
			if(e.keyCode==27 && popupStatus==1){
			disablePopup();
			}
			});

});
