/*
rotate_promo.js
Rotates Promotional Images.

By: Carl Benton
LEDstuff.co.nz
8 March 2010 

*/

var interval = 7; // Period between images (in seconds) 
interval *= 1000;

var promo_index = 0;

image_list = new Array();
image_ALT = new Array();
image_HREF = new Array();

//********************************ADD new images HERE **********************************

image_list[promo_index] = "images/promo_credit_card.jpg";
image_ALT[promo_index] = "ANZ eGate™";
image_HREF[promo_index] = "";
promo_index ++;

image_list[promo_index] = "images/promo_stock_clearance.jpg";
image_ALT[promo_index] = "Stock Clearance";
image_HREF[promo_index] = "http://ledstuff.co.nz/specials.php";
promo_index ++;

image_list[promo_index] = "images/promo_MR16_5W.jpg";
image_ALT[promo_index] = "Latest 5W Lamps";
image_HREF[promo_index] = "http://ledstuff.co.nz/product_info.php?cPath=25&products_id=225";
promo_index ++;

image_list[promo_index] = "images/promo_keyring.jpg";
image_ALT[promo_index] = "Free Keyring Offer";
image_HREF[promo_index] = "http://ledstuff.co.nz/product_info.php?cPath=2&products_id=69";
promo_index ++;

image_list[promo_index] = "images/promo_torches.jpg";
image_ALT[promo_index] = "LED Torch Range";
image_HREF[promo_index] = "http://ledstuff.co.nz/index.php?cPath=2";
promo_index ++;

image_list[promo_index] = "images/promo_prices&quality.jpg";
image_ALT[promo_index] = "Price and Service Guarantee";
image_HREF[promo_index] = "http://ledstuff.co.nz/";
promo_index ++;

//************************************************************************************************

var number_of_images = image_list.length;
var recur_call = "rotateImage()";

 /* Loads the first image: */
function loadImage () {
  promo_index = 0;
  document['promo_image'].src = image_list[promo_index];
  document['promo_image'].alt = image_ALT[promo_index];
  document['promo_image'].title = image_ALT[promo_index];
  document.getElementById('promo_link').href = image_HREF[promo_index];
	clearTimeout(recur_call);
  recur_call = setTimeout("rotateImage()", interval);
}

 /* Rotates to the next image: */
function rotateImage () {
 /*   // Fading effect:
  if (navigator.appName == "Microsoft Internet Explorer") {
    document.images.left_image.style.filter="blendTrans(duration=2)"
    document.images.left_image.style.filter="blendTrans(duration=crossFadeDuration)"
    document.images.left_image.filters.blendTrans.Apply() 
    document.images.left_image.filters.blendTrans.Play()
  }*/
  promo_index = (promo_index+1) % number_of_images;
  document['promo_image'].src = image_list[promo_index];
  document['promo_image'].alt = image_ALT[promo_index];
  document['promo_image'].title = image_ALT[promo_index];
  document.getElementById('promo_link').href = image_HREF[promo_index];
	clearTimeout(recur_call);
  recur_call = setTimeout("rotateImage()", interval);
}

 /* Moves to the next image: */
function nextImage () {
 /*   // Fading effect:
  if (navigator.appName == "Microsoft Internet Explorer") {
    document.images.left_image.style.filter="blendTrans(duration=2)"
    document.images.left_image.style.filter="blendTrans(duration=crossFadeDuration)"
    document.images.left_image.filters.blendTrans.Apply() 
    document.images.left_image.filters.blendTrans.Play()
  }*/
  promo_index = (promo_index+1) % number_of_images;
  document['promo_image'].src = image_list[promo_index];
  document['promo_image'].alt = image_ALT[promo_index];
  document['promo_image'].title = image_ALT[promo_index];
  document.getElementById('promo_link').href = image_HREF[promo_index];
}

 /* Moves to the previous image: */
function prevImage () {
 /*   // Fading effect:
  if (navigator.appName == "Microsoft Internet Explorer") {
    document.images.left_image.style.filter="blendTrans(duration=2)"
    document.images.left_image.style.filter="blendTrans(duration=crossFadeDuration)"
    document.images.left_image.filters.blendTrans.Apply() 
    document.images.left_image.filters.blendTrans.Play()
  }*/
	if (promo_index == 0) promo_index = number_of_images-1;
	else promo_index--;
  document['promo_image'].src = image_list[promo_index];
  document['promo_image'].alt = image_ALT[promo_index];
  document['promo_image'].title = image_ALT[promo_index];
  document.getElementById('promo_link').href = image_HREF[promo_index];
}

function pauseRotation () {
	clearTimeout(recur_call);
}

function resumeRotation () {
  recur_call = setTimeout("rotateImage()", interval);
}
