// -----------------------------------------------
//   --->   Ultimate Javascript Slideshow   <---
//   --->   Author: Znupi                   <---
//   --->   Contact: znupi69@gmail.com      <---
// -----------------------------------------------


imgs = [ [ "images/covershots/SS-093-HI020112041.jpg", "images/covershots/SS-100-HI020121083.jpg", "images/covershots/SK090605003.jpg", "images/covershots/SK080605330.jpg", "images/covershots/SK080829139.jpg", "images/covershots/SK070622405.jpg", "images/covershots/NS070726248.jpg", "images/covershots/BC080709101.jpg", "images/covershots/AB090719022.jpg", "images/covershots/SK091204021.jpg", "images/covershots/NL070727336.jpg", "images/covershots/PE070806307.jpg", "images/covershots/MI070720065.jpg", "images/covershots/SK090715101.jpg", "images/covershots/SK071007012.jpg", "images/covershots/NL090913069.jpg", "images/covershots/SK090613163.jpg", "images/covershots/ON070721085.jpg", "images/covershots/MB090807181.jpg", "images/covershots/AB070917315.jpg" ] ]; // The second argument passed to createJsArray() represents the number of images to load (it's the solution to your second request)
imgs2 = [ [ "images/testimonials/testimonial09.gif", "images/testimonials/testimonial05.gif", "images/testimonials/testimonial10.gif", "images/testimonials/testimonial04.gif", "images/testimonials/testimonial02.gif", "images/testimonials/testimonial08.gif", "images/testimonials/testimonial07.gif", "images/testimonials/testimonial03.gif", "images/testimonials/testimonial06.gif" ] ];
var mySlideShow1 = new SlideShow(imgs, 'slideDIV1', 4, 20, 0.05);
var mySlideShow2 = new SlideShow(imgs2, 'slideDIV2', 6, 20, 0.05);

function SlideShow(aImg, sID, iPause, iDelay, iStep) {
	var imgs = aImg;
	var preLoadObjs = Array();
	var loadedImgs = 0;
	var totalImgs= 0;
	var pause = iPause;
	var delay = iDelay;
	var step = iStep;
	var curIndex = 0;
	var curImgSet = 0;
	var curOpc = 0;
	var curDir = 1;
	var tOut = null;
	var sID = sID;
	var oDIV = null;
	var oIMG = null;
	var i;
	this.init = function() {
		oDIV = document.getElementById(sID);
		oIMG = oDIV.getElementsByTagName("img")[0];
		for (i=0; i < imgs.length; i++) totalImgs += imgs[i].length;
		for (i=0; i < imgs.length; i++) {
			for (j=0; j < imgs[i].length; j++) {
				preLoadObjs[preLoadObjs.length] = new Image();
				preLoadObjs[preLoadObjs.length-1].src = imgs[i][j];
				if (!window.opera) preLoadObjs[preLoadObjs.length-1].onload = countLoadedImgs;
				if (i == imgs.length-1 && j == imgs[i].length-1 && window.opera) {
					start();
				}
			}
		}
	}
	var countLoadedImgs = function() {
		loadedImgs++;
		if (loadedImgs == totalImgs) start();
	}
	var start = function(n) {
		oIMG.src = imgs[curImgSet][0];
		if (n) {
			oIMG.style.opacity = "1";
			if (window.ActiveXObject) oIMG.style.filter = "alpha (opacity=100)";
			curOpc = 1;
			oDIV.style.backgroundImage = "url('" + imgs[curImgSet][1] + "')";
		}
		curIndex++;
		if (n) tOut = setTimeout(doSlide, pause*1000);
		else doSlide();
	}
	var doSlide = function() {
		if (!curDir) {
			curOpc-=step;
			oIMG.style.opacity = curOpc;
			if (window.ActiveXObject) oIMG.style.filter = "alpha (opacity=" + (curOpc*100) + ")";
			if (curOpc > 0) tOut = setTimeout(doSlide, delay);
			else {
				changeImgs();
				curDir = 1;
				tOut = setTimeout(doSlide, pause*1000);
			}
		}
		else {
			curOpc+=step;
			oIMG.style.opacity = curOpc;
			if (window.ActiveXObject) oIMG.style.filter = "alpha (opacity=" + (curOpc*100) + ")";
			if (curOpc < 1) tOut = setTimeout(doSlide, delay);
			else {
				changeImgs();
				curDir = 0;
				tOut = setTimeout(doSlide, pause*1000);
			}
		}
	}
	var changeImgs = function() {
		if (curIndex < imgs[curImgSet].length-1) curIndex++;
		else curIndex = 0;
		if (!curDir) {
			oIMG.src = imgs[curImgSet][curIndex];
			curOpc = 0;
			oIMG.style.opacity = 0;
		}
		else oDIV.style.backgroundImage = "url('" + imgs[curImgSet][curIndex] + "')";
	}
	this.chgImgSet = function(newImgSet) {
		if (newImgSet != curImgSet) {
			clearTimeout(tOut);
			curImgSet = newImgSet;
			curIndex = 0;
			start(1);
		}
	}
}
