//var ROOT = '/2011/arca8/';
var ROOT = '/';


if (window.location.href.match(/#/)) {
    var hash = window.location.hash.split("#")[1];
    if (!hash) {
        hash = '';
    }
    if (hash == "/") {
        hash = "";
    }
    window.location = ROOT + hash;
}

$(function(){
    
    var supports_history_api = function () {
        return !!(window.history && history.pushState);
    }
    
    
    $("a[rel^='gallery']").prettyPhoto({theme:'dark_square'});

    $("#main").accordion({
        active: '.active',
        autoHeight: false,
        changestart: function (event, ui) {
            $('.menu.active').removeClass('active');
                                       
            var urlParts = ui.newHeader.attr('href').split(ROOT);
            var anchor = urlParts[1];                     
                                    
            if (supports_history_api() === true) {
                if (window.location.pathname !== ui.newHeader.attr('href')) {                
                    window.history.pushState({ menu: ui.newHeader.attr('href') }, "", ROOT + anchor);
                }
            } else {
                window.location = '#'+ anchor;
            }
        }
    });
    
    $('#logo').click(function () {
        $("#main").accordion("activate", 0); 
        
        return false;
    });
    
		var popped = ('state' in window.history), initialURL = location.href;
    $(window).bind("popstate", function(e) {
				// Ignore inital popstate that some browsers fire on page load
				var initialPop = !popped && location.href == initialURL;
				popped = true;
				if (initialPop) {
					return;
				}
	
        var state = window.history.state;
        if (state && state.menu) {
            $("a.menu[href='"+ state.menu +"']").click();
        } else {
            window.location.reload();
        }
    });
});


