// onready
$(function(){

    // Main nav selected effect
    $("#nav li").each(function(){
        li = $(this);
        href = $("a",li).attr("href");
        if(href == "." || href == "/"){
            if(location.pathname == "/")
                li.addClass("selected");
        }else if(location.href.indexOf(href) > -1)
            li.addClass("selected");
    });

    $('#nav li').hover(function() {
            $(this).addClass('hover');
        }, function() {
            $(this).removeClass('hover');
    });


    // Sidebar nav selected effect
    $('#sidebar .navigation li').each(function(){
        li = $(this);
        href = $('a',li).attr('href');
        index = location.href.indexOf(href);
        // extra condition is for the first link that is a substring of all the other links, and would otherwise always match
        if(index > -1 && index+href.length == location.href.length)
            li.addClass('selected');
    });

    // SWFObject insertion
    if(location.pathname == "/"){
        $("#logo").addClass("flashed");
        var so = new SWFObject("media/idealersafe.swf", "flash-logo", "194", "60", "7", "#fff");
        so.write("logo");
    }


    // open articles in new window/tab, remembering it if it's kept open
    $('#articles-news #content a').attr("target","articles");

});
