
function imageSlideShow(ImageSource, GaleryDIV, ImageDelay, FadeInDelay, Repeat)
{
    this.imgs = new Array();
    this.imgs = document.getElementById(ImageSource).getElementsByTagName("img");
    this.currentImage = 0;
    this.currentOpacity = 0;
    this.galeryDIV = document.getElementById(GaleryDIV);
    this.imageDelay = ImageDelay;
    this.fadeInDelay = FadeInDelay;
    this.thisObj = this;
    this.timer;
    this.repeat = Repeat;
    this.originalRepeat = Repeat;
    this.runing = false;
    this.paused = false;

    this.id = imageSlideShow.instances.length;
    imageSlideShow.instances[this.id] = this;

    this.galeryDIV.innerHTML= "<img src=\"" + this.imgs[0].src + "\" alt=\"\" />";

    this.setOpacity = function setOpacity(object, opacity)
    {
	object.style.opacity = (opacity / 100);
	object.style.MozOpacity = (opacity / 100);
	object.style.KhtmlOpacity = (opacity / 100);
	object.style.filter = "alpha(opacity=" + opacity + ")";
    }
    this.switchImage = function switchImage()
    {
        stoping = false;
	this.galeryDIV.style.backgroundImage="url(" + this.imgs[this.currentImage].src + ")";
	if (this.imgs.length - 1 > this.currentImage)
	    this.galeryDIV.innerHTML= "<img src=\"" + this.imgs[this.currentImage + 1].src + "\" alt=\"\" />";
	else
	{
	    this.galeryDIV.innerHTML= "<img src=\"" + this.imgs[0].src + "\" alt=\"\" />";

	    this.repeat = this.repeat - 1;
	    if (this.repeat == 0)
	    {
	      stoping = true;
	      this.stop();
	      this.runing = true; //after automated stop don't run this slide show again by onmouseover event
	    }
	}
	this.setOpacity(this.galeryDIV.getElementsByTagName("img")[0], 0);
	this.currentOpacity = 0;
	
	if (!stoping)
	  this.timer = setTimeout('imageSlideShow.instances['+this.id+'].fadeIn()', this.imageDelay);

    }
    this.fadeIn = function fadeIn()
    {
	this.currentOpacity = this.currentOpacity + 10;
	this.setOpacity(this.galeryDIV.getElementsByTagName("img")[0], this.currentOpacity);
	if (this.currentOpacity < 100)
	{
	    this.timer = setTimeout('imageSlideShow.instances['+this.id+'].fadeIn()', this.fadeInDelay);
	}
	else
	{
	    this.currentImage = this.currentImage +1;
	    if (this.currentImage > this.imgs.length - 1)
		this.currentImage = 0;
	    this.switchImage();
	}
    }
    this.start = function start()
    {
	if (!this.runing)
	{
	  this.switchImage();
	  this.runing = true;
	}
	if (this.paused)
	{
	  this.paused = false;
	  this.fadeIn();
	}
    }
    this.stop = function stop()
    {
	clearTimeout(this.timer);
        this.runing = false;
        this.galeryDIV.innerHTML= "<img src=\"" + this.imgs[0].src + "\" alt=\"\" />";
        this.currentImage = 0;
        this.currentOpacity = 0;
	this.repeat = this.originalRepeat;
    }
    this.pause = function pause()
    {
	this.paused = true;
	clearTimeout(this.timer);
    }
}
imageSlideShow.instances = new Array();



