/* Slideshow Javascript */

$(document).ready(function() {
	
	/**
	*
	*/
	function initialise_tabs() {
		
		$(".tab-container").each(function() {
		
			var container = $(this).attr("id");
			
			hide_tabs(container);
			
			display_tab(container);
			
		});
		
	}
	
	
	
	/**
	* Hides all tabs for a container
	*/
	function hide_tabs(container) {
		
		$("#"+container).children("div").each(function() {
			
			$(this).css({ "display": "none" });
			
		});
		
	}
	
	
	
	/**
	* Displays a selected tab
	*/
	function display_tab(container, tab_id) {
		
		// Hide all tabs
		hide_tabs(container);
		
		// Get the first tab if not specified
		if (!tab_id) var tab_id = $("#"+container).children("div").attr("id");
		
		$("#"+container+" #"+tab_id).css({ "display": "block" });
		
		// Loop through each tab link and set as selected where appropriate
		$("#"+container+" ul li a").each(function() {
			
			$(this).attr("class", "");
			
			if ($(this).attr("href") == "#" + tab_id) {
				
				$(this).attr("class", "selected");
				
			}
			
		});
		
	}
	
	
	
	/**
	* Sitches to a selected tab
	*/
	$("ul[id^=tab-menu] li a").click(function(event) {
		
		event.preventDefault();
		
		// Get the container
		container = $(this).parent().parent().parent().attr("id");
		
		// Get the tab
		tab_name = $(this).attr("href");
		tab_id = tab_name.substr(1, (tab_name.length - 1));
		
		// Display the appropriate tab
		display_tab(container, tab_id);
		
	});
	
	
	
	// Start the tab display
	initialise_tabs();
	
});
