﻿/***************************/
//@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 popupContactUsStatus = 0;

//loading popup with jQuery magic!
function loadPopupContactUs(){
	//loads popup only if it is disabled
	if(popupContactUsStatus==0){
		$("#backgroundContactUsPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundContactUsPopup").fadeIn("slow");
		$("#popupContactUs").fadeIn("slow");
		popupContactUsStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopupContactUs(){
	//disables popup only if it is enabled
	if(popupContactUsStatus==1){
		$("#backgroundContactUsPopup").fadeOut("slow");
		$("#popupContactUs").fadeOut("slow");
		popupContactUsStatus = 0;
	}
}

//centering popup
function centerPopupContactUs(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContactUs").height();
	var popupWidth = $("#popupContactUs").width();
	//centering
	$("#popupContactUs").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundContactUsPopup").css({
		"height": windowHeight
	});
	
}

function showPopupContactUs(){
	window.open('#', '_self');
	//centering with css
	centerPopupContactUs();
	//load popup
	loadPopupContactUs();
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("#popup-click").click(function(){
		//centering with css
		centerPopupContactUs();
		//load popup
		loadPopupContactUs();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactUsClose").click(function(){
		disablePopupContactUs();
	});
	//Click out event!
	$("#backgroundContactUsPopup").click(function(){
		disablePopupContactUs();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopupContactUs();
		}
	});

});
