
/* - ihs_theme.js - */
// for IE background images
try{
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}

jq(document).ready(function(){
   // strip height and width tags from mediaImage so IE will recognize CSS resizing
   jq(".mediaImage img").removeAttr("height").removeAttr("width");
   
   // set position of eventRegisterLink based on calendar height
   calHeight = jq(".portletCalendarList").height();
   jq(".eventRegisterLink").css("top",calHeight + 305);
   
   // blog archives portlet - expand years on click
   jq(".portletWeblogArchive h5").click(function() {
       jq(this).toggleClass("open");
       jq(this).siblings("ul").slideToggle(500);
   });
   
   // blog comments add required text
   jq("#commenting label").append("<span class='required'>(required)</span>");
   jq("#commenting #form-buttons-comment").attr("value","");
   
   // remove outline when clicking on the image map
   jq("area").focus(function() {
       if ( jq.browser.msie ) {
           this.blur();
       }
   });
});

// Featured Interface
jq(document).ready(function(){
    var numDisplay = jq("#featured-interface").attr("name");
    var totalItems = jq("#featured-interface .featuredItem").length;
    var totalPages = jq("#featured-nav .pageDot").length;
    var currentMargin = 0;
    var currentPage = 0;
    var itemWidth = 232;
    
    if (jq("body").hasClass("template-home_page_view")) {
        itemWidth = 470;
        jq(".featuredItem a").addClass("learnMore").text("learn more");
    }

    var totalWidth = "976px";
    
    if (numDisplay == 1) { totalWidth = "272px"; }
    if (numDisplay == 2) { totalWidth = "504px"; }
    if (numDisplay == 3) { totalWidth = "736px"; }
    
    jq("#featured-interface, #featured-nav").css("width",totalWidth);
    
    jq("#feature-strip").css("width",totalItems*236);
    jq("#home #feature-strip").css("width",totalItems*480);
    jq("#feature-visible").css("width",numDisplay*itemWidth);
    
    jq("#featured-interface").css("visibility","visible");
    
    // click the left arrow
    jq(".featureLeft").click(function() {
        if (currentMargin == 0) {
            currentMargin = -((totalPages - 1) * numDisplay * itemWidth);
            updatePage(totalPages-1);
            jq("#feature-strip").animate({marginLeft: currentMargin}, 700 );
        } else {
            currentMargin += numDisplay*itemWidth;
            updatePage(-1);
            jq("#feature-strip").animate({marginLeft: currentMargin}, 700 );
        }
    });
    
    // click the right arrow
    jq(".featureRight").click(function() {
        if (currentPage+1 == totalPages) {
            currentMargin = 0;
            updatePage(0);
            jq("#feature-strip").animate({marginLeft: currentMargin}, 700 );
        } else {
            currentMargin -= numDisplay*itemWidth;
            updatePage(1);
            jq("#feature-strip").animate({marginLeft: currentMargin}, 700 );
        }
    });
    
    // click a dot
    jq(".pageDot").click(function() {
        goHere = jq(this).attr("name");
        currentPage = parseInt(goHere);
        currentMargin = -(goHere * (numDisplay * itemWidth));
        jq("#feature-strip").animate({marginLeft: currentMargin}, 700 );
        
        jq("#featured-nav .pageDot").removeClass("current");
        jq("#featured-nav .pageDot").eq(currentPage).addClass("current");
    });
    
    // update current page number
    function updatePage(change) {
        if (change == 0) {
            currentPage = 0;
        } else {
            currentPage += change;
        }
        jq("#featured-nav .pageDot").removeClass("current");
        jq("#featured-nav .pageDot").eq(currentPage).addClass("current");
    }
});


