document.observe("dom:loaded", function() {

   startList();

   new Rollover('main_nav');

   toggleNav();

   fixIE();

});

//Dropdown menu for IE6:

function startList() {
    if (document.all && document.getElementById) {

        navRoot = document.getElementById("main_nav");
        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", "");
                }
            }
        }

    }

}


//Toggle home page  navigation:

function toggleNav() {
   var litems = $$('#hc_nav li h2');
   for(i=0;i<litems.length;i++)
      litems[i].observe('click', function(event) {
         var element = event.findElement('li');
         var el_siblings = element.siblings();


         if(element.hasClassName('active')) {
            element.removeClassName('active');
            new Effect.Morph(element, {
              style: 'margin:0 0 0 -236px;',
              duration: 0.5
            });
         }
         else {
            for(i=0;i<el_siblings.length;i++) {
               if(el_siblings[i].hasClassName('active')) {
                  el_siblings[i].removeClassName('active');
                  new Effect.Morph(el_siblings[i], {
                    style: 'margin:0 0 0 -236px;',
                    duration: 0.1
                  });
               }
            }

            new Effect.Morph(element, {
              style: 'margin:0 0 0 -50px;',
              duration: 0.5
            });
            element.addClassName('active');
         }
      });
}

function fixIE() {
   var titems = $$('.account_section');
   for(i=0;i<titems.length;i++) {
      if(!(titems[i].hasClassName('first-in-row'))) {
         titems[i].insert({after: '<div class="clear"></div>'})
      }
   }
}


function fixIE2() {
   var buttons = $$('#popup .button1, #popup .button2, #popup .button3, #popup .button4, #popup .button5, .shoppinglist_popup .button1, .shoppinglist_popup .button2, .shoppinglist_popup .button3, .shoppinglist_popup .button4, .shoppinglist_popup .button5');
   for(i=0;i<buttons.length;i++) {
      buttons[i].setStyle({height: buttons[i].getHeight() + 'px'});
   }
}


