/***************************/
//@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 popupMStatus = 0;
var popupSStatus = 0;

//loading popup with jQuery magic!
function loadPopupM(){
	//loads popup only if it is disabled
	if(popupMStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupMorgan").fadeIn("slow");
		popupMStatus = 1;
	}
}
function loadPopupS(){
	//loads popup only if it is disabled
	if(popupSStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupShawn").fadeIn("slow");
		popupSStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopupM(){
	//disables popup only if it is enabled
	if(popupMStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupMorgan").fadeOut("slow");
		popupMStatus = 0;
	}
}
//disabling popup with jQuery magic!
function disablePopupS(){
	//disables popup only if it is enabled
	if(popupSStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupShawn").fadeOut("slow");
		popupSStatus = 0;
	}
}

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


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("#buttonM").click(function(){
		//centering with css
		centerPopupM();
		//load popup
		loadPopupM();
	});
	$("#buttonS").click(function(){
		//centering with css
		centerPopupS();
		//load popup
		loadPopupS();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#closeLinkM").click(function(){
		disablePopupM();
	});
	$("#closeLinkS").click(function(){
		disablePopupS();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopupM();
	});
	$("#backgroundPopup").click(function(){
		disablePopupS();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupSStatus==1){
			disablePopupS();
		}
	});

});