$(function(){
	
  var sPath = window.location.pathname;
  var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
  
   if(sPage == "leisure.php"){
    $(".leisure ul li ul").hide()
	   
	
   } else { 
   		if(sPage.substring(0,5) == "hotel")
			$(".leisure ul li ul").eq(1).hide();
		else
			$(".leisure ul li ul").eq(0).hide();
   }
   $(".leisure ul li a").click(function(event){		
		if($(this).siblings("ul").size() > 0 )
		{
			event.preventDefault();
			$(this).siblings("ul").toggle("slow");
		}
	});
	
	// Brochure request form
	$("#request").click(function(){
		$.ajax({
				   type: "GET",
				   url: "/brochure-form.html",
				   success: function(response){
				   		lightboxbc(response, 'Request CCOMM Brochures & Literature');
					   //$("body").append(response);
					   $("#requestForm").submit(function(){	
							if($("#visitor_name").val() != "" && $("#visitor_email").val() != "")
							{
								var data = "name="+$("#visitor_name").val();
								data += "&email="+$("#visitor_email").val();
								data += "&phone="+$("#phone_number").val();
								$("#brochureCheckboxes input:checked").each(function(){
									data += "&"+$(this).attr("name")+"=true";
								});
								$.ajax({
								   type: "GET",
								   url: "/brochure-request.php",
								   data: data,
								   dataType: "json",
								   success: function(msg){
									  if(msg.success)
									   $("#requestForm").html("Your brochures have been requestsed");
								   }
								 });
							 } else {
								alert("Please ensure you have filled in your name and email address.");
							 }
							 return false;
						});  
				   }
				 });		
	});
});


var $j = jQuery;
function lightboxbc(content, title, callback, params){
	if($j("#lightboxBC").size() == 0){  var newLightbox = '<div id="lightboxBCWrapper"></div><div id="lightboxBC"><span id="lbTitle"></span><span id="lbClose"></span><div id="lbContents"></div></div>';  $j("body").append(newLightbox);	 }	
	$j("#lightboxBC div").html(content);
	$j("#lightboxBC #lbContents").css("width","500px");	
	$j("#lbTitle").text(title);
	var scrollPos = [ $j(window).scrollLeft(), $j(window).scrollTop()];
	var windowSize = [$j(window).width() , $j(window).height()];

	$j("#lightboxBCWrapper").css({"width":windowSize[0]+"px","height":$j(document).height()+"px","top":"0px","left":scrollPos[0]+"px"});
	$j("#lightboxBC").css("top",(((windowSize[1] - $j("#lightboxBC").height())/2)+scrollPos[1])+"px");
	$j("#lightboxBC").css("left",(((windowSize[0] - $j("#lightboxBC").width())/2)+scrollPos[0])+"px");
	$j("#lightboxBC").css("width",$j("#lbContents").css("width"));
	//$j("#lightboxBCWrapper").fadeIn();
	$j("#lightboxBCWrapper").show();
	$j("#lightboxBC").show("fast", function(){if(callback){callback( params )}});
	$j("#lightboxBCWrapper").click(function(){closelightboxbc();});
	$j("#lbClose").click(function(){closelightboxbc();});
}
function closelightboxbc(){
	$j("#lightboxBC").hide();
	$j("#lightboxBCWrapper").hide();
}
