var current;
var valid = new Array("overview", "gallery", "reviews", "support", "story");

jQuery(document).ready (function () {
	if(location.hash)
	{
		var section = location.hash.substring(1);
		if(jQuery.inArray(section, valid) > -1)
		{
			jQuery("#product_overview").hide();
			jQuery("#overview_tab").removeClass("active");
			
			var tab = jQuery("#"+section + "_tab");
			tab.addClass("active");
			
			current = jQuery("#product_"+section).show();
		}
	}
	else
	{
		current = jQuery("#product_overview");
	}
	
	var tabSwitch = function () {
		//reset
		jQuery("li.active").removeClass("active");
		current.hide();
		
		jQuery(this).parent().addClass("active");
		var id = jQuery(this).parent().attr("id").replace("_tab", ""); //remove _tab from the li to get the section we want to show
		current = jQuery("#product_"+id).fadeIn();
		location.hash = id;
		return false;
	}
	
	jQuery("#tabs a").click(tabSwitch);
	
});
