headerMenu = function(id) {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById(id);
		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", "");
				}
			}
		}
	}
}
/*
pulldownMenus = function() {
	headerMenu("PulldownMenu");
}

window.onload=pulldownMenus;
*/
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

document.observe('dom:loaded', function(e) {
  if ($("Visual")) {
    $$("#Visual li").each(function(element) {
      element.removeClassName('hide');
    });
  }
  if ($('Visual')) {
    new Carousel("Visual", 4000);
  }
  headerMenu("PulldownMenu");
  
  if ($("SubNavigationSortiment")) {
    $$("#SubNavigationSortiment li .element").each(function(element) {
      element.setStyle({display:'none'});
    });
  }
  
  if ($$("#Content .gallery_wrapper").first()) {
    $$("#Content .gallery_wrapper").each(function(element) {
      var yumTinygallery = new tinygallery($(element.parentNode).identify(), {list_element : 'img'});
    });
  }
  
  // Glider für die Startseite
  if ($("StartCarousel")) {
    var my_glider = new Glider("StartCarousel", {
      duration: 0.5,
      autoGlide: true,
      frequency: 10
    });
    $$("#StartCarousel .section").each(function(element) {
      element.observe("click", function(event) {
        document.location = element.down("a").href;
      });
    });
  }
  
  // autosubmit für die box des idealfirberaters
  if ($("SportTeaserSelector")) {
    Event.observe($("SportTeaserSelector"), "change", function() {this.parentNode.parentNode.parentNode.parentNode.submit();});
  }
  
  
  // Akkordion für Nav3
  if ($("SubContent")) {
    $$("#SubContent li .element").each(function(element) {
      element.hide();
    });
    var yumAccordion = new accordion("SubContent", {
      classNames : {
        toggle : "toggler",
        toggleActive : "selected",
        content : "element"
      }
    });
  }
  
  
  if ($$("#SubNavigationSortiment .toggler a")) {
    pathsegments = self.location.pathname.split('/')
    var url = self.location.protocol + "//" + self.location.host + self.location.pathname + '#' + pathsegments[2];
    
    $$("#SubNavigationSortiment .toggler a").each(function(element) {
      if (url == element.href) {
        yumAccordion.activate(element.up(".toggler"));
      }
    });
  }
  
  
});

var Carousel = Class.create({
  initialize: function(element, interval) {
    element = $(element);
    this.element = element;
    this.elements = element.childElements();
    this.interval = interval || 4000;
    this.current = 0;
    if(this.elements.length > 1) {
      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" });
  }
});

