// tabbed_section object
var tabbed_section = {
	tab_links : [],
	num_tabs : 0,
	tab_content_wrappers : [],
	num_cws : 0,
	
	init : function() {
		this.tab_links = cssQuery("ul.tab_nav a");
		this.num_tabs = this.tab_links.length;
		
		this.tab_content_wrappers = cssQuery("div.ts_content_wrapper");
		this.num_cws = this.tab_content_wrappers.length;
		
		this.run();
	},
	
	run : function() {
		for(var i=0; i < this.num_tabs; i++) {
			addEvent(this.tab_links[i],'click',this.showTabContent);
			this.tab_links[i].onclick = function () {return false;}
		}
	},
	
	showTabContent : function() {
		// Deselect all tabs
		tabbed_section.deselectAllTabs();
		
		// The tab that was just clicked gets the class "current"
		this.className = "current";
		this.blur(); // Get rid of the dashed border around the tab link in Firefox
		
		// Hide all of the content sections
		tabbed_section.hideAllContent();
		
		// Parse out the id from the tab's href and put it in a variable
		var contentIDArr = this.href.split("#");
		var contentID = contentIDArr[1];
		
		// Use the content section's ID to grab the correct content div and make it visible
		var tab_content = document.getElementById(contentID);
		tab_content.style.visibility = "visible";
	},
	
	deselectAllTabs: function() {
		for(var i=0; i<this.num_tabs; i++) {
			this.tab_links[i].className = "";
		}
	},
	
	hideAllContent : function() {
		for(var i=0; i<this.num_cws; i++) {
			this.tab_content_wrappers[i].style.visibility = "hidden";
		}
	}
}

function pageLoader() {
	tabbed_section.init();
}

window.addEvent(window,'load',pageLoader);

