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

$(document).ready(function(){
    //click on "learn more..." popup links
  if($(".contentpopup")) {
    ContentPopups = $(".contentpopup");
    $(".contentpopup").each(function(){
        var popupParentID = "#" + $(this).parent().attr("id");
        $(popupParentID + " .featureicon," + popupParentID + " .popuplnk," + popupParentID + " h4," + popupParentID + " > h5").mouseover().css("cursor","pointer");
        $(popupParentID + " .popuplnk," + popupParentID + " .featureicon," + popupParentID + " h4," + popupParentID + " > h5").click(function(){
            if($.browser.msie) {
                $(popupParentID + " .contentpopup").css("display","block");
            }
            else {
                $(popupParentID + " .contentpopup").fadeIn("slow");
            }
            for(i = 0; i < ContentPopups.length; i++) {
                var otherPopupParentID = "#" + $(ContentPopups[i]).parent().attr("id");
                if(otherPopupParentID != popupParentID) {
                    $(otherPopupParentID + " .contentpopup").fadeOut("fast");
                }
            }            
            return false;
        });
    });
    }
    
    //click on "X" in popups
    $(".contentpopup .closebox").click(function(){
        if($.browser.msie) {
            $(this).parent().css("display","none");
        }
        else {
            $(this).parent().fadeOut("fast");
        }
    });
    
    //mouseleave for popups
    $(".contentpopup").mouseleave(function(){
        if($.browser.msie) {
            $(this).css("display","none");
        }
        else {
            $(this).fadeOut("fast");
        }
    });
    
    
    //set Z-Index re: featurepopups
    if($(".sbprodline")) {
        var SBProdLines = $(".sbprodline");
        for(i = 0; i < SBProdLines.length; i++) {
            $(SBProdLines[i]).css("zIndex",100-i);
        }
    }
    if($(".iconfeature") && $(".contentpopup")) {
        var IconFeatures = $(".iconfeature");
        for(i = 0; i < IconFeatures.length; i++) {
            $(IconFeatures[i]).css("zIndex",100-i);
        }
    }
    if($(".columns") && $(".contentpopup")) {
        var Columns = $(".columns, .iconfeature.wide");
        for(i = 0; i < Columns.length; i++) {
            $(Columns[i]).css("zIndex",100-i);
        }
    }

  //expand or collapse an inset graphic
  $(".inset.graphic.expand a").click(function(){
    var thisInsetGraphic = $(this).parent();
    var thisInsetGraphicID = thisInsetGraphic.attr("id");
    var thisIllus = $("#" + thisInsetGraphicID + " .illus");
    var thisIllusThb = $("#" + thisInsetGraphicID + " .illusthb");
    var expandClass = thisInsetGraphic.hasClass("expanded");
    var expandBtn = $("#" + thisInsetGraphicID + " .btn");
    if(thisInsetGraphic.hasClass("wide")) {
        var expandWidth = "72em";
        var expandLeft = "-46.1em";
        var expandMarginRight = "-46.1em";
    }
    else {
        var expandWidth = "52.4em";
        var expandLeft = "-26.7em";
        var expandMarginRight = "-24.8em";
    }
        
    expandBtn.css("display","none");
    expandBtn.toggleClass("collapse");
    thisIllusThb.toggle("fast");
    thisIllus.toggle("fast");
    if(expandClass != true) {
        thisInsetGraphic.animate({left:expandLeft},150,function(){
              $(this).animate({width:expandWidth},150,function(){ 
                    if($.browser.msie && $.browser.version == 6) {
                        $(this).animate({marginRight:expandMarginRight},150); 
                    }                 
                  expandBtn.css("display","block");    
                $(this).toggleClass("expanded");
              });
      });
    }
    else {
        thisInsetGraphic.animate({width:"24em"},150);  
        if($.browser.msie && $.browser.version == 6) {
            thisInsetGraphic.animate({marginRight:"2em"},150);
        }
        thisInsetGraphic.animate({left:"0"},150,function(){
        expandBtn.css("display","block");
        $(this).toggleClass("expanded");
      });
    }
    return false;            
    });

}); //end initializations
