


// 10-09-06 -  this is complicated, but we want to make a whole class of items invisible
// and we want this to be achieved by the user clicking on one of any number of other items.
// So both the group to be disappeared and the group to have its onclick event altered
// are to be grabbed and worked on based on one of their CSS classes.
//
// NOTE: the two class names we expect to work with are disappearOnClick and causeDisappearance
// I assume these names are odd enough to avoid collision with any other Javascript we might use.





function getElementsByClassName(node, classname) {
 // 10-09-06 - I lift this from the talented Snook:
 //
 // http://www.snook.ca/archives/javascript/your_favourite_1/

   var a = [];
   var re = new RegExp('\\b' + classname + '\\b');
   var els = node.getElementsByTagName("*");
   for(var i=0,j=els.length; i<j; i++)
       if(re.test(els[i].className))a.push(els[i]);
   return a;
}


function addLoadEvent(func) {
 // 10-09-06 - I'm steaing this from Simon Willison:
 //
 // http://simon.incutio.com/archive/2004/05/26/addLoadEvent


 var oldonload = window.onload;
 if (typeof window.onload != 'function') {
   window.onload = func;
 } else {
   window.onload = function() {
     if (oldonload) {
       oldonload();
     }
     func();
   }
 }
}




var referenceToFunctionToDisappearElements = function() {
      var arrayOfBodyElements = document.getElementsByTagName("body");
      var referenceToBodyNode = arrayOfBodyElements[0];
      var arrayOfAllClickElements = getElementsByClassName(referenceToBodyNode, "disappearOnClick");

      for (var i=0; i < arrayOfAllClickElements.length; i++) {
        var referenceToOneElement = arrayOfAllClickElements[i];
        referenceToOneElement.style.display = "";
      }
}



addLoadEvent(function() {
       MM_preloadImages('images/sub/features02_easy.gif','images/sub/features03_turn.gif','images/sub/features03_rubbersleeve.gif','images/sub/features03_kwikfit.gif','images/sub/features03_nylontip.gif');
});



addLoadEvent(function() {
      var arrayOfBodyElements = document.getElementsByTagName("body");
      var referenceToBodyNode = arrayOfBodyElements[0];
      var arrayOfAllClickElements = getElementsByClassName(referenceToBodyNode, "causeDisappearance");

      var howManyElements =  arrayOfAllClickElements.length;
      for (var i=0; i < arrayOfAllClickElements.length; i++) {
        var referenceToOneElement = arrayOfAllClickElements[i];
        var oldClick = referenceToOneElement.onclick;
        if (typeof referenceToOneElement.onclick != 'function') {
          referenceToOneElement.onclick = referenceToFunctionToDisappearElements;
        } else {
          referenceToOneElement.onclick = function() {
            if (oldClick) {
              oldClick();
            }
            referenceToFunctionToDisappearElements();
          }
        }
      }
});
