﻿/***************************/
//@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 loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.88"
		});
		$("#backgroundPopup").fadeIn("slow");
		$(".popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){

	    // popup close
		$("#backgroundPopup").fadeOut("slow");
		$(".popupContact").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(w, h, callback){
	
	//request data for centering
	var windowWidth = document.documentElement.clientWidth != 0 ? document.documentElement.clientWidth : document.body.clientWidth;
	var windowHeight = document.documentElement.clientHeight != 0 ? document.documentElement.clientHeight : document.body.clientHeight;
	var popupWidth = $("#popupContact").width();
	var popupHeight = $("#popupContact").height();
	if (w != undefined && h != undefined) {
		popupWidth = w;
		popupHeight = h;
	}
	//alert(windowWidth + ", " + windowHeight + ", " + popupWidth + ", " + popupHeight);
	
	//centering
	$("#popupContact").css({
		"top" : 125,
		"left" : windowWidth/2-popupWidth/2,
		"position" : "absolute"
	});
	
	var popupWidth2 = $("#popupContact2").width();
	var popupHeight2 = $("#popupContact2").height();
	//alert(popupWidth2 + ", " + popupHeight2);
	$("#popupContact2").css({
		"top" : 125 + popupHeight + 18,
		"left" : windowWidth/2-popupWidth2/2,
//		"background-color" : "yellow",
		"position" : "absolute"
	});	
	var popupWidth3 = $("#popupContact3").width();
	$("#popupContact3").css({
		"top" : 55,
		"left" : windowWidth/2-popupWidth3/2,
//		"background-color" : "green",
		"position" : "absolute"
	});	
//	$("#popupContact3").css({
//		"top" : windowHeight - 100,
//		"left" : windowWidth/2-popupWidth3/2,
//		"position" : "absolute"
//	});	
	//only need force for IE6
	
	$("#backgroundPopup").css({
//		"height": windowHeight,
		"width": windowWidth
	});

	//if (callback != undefined) callback();
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
//	$(".button").click(function(){
//
//		//centering with css
//		centerPopup();
//	
//		//load popup
//		loadPopup();
//	
//	});
				
	//CLOSING POPUP
	//Click the x event!
	$(".popupContactClose").click(function(){
		disablePopup();
	});
	
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

}); 

