$(document).ready(function(){
    if(location.hash != '')
    {
        hash_slug = location.hash;
        hash = hash_slug.replace(/^#/, '').replace(/-/, '/');
        hash = '/' + hash + '/?ajax=1';
        
        $('#page_content').load(hash);
    }
    
    $("a.ajax").click(function(){
        // Only set the hash if not at the index page.
        if($(this).attr('href') != '/')
        {
            var hash_slug = $(this).attr('href').replace(/^\//, '').replace(/\/$/, '').replace(/\//, '-');
            location.hash = hash_slug;
        }
        else
        {
            // Firefox does not handle an empty hash gracefully.
            // And by not gracefull, I really mean it explodes (uses
            // the HTML version as the request.path).
            if($.browser.mozilla)
            {
                location.hash = '#';
            }
            else
            {
                location.hash = '';
            }
        }
        
        $('#page_content').load($(this).attr('href') + '?ajax=1');

        return false;
    });
});