// JavaScript Document
//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupGeneralStatus=0;


//loading popup with jQuery magic!
function loadPopup5(){
	//loads popup only if it is disabled
	if(popupGeneralStatus==0){
		$("#backgroundPopup5").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup5").fadeIn("slow");
		$("#popupGeneral").fadeIn("slow");
		popupGeneralStatus = 1;
	}
		

}

//disabling popup with jQuery magic!
function disablePopup5(){
	//disables popup only if it is enabled
	if(popupGeneralStatus==1){
		$("#backgroundPopup5").fadeOut("slow");
		$("#popupGeneral").fadeOut("slow");
		popupGeneralStatus = 0;
	}
		
}

//centering popup
function centerPopup5(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupGeneral").height();
	var popupWidth = $("#popupGeneral").width();
	//centering
	$("#popupGeneral").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	$("#backgroundPopup5").css({
		"height": windowHeight
	});
		$("#backgroundPopup5").css({
		"height": windowHeight
	});
	
}
$(document).ready(function () {	
							
							//Opening Times Toggle 
	$(".openingTimesToggle").hide(); 

	//Switch the "Open" and "Close" state per click then slide up/down (depending on open/close state)
	$("a.triggerToggle").click(function(){
		$(this).toggleClass("active");
		$(".openingTimesToggle").slideToggle("slow");
		return false; //Prevent the browser jump to the link anchor
	});
							
		//$('#nav li').hover(function() {
//				$(this)
//				.find('ul')
//				.stop(true, true)
//				.slideDown(100);
//		}, function() {
//				$(this)
//				.find('ul')
//				.stop(true,true)
//				.slideUp(100);
//});
		
		$('#nav li').hoverIntent(function() {
			$('ul', this).slideDown(100);

}, function() {
	$('ul', this).fadeOut(200);

});
	
	//$('#nav li').hover(
//		function () {
//			//show its submenu
//			$('ul', this).slideDown(100);
//
//		}, 
//		function () {
//			//hide its submenu
//			$('ul', this).slideUp(100);			
//		}
//	);
	
//$(function()
//{
//	$('.date-pick').datePicker({startDate:'01/01/1960'});
//});

var max = 0;
    $(".enquiryForm label").each(function(){
        if ($(this).width() > max)
            max = $(this).width();    
    });
    $(".enquiryForm label").width(max);
	
var max = 0;
    $(".EnquiryFormContainer label").each(function(){
        if ($(this).width() > max)
            max = $(this).width();    
    });
    $(".EnquiryFormContainer label").width(max);
	
// Add pdf icons to pdf links
	$("a[href$='.pdf']").addClass("pdf");
 
	// Add txt icons to document links (doc, rtf, txt)
	$("a[href$='.doc'], a[href$='.txt'], a[href$='.rft']").addClass("txt");
 
	// Add zip icons to Zip file links (zip, rar)
	$("a[href$='.zip'], a[href$='.rar']").addClass("zip"); 
 
	// Add email icons to email links
	//$("a[href^='mailto:']").addClass("email");
 
//	//Add external link icon to external links - 
//	$('a').filter(function() {
//		//Compare the anchor tag's host name with location's host name
//	    return this.hostname && this.hostname !== location.hostname;
//	  }).addClass("external");
	//You might also want to set the _target attribute to blank
	
	$('a').filter(function() {
		//Compare the anchor tag's host name with location's host name
	    return this.hostname && this.hostname !== location.hostname;
	  }).addClass("external").attr("target", "_blank");
	


$('a.addthis_button, .noExtLink, .noExternal').removeClass('external');
$('.noPDFLink').removeClass('pdf');



//LOADING POPUP
	//Click the button event!
	$("#general").click(function(){
						
		//centering with css
		centerPopup5();
		//load popup
		loadPopup5("#popupGeneral");
	});
		
	//CLOSING POPUP
	//Click the x event!
	$("#popupGeneralClose").click(function(){
		disablePopup5();
		mpl.sendEvent('STOP');
	});
	//Click out event!
	$("#backgroundPopup5").click(function(){
		disablePopup5();
		mpl.sendEvent('STOP');
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupGeneralStatus==1 ){
			disablePopup5();
			mpl.sendEvent('STOP');
		}
	});

});
