window.onload = function(){
  // verticallyCenterImages('div','products_thumb');
  window.setTimeout("verticallyCenterImages('div','products_thumb')", 100);
  //window.setTimeout("verticallyCenterImages('p','image')", 100);
}

function enlargeProductImage(src)
{
  document.getElementById('product_image').src = src;
}


// Center an image vertically within its parent element (no acceptable way to do this in CSS)
// Works by adding the appropriate margin to the top of the image
// specify tag name of image container (div,p etc.) and its class name
function verticallyCenterImages(tag_name, class_name)
{
  elements = document.getElementsByTagName(tag_name);
  for(i=0;i<elements.length;i++){
    c = elements.item(i);
    if(c.className.indexOf(class_name)>-1){
      image = getBuriedTag(c,'IMG');
      if(image.offsetHeight < 3){
        window.setTimeout("verticallyCenterImages('"+tag_name+"','"+class_name+"')", 100);
        return;
      }
      if(image != undefined){
        margin = Math.floor((c.offsetHeight - image.offsetHeight)/2);
        if(margin == 1){margin=0};
        image.style.marginTop = margin + 'px';
      }
    }

  }
}

function getBuriedTag(element,tagname)
{
  for(var i = 0; i < element.childNodes.length; i++){
    childNode = element.childNodes[i];
    if(childNode.nodeName == tagname){
      return childNode;
    }
    else if(childNode.childNodes.length > 0){
      if(tag = getBuriedTag(childNode,tagname)){
        return tag;
      }
    }
    //return false;
  }
}


function selectVariant(s){
  price_text = s.options[s.selectedIndex].text
  price_text = price_text.replace(/^[^£]*/,'')
  document.getElementById('price').innerHTML = price_text
  document.getElementById('was_price').innerHTML = '&nbsp;'
}
