////
//// support code for International Scholars Office site
////

//
// required:
//   jquery.js (version 1.2.6+) (see jquery.com)
//   jquery.ifixpng.js
//   jquery.preloadimages.js
//

$(document).ready(function(){

  //
  // fix png images for IE6
  //
  //$.ifixpng('/scholars/img/spacer.gif'); /// NOTE: no png images on ISchO site
  //$('img[@src$=.png]').ifixpng();

  //
  // image preloads and mouseovers
  //
  // function gets the mouseover version of the specified image src
  var getMouseoverSrc = function(src) {
    return src.replace(/_off/, '_on');
  }
  //
  // find nav item whose class is same as page, and highlight that item
  //
  $("#divprimarynav li")
    .each( function(i) {
      var liclass = this.className;
      if($("body").hasClass(liclass)) {
        var img = $(this).find("img");
        img.attr("src", getMouseoverSrc(img.attr("src")));
        return false; // break
      }
    });

  //
  // set up mouseover and preload
  // (assumes any image with '_off' in it needs a mouseover and preload)
  //
  $("img[src*='_off']")
    .each( function(i) {
      // set up two versions of image
      var src1 = this.src;
      var src2 = getMouseoverSrc(src1);
      // preload mouseover version
      $.preloadImages.add(src2);
      // save two values in the image itself
      this.src1 = src1;
      this.src2 = src2;
      // respond to mouseover/mouseout
      $(this).hover(
        function () { // mouseover function
          this.src = this.src2;
        },
        function () { // mouseout function
          this.src = this.src1;
        }
      );
    });
    // start preload
    $.preloadImages.start();

   //
   // attach click event to "back to top" links
   //
   $("p.backtotop a")
     .click( function() {
       window.scrollTo(0,0);
       return false;
     });



});
