function init() {
    if (!document.getElementsByTagName) return;
    var productImageThumbs = getElementsByAttribute("class", "productthumb");
	var now = new Date();
	
    for (var i = 0; i < productImageThumbs.length; i++) {
		/* make the thumb the current loop and create a link for it */
		var productImageThumb = productImageThumbs[i];  
		var imageLink = document.createElement("a");
		imageLink.setAttribute("href", "javascript:;");
		/* get the current thumb's parent and append the link to it */
        productImageThumb.parentNode.appendChild(imageLink);
		/* append the current thumb to the new link */
		imageLink.appendChild(productImageThumb);	
	    
		addEvent(imageLink, "click", loadLarge, false);
	}
	return true;
}

function loadLarge(e) {
  var t = window.event ? window.event.srcElement : e ? e.target : null;
  if (!t) return;	
  var largeHolder = document.getElementById("largeholder");
  var imageCaption = document.getElementById("imgcaption");
  var captionField = document.getElementById("captionfield");  
  /* the large image reference */
  var largeImage = largeHolder.getElementsByTagName("img")[0];
  /* create a new date object to get the current seconds. we pass these on the end of the large
  image call to make IE not cache the image but get the current one every time */
  var now = new Date();
  var newProduct = new Image();   
  /* get the target image */
  var targetImg = getEventTarget(e);
  /* alert any errors loading image */
  newProduct.onerror = function() {
    alert("Failed to load the image");
  }; 
  /* when the new product loads set the large image's data to the new image */
  newProduct.onload = function() {
  	largeImage.src = newProduct.src;
	largeImage.width = newProduct.width;
	largeImage.height = newProduct.height;
	largeImage.alt = targetImg.alt;
  }; 
  /* set the new product image to the src of the thumb - but in the large folder */
  newProduct.src = "assets/images/products/large/"+targetImg.src.substring(targetImg.src.indexOf("thumbs/")+7,targetImg.src.length)+"?t="+now.getHours();
  imageCaption.innerHTML = /[^\s+]/.test(targetImg.alt) ? " - " + targetImg.alt : targetImg.alt;
  for (var i=0; i<captionField.options.length; i++) {
    if (captionField.options[i].value == targetImg.alt) {
	  captionField.selectedIndex = i;
	  break;
	}
  }
  return true;
}

addLoadListener(init);
