var tabs = [];
var tabContainers = [];

$(function()
{
    tabs.push($('#homepage-button').get(0));
    tabContainers.push($('#page-homepage').get(0));
    $('#screen #menu-content a').each(function()
    {
	// note that this only compares the pathname, not the entire url
	// which actually may be required for a more terse solution.
	if(this.pathname == window.location.pathname && !$(this).hasClass('not-page'))
	{
	    tabs.push(this);
	    tabContainers.push($('#page-'+this.hash.replace(/#/,'')).get(0));
	}
    });
    
    check_tabs(tabContainers,document.location.hash);
    
    $(tabs).click(function(event)
    {
	if(!dialog_showed)
	{
	    var hash = this.hash;
	    // hide all tabs, show the one
	    check_tabs(tabContainers,hash);
	    document.location.hash = this.hash;
	}
        return false;
    });
});

function check_tabs(tabContainers,tab)
{
    $(tabContainers).each(function(index,container)
    {
	if($(container).attr('id') == 'page-'+tab.replace(/#/,''))
	    $(container).fadeIn('fast');
	else $(container).fadeOut('fast');
    });
    var label = $(tab+'-menu-item').text();
    if(tab.length == 0 || tab == '#homepage')
    {
	$('#page-homepage').css('display','block !important');
	label = 'Portfolio Michala Szajtera';
	if(menu_state) $('.menu-handle').first().click();
    }
    $('#screen-label').html('<h1>'+label+'</h1>');
}
