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

//loading popup with jQuery magic!
function loadPopupBrochure(){
	//loads popup only if it is disabled
	if(popupStatusBrochure==0){
		$(".backgroundPopupBrochure").css({
			"opacity": "0.8"
		});
		$(".backgroundPopupBrochure").fadeIn("slow");
		$("#popupBrochure").fadeIn("slow");
		popupStatusBrochure = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopupBrochure(){
	//disables popup only if it is enabled
	if(popupStatusBrochure==1){
		$(".backgroundPopupBrochure").fadeOut("slow");
		$("#popupBrochure").fadeOut("slow");
		popupStatusBrochure = 0;
	}
}

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


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$(".buttonBrochure").click(function(){
		//centering with css
		centerPopupBrochure();
		//load popup
		loadPopupBrochure();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$(".popupBrochureClose").click(function(){
		disablePopupBrochure();
	});
	//Click out event!
	$(".backgroundPopupBrochure").click(function(){
		disablePopupBrochure();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatusBrochure==1){
			disablePopupBrochure();
		}
	});

});