
$j(document).ready(function() {
	initProductSubPageTabbing();
});


function initProductSubPageTabbing() {
	// get #-value from url
	var anchor = window.location.hash.replace('#','');
	$j('#sub-pages li').each(function(i, node) {
		// get tabs
		var tab = $j(node).children('h3').addClass('tab');
		// activate first page, hide others
		if (($j(tab).attr('id') == anchor) || ((!anchor) && (i==0)))
			$j(tab).addClass('active');
		else
			$j(node).css('display', 'none');
		// bind click event
		$j(tab).click(function(){
			// show page, hide others
			if ($j(node).css('display') == 'none') {
				$j('#sub-pages li').hide();
				$j(node).show();
			}
			// set active tab
			$j('h3.tab').removeClass('active');
			$j(this).addClass('active');
		});
		// move tabs in dom before list
		$j('#sub-pages').before(tab);
		// remove anchor to prevent jump to element
		$j(tab).removeAttr('id');
	});
}


