var AjaxNavMenu = 
{
    init : function()
    {
        $('a[path]').bind
        ({
            click: function()
            {
                AjaxNavMenu.load_content(this.getAttribute('path'));
            },
            
            dblclick : function()
            {
                return false;
            },
            
            mouseover: function()
            {
                this.style.cursor = 'pointer'; //Show a click cursor to the user
                this.style.textDecoration = 'underline';
            },
            
            mouseout: function()
            {
                this.style.textDecoration = 'none';
            }
        });
        
        $('a[path]').filter('.first_level').bind
        ({
            click: function()
            {
                AjaxNavMenu.update_navmenu_style(this);
            }
        });
    },

    load_content : function(contentPath)
    {
        // jquery: hide our body content and show our progress indicator (immediately)
        $('#body-content').hide();
        $('#progress-indicator').show();
        
        // use ajax to load the specified content block (see js/ajax.js)
        getWidget('[[Content:Display path="'+contentPath+'"]]', 'body-content', AjaxNavMenu.on_load_content);
    },
    
    on_load_content : function()
    {
        // jquery: hide the progress indicator and fade in our body content (that was loaded earlier by ajax)
        $('#body-content').fadeIn(1000);
        $('#progress-indicator').hide();
        
        // Can you believe that this took 3 hours to figure out? Why? 'cause this isn't documented anywhere. 
        // I just came up with it through javascript debugging
        
        var sharethis_button = $('.st_sharethis_custom');
        
        if (sharethis_button.length != 0)
        {
            stWidget.addEntry
            ({
                service:"sharethis",
                element:sharethis_button[0],
                type:'custom'
            });
        }
    },
    
    update_navmenu_style: function(anchorEl)
    {
        // WARNING: this assumes that the element passed in is for an anchor tag.
        // cycle through all our list items and ensure they are not active.
        $(anchorEl).parents('ul').children('li').removeClass('active');
        
        // ensure that our selected list item is active
        $(anchorEl.parentNode).addClass('active');
    }
}

