﻿$(document).ready(function() {


	// MAIN NAV - DROP DOWN MENU
	// -------------------------
	$("div.top_nav ul li a").hover(function() {
											 
		$(this).parent().find("ul.subnav").css({ opacity: 0.95 }).slideDown('fast').show();
		
		$(this).parent().hover(function() {
		}, function(){	
			$(this).parent().find("ul.subnav").fadeOut('fast');
		});
	}, function() {
		// empty function to stop page error in IE
	});
	$("div.second_nav ul li a").hover(function() {
											 
		$(this).parent().find("ul.subnav").css({ opacity: 0.95 }).slideDown('fast').show();
		
		$(this).parent().hover(function() {
		}, function(){	
			$(this).parent().find("ul.subnav").fadeOut('fast');
		});
	}, function() {
		// empty function to stop page error in IE
	});
	
	
	// WHATS ON CALENDAR - DROP DOWN ITEMS
	// -----------------------------------
	$("#body_area div.whats_on table tr td.info a").click(function() {
		
		var current_class = $(this).attr("class");
		
		$("#body_area div.whats_on table tr td.info a.open").removeClass("open");		// remove 'open' class from all a links
				
		if(current_class != "open") $(this).addClass("open");		// add 'open' class to the current link if it's closed
		
		var a_name = $(this).attr("name");
		var infoblock_path = "td.infoblock div." + a_name;
		
		if($(infoblock_path).is(":hidden")) {
			$("td.infoblock div:visible").slideUp("fast").hide();				// hide all visible infoblocks
			$(infoblock_path).slideDown("fast").show();
		} else {
			$(infoblock_path).slideUp("fast").hide();
		}
	
	});
	
	
	// TOP OF PAGE LINK
	// ----------------
	$("a.top_of_page").click(function() {
		$("html, body").animate( { scrollTop: 0 }, "slow" );
	});


	// IMAGE GALLERY / SLIDESHOW VIEWER
	// --------------------------------
	$("a.slideshowlauncher").click(function(e) {
		$("#image_gallery_background").css({"opacity" : "0.7"}).fadeIn("slow");
		$("#image_gallery").css({
			top:'50%',
			left:'50%',
			margin:'-'+($('#image_gallery').height() / 2)+'px 0 0 -'+($('#image_gallery').width() / 2)+'px'
		});
		
		// $("#image_gallery").html("<img src='images/loading.gif' alt='Currently Loading' id='loading' />").fadeIn("slow");
		$("#image_gallery").fadeIn("slow");
		
		var slide_show_id = $(this).attr("href").substring(24);
		
		// AJAX bit
		$.ajax({
			url: 'image_gallery_ajax.php',
			type: 'POST',
			data: 'slide_show_id=' + slide_show_id,
			success: function(result) {
				$("#image_gallery").html(result);
				$("#image_gallery div.photo img[name='pic1']").fadeIn("fast");
			}
		});
		
		return false;
	});
	
	$("#image_gallery_background").click(function() {
		$("#image_gallery").fadeOut("slow");
		$("#image_gallery_background").fadeOut("slow");
	});


});
	
	function close_image_gallery() {
		$("#image_gallery").fadeOut("slow");
		$("#image_gallery_background").fadeOut("slow");
	}
	
	function change_image(a, img_href) {
		
		$("#image_gallery ul li a").removeClass("active");		// remove 'active' class from all links
		$(a).addClass("active");								// add 'active' class to this link
		
		// change image
		$("#image_gallery div.photo img:visible").fadeOut("slow");
		$("#image_gallery div.photo img[name='" + img_href + "']").fadeIn("slow");
		
		if($(a).attr("name") == "none") $("#image_gallery p.description").html("&nbsp;");
		else $("#image_gallery p.description").html($(a).attr("name"));
		
		return false;
	}
