function f(tdName) {
  var td = document.getElementById(tdName);
  td.style.background="#446666";
}

function fo(tdName) {
  var td = document.getElementById(tdName);
  td.style.background="transparent";
}

function mOn (imageName) {
  document.images[imageName].src=eval(imageName + "_on.src");
}

function mOf (imageName) {
  document.images[imageName].src=eval(imageName + "_of.src");
}

function confirmSubmit() {
  var agree=confirm("Are you sure you wish to continue?");
  if (agree)
  return true ;
  else
  return false ;
}

function PopUp(url, height, width) {
  help = window.open(url, "help", "scrollbars,width="+width+",height="+height+",top=0,left=0");
  window.help.focus();
}

function copyCheckbox(obj)
{
 if(obj.isSimilar.checked == true)
 {
  obj.fullNamePickup.value = obj.fullname.value;
  obj.addressPickup.value = obj.address.value;
  obj.cityPickup.value = obj.city.value;
  obj.postcodePickup.value = obj.postcode.value;

  obj.countyId.selectedIndex = obj.countryUkId.selectedIndex;
 }
 else
 {
 obj.fullNamePickup.value = '';
 obj.addressPickup.value = '';
 obj.cityPickup.value = '';
 obj.postcodePickup.value = '';

 obj.countyId.selectedIndex = '';
 }
}




/* Array to hold preloaded images */

var pics = Array();

/* Number of increments to use when resizing */
var steps = 10;

/* Holds the DOM reference to the image */
var display;

/* Keeps track of where we are in the process */
var counter;

/* Total number of images in the gallery */


function init()
{
	for (i=0; i<product_images.length; i++)
	  loadImage(i);
	  
	counter = 0;
	display = document.getElementById('display_image');

/*	loadImage(0);
	loadImage(1);
	loadImage(totalimages-1);*/
}

function loadImage(index) {
	if (! pics[index]) {
		pics[index] = new Image();
		pics[index].src = product_images[index];
	}
}

function advance()
{
	if (counter == totalimages) {
		previous = counter;
		counter = 1;
	} else if (counter == totalimages - 1) {
		previous = counter;
		counter++
	} else {
		previous = counter;
		counter++;
		loadImage(counter + 1);
	}
	
	initSlide();
}

function retreat()
{
	if (counter == 1) {
		previous = counter;
		counter = totalimages;
		loadImage(totalimages - 1);
		nextcounter = counter - 1;
	} else if (counter == 2) {
		previous = counter;
		counter--;
	} else {
		previous = counter;
		counter--;
		loadImage(counter - 1);
	}
	
	initSlide();
}

function getImage(index)
{
	 counter = index;
	 /*if (index == 0) previous = totalimages;
	 else previous = counter -1;
	 
	 if (index == totalimages -1) nextcounter = 0;
	 else nextcounter = counter + 1;*/
	 initSlide();
}

function initSlide()
{
	/*width_diff = pics[counter].width - pics[previous].width;
	width_increment = width_diff / steps;
	height_diff = pics[counter].height - pics[previous].height;
	height_increment = height_diff / steps;*/
	
	width_increment  = 0;
	height_increment = 0;
	slide(100, width_increment, height_increment, 1);
}

function slide(opacity, width_increment, height_increment, tally_steps)
{
	if (tally_steps != steps) {
		tally_steps++;
		display.width += width_increment;
		display.height += height_increment;
		setOpacity(opacity)
		opacity -= 100/steps;
		window.setTimeout("slide("+opacity+","+width_increment+","+height_increment+","+tally_steps+")", 50);
	} else {
		display.style.backgroundImage = 'url('+ product_images +')';
		setOpacity(0);
		display.src = product_images[counter];
		display.width = pics[counter].width;
		display.height = pics[counter].height;
		fadeIn(10);
	}
}

function setOpacity(opacity) 
{
	opacity = (opacity == 100)?99.999:opacity;
 
	// IE/Win
	display.style.filter = "alpha(opacity:"+opacity+")";
 
	// Safari<1.2, Konqueror
	display.style.KHTMLOpacity = opacity/100;
 
	// Older Mozilla and Firefox
	display.style.MozOpacity = opacity/100;
  
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	display.style.opacity = opacity/100;
}

function fadeIn(opacity) 
{
	if (opacity <= 100) 
	{
		setOpacity(opacity);
		opacity += 5;
		window.setTimeout("fadeIn("+opacity+")", 50);
	}
}

function fadeOut(opacity) 
{
	if (opacity <= 100) 
	{
		setOpacity(opacity);
		opacity -= 5;
		window.setTimeout("fadeOut("+opacity+")", 50);
	}
}
