﻿/***************************/
//@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(popupid){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({"opacity": "0.7"});
		$("#backgroundPopup").fadeIn("slow");
		$("#"+popupid).fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$(".popupContact").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(popupid){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $(popupid).height();
	var popupWidth = $(popupid).width();
	//centering
	$(popupid).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!
	$(".popup_button").click(function(){
		/*
		//load popup
		loadPopup($(this).attr('rel'));*/
		blockme($(this).attr('rel'));
		//centering with css
		centerPopup(".blockMsg");
	});
				
	//CLOSING POPUP
	//Click the x event!
	$(".popupContactClose").click(function(){
		//disablePopup();
		unblockme();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		//disablePopup();
		unblockme();
	});
	//Press Escape event!
	$(document).bind('keyup',function(e){
		if(e.keyCode==27 && popupStatus==1){
			//disablePopup();
			unblockme();
		}
	});

});

//function used to show popup for please wait in ajax process
function blockme(ids){
	$.blockUI({ message: $('#'+ids).html()
	,css : {'width': '380px', backgroundColor: '#fff', '-webkit-border-radius': '10px', '-moz-border-radius': '10px','border':'5px solid #ddd',
	'-webkit-box-shadow':' 0 0 5px 5px#888'}
	,fadeIn: 0
    ,fadeOut: 2000 
	});
	$(".blockOverlay").css({'backgroundColor': '#000', 'color': '#fff','opacity':'0.6','height':getDocHeight()});
	popupStatus = 1;
	$(".blockOverlay").click(unblockme);
}
//function used to unblock the window
function unblockme(){
	popupStatus = 0;
	$.unblockUI();
}
//function used to get the maximum height of the document for ui blocking
function getDocHeight() {
    return Math.max(
        Math.max(document.body.scrollHeight, document.documentElement.scrollHeight),
        Math.max(document.body.offsetHeight, document.documentElement.offsetHeight),
        Math.max(document.body.clientHeight, document.documentElement.clientHeight)
    );
}

