﻿/***************************/
//@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 popup2Status = 0;

//loading popup with jQuery magic!
function loadPopup2(){
	//loads popup only if it is disabled
	if(popup2Status==0){
		jQuery("#backgroundPopup2").css({
			"opacity": "0.5"
		});
		jQuery("#backgroundPopup2").fadeIn("slow");
		jQuery("#popup2Contact").fadeIn("slow");
		popup2Status = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup2(){
	//disables popup only if it is enabled
	if(popup2Status==1){
		jQuery("#backgroundPopup2").fadeOut("slow");
		jQuery("#popup2Contact").fadeOut("slow");
		popup2Status = 0;
	}
}

//centering popup
function centerPopup2(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popup2Height = jQuery("#popup2Contact").height();
	var popup2Width = jQuery("#popup2Contact").width();
	//centering
	jQuery("#popup2Contact").css({
		"position": "absolute",
		"top": windowHeight/4-popup2Height/4,
		"left": windowWidth/2-popup2Width/2
	});
	//only need force for IE6
	
	jQuery("#background2Popup").css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
jQuery(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!

		//centering with css
		centerPopup2();
		//load popup
		loadPopup2();

				
	//CLOSING POPUP
	//Click the x event!
	jQuery("#popup2ContactClose").click(function(){
		disablePopup2();
	});
	//Click out event!
	jQuery("#backgroundPopup2").click(function(){
		disablePopup2();
	});
	//Press Escape event!
	jQuery(document).keypress(function(e){
		if(e.keyCode==27 && popup2Status==1){
			disablePopup2();
		}
	});

});
