/******************************************************************************

MUMC X-BLIZZARD
---------------
Image fader by Yraen Ironheart.

******************************************************************************/


/*************
* X-BLIZZARD *
**************
Fader innerer and outerer. Add the id's of the things to be faded in the 
specified array. The first three variables are just generic settings. Note that
for images to fade, they must have unique ID tags in the html.
*/
var blizzard = {
   minOpacity: 80,
   maxOpacity: 100,
   fadeRate: 40,
   sponsors: document.getElementsByTagName('img'),

   /* isSponsor()
   **************
   */
   isSponsor: function(i) {
      if (this.sponsors[i].getAttribute('class') == 'fade' || this.sponsors[i].className == 'fade') {
         return true;
      }
      else return false;
   },
   
   /* init()
   *********
   Initialise the fading capability. MUMC Summit has a minOpacity of 40 since
   Blizzard is used in the Gear and Guides section; however, this minOpacity
   is too much for the Glacier photo gallery thumbnails where a minOpacity of
   80 is used.
   */
   init: function(site) {
      if (site == 'summit') {
         blizzard.minOpacity = 50;

         // Apply to main section banner
         blizzard.fadeIn('sectionBanner', 0);         
      }
      else {
         blizzard.minOpacity = 80;
      }
         
      for (i=0; i<this.sponsors.length; i++) {
         if (this.isSponsor(i)) {
            var sponsorID = this.sponsors[i].id;
            
            this.setOpacity(sponsorID, this.minOpacity);
            setAttributeById(sponsorID,'onmouseover', "blizzard.fadeIn('"+sponsorID+"', blizzard.minOpacity)");
            setAttributeById(sponsorID,'onmouseout', "blizzard.fadeOut('"+sponsorID+"', blizzard.maxOpacity)");
         }
      }
      
      return;
   },
   
   /* setOpacity()
   ***************
   Sets the opacity of the specified element.
   */
   setOpacity: function(id,opacity) {
      var currentOpacity;
      var obj = document.getElementById(id);
     
      if (opacity == 100) currentOpacity = 99.999;
      else currentOpacity = opacity;
 
      // IE/Win
      if (obj.style.filter != null)
         obj.style.filter = "alpha(opacity:"+currentOpacity+")";
     
      // Old Safari, Konquerer
      if (obj.style.KHTMLOpacity != null)
         obj.style.KHTMLOpacity = currentOpacity/100;
     
      // Old Mozilla Firefox
      if (obj.style.MozOpacity != null)
         obj.style.MozOpacity = currentOpacity/100;
     
      // New Safari, Firefox and CSS3
      if (obj.style.opacity != null)
         obj.style.opacity = currentOpacity/100;
   },
  
   /* fadeIn()
   ***********
   Fades in the element using a timeout.
   */
   fadeIn: function(id, opacity) {
      if (opacity <= this.maxOpacity) {
         this.setOpacity(id, opacity);
         opacity += 10;
         window.setTimeout("blizzard.fadeIn('"+id+"',"+opacity+")", this.fadeRate);
      }
   },

   /* fadeOut()
   ************
   Fades out the element using a timeout.
   */
   fadeOut: function(id, opacity) {
      if (opacity >= this.minOpacity) {
         this.setOpacity(id,opacity);
         opacity -= 10;
         window.setTimeout("blizzard.fadeOut('"+id+"',"+opacity+")",this.fadeRate);
      }
   }
}