// Slideshow 

var availableImages = new Array();
availableImages[0] = "/images/slideshow/0.jpg";
availableImages[1] = "/images/slideshow/1.jpg";
availableImages[2] = "/images/slideshow/2.jpg";
availableImages[3] = "/images/slideshow/3.jpg";
availableImages[4] = "/images/slideshow/4.jpg";

var availableLinks = new Array();
availableLinks[0] = "products.php5?reusable";
availableLinks[1] = "products.php5?fibre_optic_superled";
availableLinks[2] = "products.php5?phototherapy";
availableLinks[3] = "products.php5?entonox";
availableLinks[4] = "products.php5?f9_express_ctg_machine";

var currentIndex = 0;
var rotationSpeed = 4000;
var timerInstance;
var moviePlaying = true;
var x = 0;

function updateslideshow(imgId, manualUpadate) {
     var speed = Math.round(500 / 100);
     var timer = 1;
     for (i = 100; i >= 0; i--) {
          setTimeout("changeOpacity(" + i + ")", (timer * speed));
          timer++;
     }
     currentIndex = imgId;
	 setTimeout("switchSlides()", (speed * 110));
}

function switchSlides() {
     var slide = document.getElementById("slide");
     var backSlide = document.getElementById("backSlide");
     slide.src = backSlide.src;
	 changeOpacity(100);
     backSlide.src = availableImages[(currentIndex + 1)%(availableImages.length)];
     updateAdLink(currentIndex);
}

function changeOpacity(opacity) {
     var realImage = document.getElementById("slide");
     realImage.style.opacity = (opacity / 100);
     realImage.style.filter = "alpha(opacity=" + opacity + ")";
     realImage.style.MozOpacity = (opacity / 100);
     realImage.style.KhtmlOpacity = (opacity / 100);
}

function updateAdLink(imgId) {
     var obj = document.getElementById("adLink");
     obj.href = availableLinks[imgId];
}

var firstRun = true;

function rotatePhoto() {
	if (firstRun!=true) {
		getNextPhoto();
	}
	timerInstance = setTimeout("rotatePhoto()", rotationSpeed);
	firstRun = false;
}

function getNextPhoto() {
     x = currentIndex;
     if (x < availableImages.length - 1) {
          x++;
     } else {
          x = 0;
     }
     updateslideshow(x, false);
}

function stopTimer() {
	 clearTimeout(timerInstance);
}

function startTimer() {
	timerInstance = setTimeout("rotatePhoto()", rotationSpeed);
}