/*
*@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;
var popupStatusSitemap = 0;
var popupStatusServices = 0;
var arrayService = new Array();
arrayService['ls'] = '/?/lvl/281927';
arrayService['ps'] = '?/lvl/281922';
arrayService['lml'] = '?/lvl/281923';
arrayService['ccc'] = '?/lvl/281924';
arrayService['gmr'] = '?/lvl/281925';
arrayService['qc'] = '?/lvl/281926';
//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#bgWindow").css({
			"opacity": "0.7"
		});
		$("#bgWindow").fadeIn("slow");
		$("#mapWindow").fadeIn("slow");
		popupStatus = 1;
	}
}
// load popup sitemap
function loadPopupSitemap(){
	//loads popup only if it is disabled
	if(popupStatusSitemap==0){
		$("#bgWindowSitemap").css({
			"opacity": "0.7"
		});
		$("#bgWindowSitemap").fadeIn("slow");
		$("#sitemapWindow").fadeIn("slow");
		popupStatusSitemap = 1;
	}
}
// load popup services
function loadPopupServices(link){
	//loads popup only if it is disabled
	if(popupStatusServices==0){
		$(".bgWindowService").css({
			"opacity": "0.7"
		});
		$(".bgWindowService").fadeIn("slow");
		$("#servicesWindow").fadeIn("slow");
		popupStatusServices = 1;
		loadContentServices(link);
	}
}
function loadContentServices(link){
	//loads content
	$("#serviceContent").fadeOut("slow",function() {
		$("#serviceContent").unload();
		$("#serviceContent").load(link,function() {
			$("#serviceContent").fadeIn("slow");
		});
	});
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#bgWindow").fadeOut("slow");
		$("#mapWindow").fadeOut("slow");
		popupStatus = 0;
	}
}
//disabling sitemap popup with jQuery magic!
function disablePopupSitemap(){
	//disables popup only if it is enabled
	if(popupStatusSitemap==1){
		$("#bgWindowSitemap").fadeOut("slow");
		$("#sitemapWindow").fadeOut("slow");
		popupStatusSitemap = 0;
	}
}
//disabling popup services with jQuery magic!
function disablePopupServices(){
	//disables popup only if it is enabled
	if(popupStatusServices==1){
		$(".bgWindowService").fadeOut("slow");
		$("#servicesWindow").fadeOut("slow");
		popupStatusServices = 0;
	}
}
//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#mapWindow").height();
	var popupWidth = $("#mapWindow").width();
	//centering
	$("#mapWindow").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	$("#bgWindow").css({
		"height": windowHeight
	});
}
//centering sitemap popup
function centerPopupSitemap(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#sitemapWindow").height();
	var popupWidth = $("#sitemapWindow").width();
	//centering
	$("#sitemapWindow").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	$("#bgWindowSitemap").css({
		"height": windowHeight
	});
}
//centering popup Services
function centerPopupServices(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#servicesWindow").height();
	var popupWidth = $("#servicesWindow").width();
	//centering
	$("#servicesWindow").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	$(".bgWindowService").css({
		"height": windowHeight
	});
}

//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	
	//not in original changed to be clickable from image not button
	$("#popupOpen").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
	$("#popupOpenImage").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
	$("#popupOpenSitemap").click(function(){
		//centering with css
		centerPopupSitemap();
		//load popup
		loadPopupSitemap();
	});
	
	//CLOSING POPUP
	//Click the x event!
	$("#fgClose").click(function(){
		disablePopup();
	});
	$("#linkClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#bgWindow").click(function(){
		disablePopup();
	});
	
	//CLOSING POPUP
	//Click the x event!
	$("#fgCloseSitemap").click(function(){
		disablePopupSitemap();
	});
	$("#linkCloseSitemap").click(function(){
		disablePopupSitemap();
	});
	//Click out event!
	$("#bgWindowSitemap").click(function(){
		disablePopupSitemap();
	});
	
	
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27){
			if(popupStatus==1){
				disablePopup();
			} else if(popupStatusSitemap==1) {
				disablePopupSitemap();
			} else if(popupStatusServices==1) {
				disablePopupServices();
			}
		}
	});

});
