var $ = function(id) {
  return document.getElementById(id);
}

function swapThumb(newSrc) {
  if ($('mimg')) {
    $('mimg').src = newSrc;
  }
}

function toggleTab(index) {
  var title = $('prod-tab-titles');
  if (title) {
    var links = title.getElementsByTagName("A");
	for (var i = 1; i <= links.length; i++) {
      if (i == index) {
	    links[i-1].id = "sel"
	  }
	  else links[i-1].id = "";
	}
	
	for (var i = 1; i <= 3; i++) {	  
	  var content = $('tab' + i);
	  if (content) {
	    content.style.display ='none';  
	  }
	}
	$('tab' + index).style.display = 'block';
  }
}

function emailAFriend(productName) {
  var script = "I thought you might be interested in " + productName + ".\n\nYou can view it at\n" + window.location;
  var subject = encodeURI(productName + " from UK Camera Direct");
  window.location.href = 'mailto:?subject=' + subject + '&body=' + encodeURI(script);
}

// fix height 
var $$$ = function(tagName, className) {
  var allTags = document.getElementsByTagName(tagName);
  var ret = new Array();
  for (var i = 0 ; i < allTags.length; i++) {
    if (allTags[i].className && allTags[i].className == className) {
	  ret.push(allTags[i]);
	}
  }
  return ret;
};

function checkColourBoxes() {
  var colours = $$$("DIV", "bundle");
  var temp = new Array();
  for (var i = 0; i < colours.length; i++) {
	temp.push(colours[i]);
    if ((i + 1) % 2 == 0) {
	  var theHighest = 0;
	  for (var j = 0; j < temp.length; j++) {
	    if (temp[j].offsetHeight > theHighest) theHighest = temp[j].offsetHeight;
	  }
	  
	  for (var j = 0; j < temp.length; j++) {
	    temp[j].style.height = theHighest + "px";
	  }
	  temp = new Array();
	}
  }
}

if (window.attachEvent) { 
  window.attachEvent("onload", checkColourBoxes); 
} 
else {  
  window.addEventListener("load", checkColourBoxes, false); 
}
