/*
	cTabbedContent v0.2 - Bookmarkable, expandable tabbed content
	written by Hall (http://hall.xetech.org)

*/

$(document).ready(function() {
	//Attach events						   
	$('.cTabbedContent .tabs ul li a').mousedown(function(){
		switchTBC($(this).attr("href"));
	});
	initTBC();
});

function initTBC() {
	// If hash not exists, this indicates first-time user is accessing the page
	var h = document.location.hash;
	if(h == '') {
		toggleTab(ieHashFix($('.cTabbedContent .tabs ul li:first-child').find('a').eq(0).attr("href")));
		toggleContent($('.cTabbedContent .content>div:first-child').id());
	} else {
	// If hash exists, switch to that tab
		switchTBC(h);
	}
}

function switchTBC(h) {
	h = ieHashFix(h);
	toggleTab(h);
	toggleContent(h.replace('#',''));
}

function toggleContent(id) {
	$('.cTabbedContent .content>div').each(function(){
		$(this).attr("class", 'section').addClass((this.id == id || id == 'Section-All') ? 'show' : 'hide');
	});	
}

function toggleTab(h) {
	$('.cTabbedContent .tabs ul').find("li").each(function(){
		$(this).attr("class", (ieHashFix($(this).find('a').eq(0).attr("href")) == h) ? 'current' : '');
	});
}

function ieHashFix(h) {
	/* Dirty IE hack */
	return '#' + h.split('#')[1];
}