// Show subnavigation for header in IE6
headerMenu = function(id) {
  if (document.all&&document.getElementById) {
    navRoot = document.getElementById(id).firstChild;
    for (i=0; i<navRoot.childNodes.length; i++) {
      node = navRoot.childNodes[i];
      if (node.nodeName=="LI") {
        node.onmouseover=function() {
          this.className+=" over";
        }
        node.onmouseout=function() {
          this.className=this.className.replace(" over", "");
        }
      }
    }
  }
}

// load slideshow for suppliers pool
function SlideShow() {
  Effect.Fade(slides[no], { duration:1, from:1.0, to:0.0 });
  if (++no == slides.length) {
    no = 0;
  }
  Effect.Appear(slides[no], { duration:1, from:0.0, to:1.0 });
}

var Carousel = Class.create({
  initialize: function(element, interval) {
    element = $(element);
    this.element = element;
    this.elements = element.childElements();
    this.interval = interval || 4000;
    this.current = 0;
    
    this.hide();
    setInterval(this.update.bind(this), this.interval);
  },
  
  hide: function() {
    this.elements.each(function(element) {
      Element.hide(element);
    });
    Element.show(this.elements.first());
  },
  
  update: function() {
    Effect.Fade(this.elements[this.current], { duration:1, from:1.0, to:0.0 });
    if (++this.current == this.elements.length) {
      this.current = 0;
    }
    Effect.Appear(this.elements[this.current], { duration: 1, from: 0.0, to: 1.0, queue: "end" });
  }
});

autoload = function() {
  // load subnavigation
  headerMenu("Navigation");
  
  // load slideshow
  setInterval('SlideShow()', 4000);
}

window.onload = autoload;
