var centre_image=true // set to false to stop the image centering
// onload events
$(function(){
	resizeElements();
	/*if(navigator.userAgent.toLowerCase().indexOf('chrome') > -1){
		setTimeout("resizeImage();centreImage()",100)
	}else{
		resizeImage();
		centreImage()
	}*/
	setTimeout("resizeImage();centreImage",100)// need to delay a bit to allow for image to load, load() don't work on most browsers for cache images so hack it in
	$("#enquiry").change(function(){contact(this,"enquiry")});
	$("#hearabout").change(function(){contact(this,"hearabout")});
	// listing
	$("#venue-gallery-page-thumbs div.venue-gallery-prev a").click(function(event){event.preventDefault();gallerySlide("prev",this,"thumbs")});
	$("#venue-gallery-page-thumbs div.venue-gallery-next a").click(function(event){event.preventDefault();gallerySlide("next",this,"thumbs")});
	$("#venue-gallery-page-thumbs div.venue-gallery-widther li a").click(function(event){event.preventDefault();galleryView(this)});
	// show 
	$("#venue-gallery-page-show div.venue-gallery-prev a").live("click",function(event){event.preventDefault();gallerySlide("prev",this,"show")});
	$("#venue-gallery-page-show div.venue-gallery-next a").live("click",function(event){event.preventDefault();gallerySlide("next",this,"show")});
});
// onresize events
$(window).resize(function(event){centreImage();resizeImage()});

// resize the elements
function resizeElements(){var floatH=$("#venue-float").height();$("#venue-wrapper").height(floatH);$("#venue-bg").height(floatH);$("#venue-nav-bg").height(floatH)}
// centre image
function centreImage(){if(centre_image){offset=Math.round(parseInt(($("#venue-image").height()-$("#venue-float").height())/2));$("#venue-image").css("margin","-"+offset+"px")}}
// resize the image
function resizeImage(){var floatH=$("#venue-float").height(),imgH=$("#venue-image").height();if(floatH>imgH){$("#venue-image").height(floatH)}}

// enquiry tab reveal 
function contact(el,sector){
	if(contactReveal("hide",sector,"all")){
		switch(el.value.toLowerCase())
		{
			case "call me back":
				contactReveal("show",sector,"#enq-call")
			break;
			case "wish to make a booking":
				contactReveal("show",sector,"#enq-book")			
			break;
			case "other":
				contactReveal("show",sector,"#hear-other")			
			break;
		}
	}
}
function contactReveal(state,sector,id){
	var result;
	if(id=="all"){id="div.contact-reveal"}
	if(state=="show"){
		$("#reveal-"+sector+" "+id).slideDown("fast",function(){resizeElements();centreImage();resizeImage();result=true})
	}else{
		$("#reveal-"+sector+" "+id).slideUp("fast",function(){resizeElements();centreImage();resizeImage();result=true})		
	}
	return result
}

// gallery
function gallerySizes(sec){
	var sizes={
		wrapper:$("#venue-gallery-page-"+sec+" div.venue-gallery-wrapper").width(),
		widther:$("#venue-gallery-page-"+sec+" div.venue-gallery-widther").width()
	}
	return sizes
}
function galleryLeft(id){
	return $("#"+id).position().left
}
function gallerySlide(dir,el,sec){
	var sizes=gallerySizes(sec);
	if($(el).attr("href")){
		if(dir=="next"){var opr="-"}else{var opr="+"}
		$("#venue-gallery-page-"+sec+" div.venue-gallery-thumbs").animate({
			left:opr+"="+sizes.wrapper
		},"fast","swing",function(){
			galleryButtons(sizes,sec)
		})
	}
}
function galleryButtons(obj,sec){
	obj.thumbs_left=parseInt($("#venue-gallery-page-"+sec+" div.venue-gallery-thumbs").css("left").replace("-",""))+1;
	// prev
	if(obj.thumbs_left<obj.wrapper){galleryDisable("prev",1,sec)}else{galleryDisable("prev",0,sec)}
	// next 
	if(parseInt(obj.thumbs_left+obj.wrapper) < obj.widther){galleryDisable("next",0,sec)}else{galleryDisable("next",1,sec)}
}
function galleryDisable(dir,disable,sec){
	if(disable){
		// disable
		$("#venue-gallery-page-"+sec+" div.venue-gallery-"+dir+" a").addClass("disabled");
		$("#venue-gallery-page-"+sec+" div.venue-gallery-"+dir+" a").removeAttr("href");
	}else{
		// enable
		$("#venue-gallery-page-"+sec+" div.venue-gallery-"+dir+" a").removeClass("disabled");
		$("#venue-gallery-page-"+sec+" div.venue-gallery-"+dir+" a").attr("href","#");
	}
}
function galleryView(el){
	$("#overlay-align").load("/overlay/gallery/",{"navigation_id":$(el).attr("data-navigation_id"),"image_id":$(el).attr("data-image_id")},function(){
		toggleOverlay("show")
		setTimeout(function(){
			$("#venue-gallery-page-show div.venue-gallery-thumbs").css("left","-"+galleryLeft($(el).attr("data-image_id"))+"px");
			var sizes=gallerySizes("show");
			galleryButtons(sizes,"show")
		},450)
	})
}
