var buttonContainerId = 'tab_buttons';
var contentContainerId = 'tab_content';

// Hide all tabs
function hideTabs() {
	jQuery('div.tabContent').hide();
	jQuery('div#'+buttonContainerId+' li.current').removeClass('current');
}

// Show the tab with the specified id
function showTab(tabId) {
	hideTabs();
	jQuery('#'+tabId).show();
	jQuery('a[rel="'+tabId+'"]').parents('li').addClass('current');
}

// Hide all tabs, show the first tab, populate event handlers on tab buttons
function initializeTabs() {
	hideTabs();
	var currentTabId = false;
	if ( location.toString().indexOf('#') != -1 ) currentTabId = location.toString().substring(location.toString().indexOf('#')+1);
	if ( !currentTabId )
	{
		jQuery('div.tabContent').eq(0).show();
		jQuery('#'+buttonContainerId+' li').eq(0).addClass('current');
	} else {
		showTab(currentTabId);
	}
	jQuery('#'+buttonContainerId+'>ul>li>a').click(
		function()
		{
			showTab( jQuery(this).attr('rel') );
			return false;
		}
	);
	jQuery('#'+buttonContainerId+'>ul>li a.open').click(
		function()
		{
			jQuery(this).parent('div.gallery').find('a').eq(0).click();
			return false;
		}
	);
}

jQuery(initializeTabs);