﻿/***************************/
//@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 who = 0;
var whos = 0;
var what = 0;
var which = 0;
var why = 0;
var where = 0;

//loading popup with jQuery magic!
function loadPopup(whos,what){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$(what).css({
			"opacity": "0.7"
		});
		$(what).fadeIn("slow");
		$(whos).fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(which,where){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$(where).fadeOut("slow");
		$(which).fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(who,why){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $(who).height();
	var popupWidth = $(who).width();
	//centering
	$(who).css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$(why).css({
		"height": windowHeight
	});
	
}
function cpop(who,why){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $(who).height();
	var popupWidth = $(who).width();
	//centering
	$(who).css({
		"position": "absolute",
		"top": 350,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$(why).css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("#button").click(function(){
		//centering with css
		centerPopup('#popup1','#backgroundPopup');
		//load popup
		loadPopup('#popup1','#backgroundPopup');
	});
		$("#buttonc").click(function(){
		//centering with css
		centerPopup('#popup1','#backgroundPopup');
		//load popup
		loadPopup('#popup1','#backgroundPopup');
	});
		$("#buttona").click(function(){
		//centering with css
		cpop('#popup2','#backgroundPopup2');
		//load popup
		loadPopup('#popup2','#backgroundPopup2');
	});
			$("#buttone").click(function(){
		//centering with css
		cpop('#popup4','#backgroundPopup4');
		//load popup
		loadPopup('#popup4','#backgroundPopup4');
	});
			$("#buttonb").click(function(){
		//centering with css
		centerPopup('#popup3','#backgroundPopup3');
		//load popup
		loadPopup('#popup3','#backgroundPopup3');
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popup1Close").click(function(){
		disablePopup('#popup1','#backgroundPopup');
	});
		$("#popup2Close").click(function(){
		disablePopup('#popup2','#backgroundPopup2');
	});
			$("#popup4Close").click(function(){
		disablePopup('#popup4','#backgroundPopup4');
	});
		$("#popup3Close").click(function(){
		disablePopup('#popup3','#backgroundPopup3');
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup('#popup1','#backgroundPopup');
	});
		$("#backgroundPopup2").click(function(){
		disablePopup('#popup2','#backgroundPopup2');
	});
		$("#backgroundPopup3").click(function(){
		disablePopup('#popup3','#backgroundPopup3');
	});
			$("#backgroundPopup4").click(function(){
		disablePopup('#popup4','#backgroundPopup4');
	});
	

});
