﻿/***************************/
//@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 = 1;

//loading popup with jQuery magic!
function loadPopup(divName){
	//loads popup only if it is disabled
	//if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#"+divName).fadeIn("slow");
		//popupStatus = 1;
	//}
}

//disabling popup with jQuery magic!
function disablePopup(divName){
	//disables popup only if it is enabled
	//if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$(".modal").fadeOut("slow");
	//	popupStatus = 0;
	//}
}

//centering popup
function centerPopup(divName){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#"+divName).height();
	var popupWidth = $("#"+divName).width();
	//centering
	$("#"+divName).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!
	$("#xxxloginBut").click(function(){
		centerPopup("popupContact");
		loadPopup("popupContact");
	});
	$("#getBen").click(function(){
		centerPopup("benefitPop");
		loadPopup("benefitPop");
	});
	$("#loginInfo").click(function(){		
		centerPopup("loginInfoWin");
		loadPopup("loginInfoWin");
	});
		$(".afterCare").click(function(){		
		centerPopup("afterCareWin");
		loadPopup("afterCareWin");
	});
		$(".suppliersBox").click(function(){		
		centerPopup("suppliersWin");
		loadPopup("suppliersWin");
	});
		$(".batteries").click(function(){		
		centerPopup("batteriesWin");
		loadPopup("batteriesWin");
	});
		$(".matching").click(function(){		
		centerPopup("matchingWin");
		loadPopup("matchingWin");
	});
		$(".Bromley").click(function(){		
		centerPopup("BromleyWin");
		loadPopup("BromleyWin");
	});
		$(".Maidstone").click(function(){		
		centerPopup("MaidstoneWin");
		loadPopup("MaidstoneWin");
	});
		$(".Orpington").click(function(){		
		centerPopup("OrpingtonWin");
		loadPopup("OrpingtonWin");
	});
		$(".Sevenoaks").click(function(){		
		centerPopup("SevenoaksWin");
		loadPopup("SevenoaksWin");
	});
		$(".Tonbridge").click(function(){		
		centerPopup("TonbridgeWin");
		loadPopup("TonbridgeWin");
	});
		$(".Bridgford").click(function(){		
		centerPopup("BridgfordWin");
		loadPopup("BridgfordWin");
	});
		$(".Hockley").click(function(){		
		centerPopup("HockleyWin");
		loadPopup("HockleyWin");
	});
		$(".Stapleford").click(function(){		
		centerPopup("StaplefordWin");
		loadPopup("StaplefordWin");
	});
		$(".Bingham").click(function(){		
		centerPopup("BinghamWin");
		loadPopup("BinghamWin");
	});
		$(".Ashfield").click(function(){		
		centerPopup("AshfieldWin");
		loadPopup("AshfieldWin");
	});
				
	//CLOSING POPUP
	//Click the x event!
	$(".modalClose").click(function(){
		disablePopup();

	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();

	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();

		}
	});
//BOOKMARK FUNCTION ----------------------------------------------------------------------------
	// add a "rel" attrib if Opera 7+
	if(window.opera) {
		if ($("a.addfav").attr("rel") != ""){ // don't overwrite the rel attrib if already set
			$("a.addfav").attr("rel","sidebar");
		}
	}

	$("a.addfav").click(function(event){
		event.preventDefault(); // prevent the anchor tag from sending the user off to the link
		var url = this.href;
		var title = this.title;

		if (window.sidebar) { // Mozilla Firefox Bookmark
			window.sidebar.addPanel(title, url,"");
		} else if( window.external ) { // IE Favorite
			window.external.AddFavorite( url, title);
		} else if(window.opera) { // Opera 7+
			return false; // do nothing - the rel="sidebar" should do the trick
		} else { // for Safari, Konq etc - browsers who do not support bookmarking scripts (that i could find anyway)
			 alert('Unfortunately, this browser does not support the requested action,'
			 + ' please bookmark this page manually.');
		}

	});
//END BOOKMARK FUNCTION -------------------------------------------------------------------------------

});