﻿
function SlideShow(names, links, image1, image2, timeout, fadespeed)
{
    this._names = names;
    this._links = links;
    this._image1 = image1
    this._image2 = image2;
    this._timeout = timeout;
    this._fadespeed = fadespeed;
    this._curr_image = 0;
    
    this._curr_image = this._names.length;
    this.UpdateImage(false); 
}


SlideShow.prototype.UpdateImage = function (isReverse) {
	var captionStr;
	
	this._curr_image++;
	var next_image = this._curr_image + 1;
	if (this._curr_image >= this._names.length) {
		this._curr_image = 0;
		next_image = 1;
	}
	else if (next_image >= this._names.length) {
	    next_image = 0;
	}
	
    var o = this;
	var imageElement = document.getElementById(isReverse? o._image2 : o._image1);
	imageElement.src = this._names[this._curr_image];

    if (o._links != null && o._links[o._curr_image] != undefined)
    {      
	    imageElement.onclick = function() 
        {
	        window.location.href = o._links[o._curr_image];
        };
    }
    else
    {
        imageElement.onclick = null;
    }
	if (this._fadespeed != undefined)
	{	
	    var imageElement2 = document.getElementById(isReverse? o._image1 : o._image2);
	    imageElement2.src = o._names[next_image];
	    function NextUpdateImage()
        {
            o.UpdateImage(!isReverse);
        }
	    function NextFadeOut()
        {
            opacity(isReverse? o._image2 : o._image1, 100, 0, o._fadespeed, NextUpdateImage);
        }
        function WaitNextFadeOut()
        {
            setTimeout(NextFadeOut, o._timeout);
        }
	    opacity(isReverse? o._image2 : o._image1, 0, 100, o._fadespeed, WaitNextFadeOut);
	}
	else
	{
	    function NextUpdateImage()
        {
            o.UpdateImage();
        }
	    setTimeout(NextUpdateImage, o._timeout);	    
    }
}

if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();