
$(document).ready(function(){
	$('#calendarTab > div').hide(); // Hide all divs
	$('#calendarTab > div:first').show(); // Show the first div
	$('#calendarTab ul li:first').addClass('active'); // Set the class for active state
	$('#calendarTab ul.calendarTabs li a').click(function(){ // When link is clicked
		$('#calendarTab ul.calendarTabs li').removeClass('active'); // Remove active class from tab
		$(this).parent().addClass('active'); //Set parent of clicked tab link class to active
		var currentTab = $(this).attr('href'); // Set currentTab to value of href attribute
		$('#calendarTab > div:visible').hide(); //hide visible div
		$(currentTab).show(); //show target div
		return false;
	});
	$('#HPtab > div').hide(); // Hide all divs
	
	// append ?tab=tabName to the URL to show the tabName tab first where tabName is the tab anchor name
	var queryStringParts = location.search.substring(1).split('&');
	var initialTab = null;
	for(i=0;i<queryStringParts.length;i++) {
		var tempParts = queryStringParts[i].split('=');
		if(tempParts[0] == 'tab') {
			initialTab = tempParts[1];
			break;
		}
	}
	var initialTabAnchor = null;
	
	if(!(initialTab === '')) {
		$('#HPtab > ul.HPtabs li a').each(function() {
			var anchorTabPart = this.href.split('?')[1].split('=')[1];
			if(anchorTabPart == initialTab) {
				initialTabAnchor = $(this);
			}
		});
	}
		
	if(initialTabAnchor != null && initialTabAnchor.length != 0) {
		$('#'+initialTab).show();
		initialTabAnchor.parent().addClass('active');
	} else {
		// either no initial tab was specified or the specified tab could not be found
		// just show the first tab
		$('#HPtab > div:first').show(); // Show the first div
		$('#HPtab ul li:first').addClass('active'); // Set the class for active state
	} 	
});
