$(document).ready(function() {

    var contentWrapID = '___content-wrapper';
    
    $('#content').wrap('<div id="' + contentWrapID + '></div>');
    
    function showNewContent() {
        $("#" + contentWrapID).slideDown();
        $('#load').fadeOut();   
    }
    
    function pageload(hash) {
        if(hash) {
            $("#" + contentWrapID).load(hash + " #content",'',function(){
                if($('img:last',this).get(0)) {
                    $('img:last',this).load(function(){
                        showNewContent();
                    });
                } else {
                    showNewContent();
                }

            });
        } else {
            $("#" + contentWrapID).load("index.html #content");
        }
    }
    $.historyInit(pageload);
    
    $('#nav li a').click(function(){
        
        var hash = $(this).attr('href');
        hash = hash.replace(/^.*#/, '');
        $("#" + contentWrapID).slideUp(300,function(){
            $.historyLoad(hash);
        });
        if(!$('#load').get(0)) {
            $('#wrapper').append('<span id="load">LOADING...</span>');
        }
        $('#load').fadeIn('normal');
        return false;
    
    });
	    $('#navequipment li a').click(function(){
        
        var hash = $(this).attr('href');
        hash = hash.replace(/^.*#/, '');
        $("#" + contentWrapID).slideUp(300,function(){
            $.historyLoad(hash);
        });
        if(!$('#load').get(0)) {
            $('#wrapper').append('<span id="load">LOADING...</span>');
        }
        $('#load').fadeIn('normal');
        return false;
    
    });

});
