// JavaScript Document

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupLocationsStatus=0;


//loading popup with jQuery magic!
function loadPopup3(){
	//loads popup only if it is disabled
	if(popupLocationsStatus==0){
		$("#backgroundPopup3").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup3").fadeIn("slow");
		$("#popupLocations").fadeIn("slow");
		popupLocationsStatus = 1;
	}
		

}
//disabling popup with jQuery magic!
function disablePopup3(){
	//disables popup only if it is enabled
	if(popupLocationsStatus==1){
		$("#backgroundPopup3").fadeOut("slow");
		$("#popupLocations").fadeOut("slow");
		popupLocationsStatus = 0;
	}
		
}
//centering popup
function centerPopup3(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupLocations").height();
	var popupWidth = $("#popupLocations").width();
	//centering
	$("#popupLocations").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	$("#backgroundPopup3").css({
		"height": windowHeight
	});
		$("#backgroundPopup3").css({
		"height": windowHeight
	});
	
}
$(document).ready(function(){
//LOADING POPUP
	//Click the button event!
	$("#locations").click(function(){
						
		//centering with css
		centerPopup3();
		//load popup
		loadPopup3("#popupLocations");
	});
		
	//CLOSING POPUP
	//Click the x event!
	$("#popupLocationsClose").click(function(){
		disablePopup3();
	});
	//Click out event!
	$("#backgroundPopup3").click(function(){
		disablePopup3();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupLocations==1 ){
			disablePopup3();
		}
	});
});
