// Site wide functions for whistler.com

function load_tabs(tab){
	
	var resetTab = function () {
	  $(".toggle").hide();
	  $("#tabs li a").attr("class", "");
	};
	resetTab();
	
	if((window.location.hash != "") && $(window.location.hash).is("div")){
		//hash present, load requested tab
		var default_tab = $(window.location.hash);
		var selected_tab = $("#tab-" + window.location.hash.substring(1));
	} else if (tab){
		//function being passed a tab as an arguement, load requested tab
		var default_tab = $("#" + tab);
		var selected_tab = $("#tab-" + tab);
	} else {
		//no specific tab requested, load first
		var default_tab = $(".toggle:first");
		var selected_tab = $("ul#tabs li:first a");
	}
	
	$(".toggle").hide();
	default_tab.show();
	selected_tab.addClass("on");
	
	$("#chapters").prev().attr("id", "tabs");
	
	$("#tabs li a").bind('click', function () {
		resetTab();
		var e = $(this).attr("href");
		$(this).attr("class", "on");
		$(e).show();
		return false;
	});
	
}

$(document).ready(function(){
	if($("#chapters").length > 0){
		load_tabs();
		scroll(0,0);
	}
	$("a[rel='external']").attr("target", "_blank");
});
