$(document).ready(function() {

    $("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)

    $("ul.topnav > li > a").click(function(e) { //When trigger is clicked...
        if ($(this).next().length)
            e.preventDefault();
    });
    
    $("ul.topnav > li > a").mouseover(function(e) {
        //Following events are applied to the subnav itself (moving subnav up and down)
        $(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click

        $(this).parent().hover(null, function() {
            $(this).parent().find("ul.subnav").slideUp('fast'); //When the mouse hovers out of the subnav, move it back up
        });
    });

    if (!canBookmark())
        $('.social .favourites').hide();

});

function bookmark(title, url) {    
    if (window.sidebar) { // firefox
        window.sidebar.addPanel(title, url, "");
    }
    else if (window.opera && window.print) { // opera
        var elem = document.createElement('a');
        elem.setAttribute('href', url);
        elem.setAttribute('title', title);
        elem.setAttribute('rel', 'sidebar');
        elem.click();
    }
    else if (document.all) {
        window.external.AddFavorite(url, title);
    }
}

function canBookmark() {
    if (window.sidebar && 'addPanel' in window.sidebar)
        return true;
    if (window.external && 'AddFavorite' in window.external)
        return true;
    if (window.opera && window.print)
        return true;
    return false;
}
