$('html').addClass('js');

$(document).ready(function(){

        //setup for Accordion animation on select SB Widgets
        $(".accordion").each(function(i){
                        
            var thisAccordion = $(this);            
            var thisAccordionID = "#" + thisAccordion.attr("id");            
            var thisDrawers = $(thisAccordionID + " .drawer");
                        
            var thisDrawersCount = thisDrawers.length;; 
            var lastDrawer = thisDrawers[thisDrawersCount - 1]; 
            $(lastDrawer).addClass("active");
            
            var thisDrawersContents = $(thisAccordionID + " .drawer .contents");    
            thisDrawersContents.each(function(){
            $(this).data("contentsHeight",$(this).attr("offsetHeight")-12);
        
            if($(this).parent().hasClass("active")) {
                $(this).css("height","auto");
            }
            else {
                $(this).parent().addClass("inactive");
                $(this).css("height","0");
            }
        });
        
        $(thisAccordionID + " .drawer h5").each(function(i){
            $(this).click(function(){
                for(d=0; d < thisDrawersCount; d++) {
                    if(i == d) {
                        $(thisDrawersContents[d]).parent().removeClass("inactive").addClass("active").addClass("active_ie");
                        $(thisDrawersContents[d]).animate({height: $(thisDrawersContents[d]).data("contentsHeight")}, 300);
                    }
                    else {
                        $(thisDrawersContents[d]).animate({height: "0"}, 300);
                        $(thisDrawersContents[d]).parent().removeClass("active").removeClass("active_ie").addClass("inactive");
                    }
                }
            });
            
        });
        
    });

    
    //add arrow to More links
    if($(".morelnk a")) {
        $(".morelnk a").append("<span class=\"arrow\">&nbsp;&raquo;</span>");
    }
    if($("a.morelnk")) {
        $("a.morelnk").append("<span class=\"arrow\">&nbsp;&raquo;</span>");
    }
    if($(".sptopic h6 a")) {
        $(".sptopic h6 a").append("<span class=\"arrow\">&nbsp;&raquo;</span>");
    }

    
    //populate Recent List cookie   
    $(".recentSelect").each(function(){
        var currentRecentSelectID = $(this).attr("id");
        $("#" + currentRecentSelectID + " a").click(function(){
            var currentLinkURL = $(this).attr("href");
            var currentLinkText = $(this).text();
            var currentRecentListID = currentRecentSelectID + "_recents";
            if(currentLinkURL != "") {
                setRecentSelections(currentLinkURL, currentLinkText, currentRecentListID, 11);
            }
        });
    });
    
    
    //setup Recent Lists
    $(".recentList").each(function(){
        var selectListID = $(this).parent().children().children(".recentSelect").attr("id");
        $(this).attr("id",selectListID + "_recents");
    });
    
    
    //highlight Start tab in Local Nav
    $("#localnav .tab.start").addClass("on");


    //setup for SB Widget flyout
    $(".sbflyout_button").click(function(){
        $(this).next(".sbflyout_popup").show("normal",function(){
            //$(this).animate({opacity:0.97},100);
        });
    });  
    
    $(".sbflyout_popup").mouseleave(function(){
        $(this).hide("fast");
    }); 
    
    if($(".sbflyout")) {
        $(".sbflyout").parent().parent().parent().css("zIndex",200);
        $(".sbflyout").parent().parent().css("zIndex",200);
        $(".sbflyout").parent().parent().siblings().css("zIndex",0);
        $(".sbflyout").parent().parent().parent().siblings(".sbwidget").css("zIndex",0);
    }
    
    $(".sbflyout").parent().parent().css("overflow","visible");

    
    //setup pointer cursor for Flyout Button in IE6 
    $(".sbflyout_button").hover(function(){
        $(this).css("cursor","pointer");
    });
    
}); //end document ready initializations


$(window).load(function(){

    //populate Recent Lists
    $(".recentList").each(function(){
        var recentListID = $(this).attr("id");
            getRecentItems(recentListID);
            if($.browser.msie) { 
                var recentListParentDrawer = $("#" + recentListID).parent().parent().parent().parent().attr("id");
          var siblingSelector = "#" + recentListParentDrawer;
          $(siblingSelector + " .drawer").animate({top:"0"},100);
            }
      else {
          $("#" + recentListID).show("slow");
      }
    });
    
}); //end window load initializations