var allowed;
var input;
Event.observe(window, 'load', function() {
   $A($('productThumbnails').getElementsByTagName('a')).each(function(a) {
      Event.observe(a, 'click', function(e) {
         Event.stop(e);         $('productPreviewArea').ImageLoader.zoomImage = a.getAttribute('zoom');
         $('productPreviewArea').ImageLoader.loadImage(a.href);
         
         var newDesc = (a.childNodes[0] && a.childNodes[0].tagName) ? a.childNodes[0].getAttribute('alt') : '';
         $('zoomDescription').fulldesc = newDesc;
         $('zoomDescription').update('<p>' + newDesc.truncate(20) + '</p>');
         
         var zoomLink = $('zoomImageLink');
         zoomLink.alt = newDesc;
         zoomLink.href = a.getAttribute('zoom');
         
         if(!zoomLink.href || zoomLink.href == '') zoomLink.style.visibility = 'hidden'; else zoomLink.style.visibility = '';
         myLightbox.updateImageList();
      });
   });
   // find variation dropdown, read dependson
   var addBox = document.body.getElementsByClassName('add-box');
   if(addBox.length > 0){
      addBox = addBox[0];
   } else {
      addBox = null;
   }
   if(addBox){
      var select = addBox.getElementsByTagName('SELECT');
      input = addBox.getElementsByTagName('INPUT');
      if(select.length > 0){
         select = select[0];
      } else {
         select = null;
      }
      if(input.length > 0){
         input = input[0];
      } else {
         input = null;
      }
      if(input && select){
         var cName = input.className.split(' ');
         for(var i = 0; i < cName.length; i++){
            if(cName[i].indexOf('dependsOn') != -1)
               allowed = cName[i].split('=')[1].split('|');
         }
         if(allowed.indexOf(String($F(select))) != -1){
            hideOOS();
         } else {
            showOOS();
         }
         Event.observe(select, 'change', function(e) {
            if(allowed.indexOf(String($F(this))) != -1){
               hideOOS();
            } else {
               showOOS();
            }
         });
      }
   }
});
function hideOOS(){
   $('OOS').update('');
   input.show();
}
function showOOS(){
   $('OOS').update('<br><b>The selected product variation is out of stock.</b>');
   input.hide();
}

