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

//loading popup with jQuery magic!
function loadPopupSearch(){
	//loads popup only if it is disabled
	if(popupSearchStatus==0){
		$("#searchForm").fadeIn("slow");
		popupSearchStatus = 1;
	}
}

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

//centering popup
function centerPopupSearch(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#searchForm").height();
	var popupWidth = $("#searchForm").width();

//alert(screen.width);
//alert($("#popupWindow").width());
//alert((screen.width-popupWidth)/2);
		//centering
	$("#searchForm").css({
		"position": "absolute",
		"top": (windowHeight/2-popupHeight/2),
		"left": (screen.width - popupWidth)/2
	});
	//only need force for IE6

}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){

	//LOADING POPUP
	//Click the buttonPopup event!
	$("#buttonPopup").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});

	//CLOSING POPUP
	//Click the x event!
	$("#popupSearchClose").click(function(){
		disablePopupSearch();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupSearchStatus==1){
			disablePopupSearch();
		}
	});

});