// Currently only supporting IE
function MySlideShow(width, height, pause, imagesArray, startNum, slideshowName, linksArray)
{
	// Constructor
	this.width = width;
	this.height = height;
	this.pause = pause;
	this.imagesArray = imagesArray;
	this.linksArray = (linksArray != null) ? linksArray : null;
	this.currentImageNum = startNum;
	this.canvas1 = slideshowName + '_1';
	this.canvas2 = slideshowName + '_2';
	this.currentCanvas = this.canvas1;
	this.curPos = 0;
	if (document.getElementById && navigator.userAgent.indexOf("IE") != -1)
	{
		this.browser = "IE";
	}
	else if (document.getElementById && navigator.userAgent.indexOf("Mozilla") != -1)
	{
		this.browser = "Mozilla";
	}
	else
	{
		this.browser = "";
	}

	// Call where you want the slideshow to appear
	this.placeSlideshow = function()
	{
		document.writeln('<div style="position: relative; width: ' + this.width + 'px; height: ' + this.height + 'px; overflow: hidden;">');
		document.writeln('	<div id="' + this.canvas1 + '" style="position: absolute; top: 0; left: 0; width: ' + this.width + 'px; height: ' + this.height + 'px; z-index: 2; filter: alpha(opacity=100); -moz-opacity: 1;">');
		if (this.linksArray && this.linksArray[this.currentImageNum] != 'undefined')
			document.writeln('		<a href="' + this.linksArray[this.currentImageNum] + '"><img name="ss" src="' + this.imagesArray[this.currentImageNum] + '" border="0" alt="" /></a></div>');
		else
			document.writeln('		<img name="ss" src="' + this.imagesArray[this.currentImageNum] + '" alt="" /></div>');
		document.writeln('	<div id="' + this.canvas2 + '" style="position: absolute; top: 0; left: 0; width: ' + this.width + 'px; height: ' + this.height + 'px; z-index: 1; filter: alpha(opacity=0); -moz-opacity: 0;">');
		document.writeln('		</div>');
		document.writeln('</div>');
	}

	this.preloadImages = function()
	{
		var array1 = this.imagesArray.slice(this.currentImageNum, this.imagesArray.length - 1);
		var array2 = (this.currentImageNum > 0) ? this.imagesArray.slice(0, this.currentImageNum - 1) : new Array();
		var preloadArray = array1.concat(array2);
		var rslt = new Array();
		for (x = 0; x < preloadArray.length; x++)
		{
			rslt[x] = new Image();
			rslt[x].src = preloadArray[x];
		}
	}

	// Start the show
	this.startAutomatic = function()
	{
		if (this.browser != "")
		{
			// Callwrapper
			this.callwrapper = new CCallWrapper(this, this.pause, 'goNextSlide', 'no');
			CCallWrapper.asyncExecute(this.callwrapper);
	
			this.preloadImages();
		}
	}

	// Stops the show
	this.stopAutomatic = function()
	{
		if (typeof(this.callwrapper) != "undefined")
		{ 
			this.callwrapper.cancel();
		}
	}

	// Advance one slide
	this.goNextSlide = function(stopAfter)
	{
		// Change current canvas and bring to front
		this.currentCanvas = (this.currentCanvas == this.canvas1) ? this.canvas2 : this.canvas1;
		this.currentImageNum = (this.currentImageNum == this.imagesArray.length - 1) ? 0 : this.currentImageNum + 1;

		if (this.browser == "IE")
			document.getElementById(this.currentCanvas).filters.alpha.opacity = 0;
		else if (this.browser == "Mozilla")
			document.getElementById(this.currentCanvas).style.MozOpacity = 0;

		if (this.linksArray && this.linksArray[this.currentImageNum] != 'undefined')
			document.getElementById(this.currentCanvas).innerHTML = '<a href="' + this.linksArray[this.currentImageNum] + '"><img src="' + this.imagesArray[this.currentImageNum] + '" border="0" alt="" /></a>';
		else
			document.getElementById(this.currentCanvas).innerHTML = '<img src="' + this.imagesArray[this.currentImageNum] + '" alt="" />';
		document.getElementById(this.currentCanvas).style.zIndex += 2;
		// Callwrapper
		this.callwrapper = new CCallWrapper(this, 0, 'advanceFrame', stopAfter);
		CCallWrapper.asyncExecute(this.callwrapper);
	}

	this.advanceFrame = function(stopAfter)
	{
		if ((this.browser == "IE") && (document.getElementById(this.currentCanvas).filters.alpha.opacity != 100))
		{
			this.curPos += 10
			document.getElementById(this.currentCanvas).filters.alpha.opacity += this.curPos;
			// Callwrapper
			this.callwrapper = new CCallWrapper(this, 50, 'advanceFrame', stopAfter);
			CCallWrapper.asyncExecute(this.callwrapper);
		}
		else if ((this.browser == "Mozilla") && (document.getElementById(this.currentCanvas).style.opacity != 1))
		{
			this.curPos += 10
			document.getElementById(this.currentCanvas).style.opacity = this.curPos / 100;
			// Callwrapper
			this.callwrapper = new CCallWrapper(this, 50, 'advanceFrame', stopAfter);
			CCallWrapper.asyncExecute(this.callwrapper);
		}
		else
		{
			this.curPos = 0;
			if (stopAfter == 'no')
			{
				// Callwrapper
				this.callwrapper = new CCallWrapper(this, this.pause, 'goNextSlide', 'no');
				CCallWrapper.asyncExecute(this.callwrapper);
			}
			return true;
		}
	}

	this.gotoSlide = function(num)
	{
		if (this.browser != "")
		{
			this.stopAutomatic();
			this.currentImageNum = num - 1;
			this.goNextSlide('yes');
		}
		else
		{
			document.images['ss'].src = this.imagesArray[num-1];
		}
	}
}
