﻿function slideshow( name, dst1, dst2, arr, fade, delay, step )
{
	this.images = arr;
	this.object1 = dst1;
	this.object2 = dst2;
	this.opacity1 = 0;
	this.opacity2 = 0;
	this.fade = fade;
	this.delay = delay;
	this.actImg = 0;
	this.maxImg = this.images.length;
	this.name = name;
	this.step = step;
	this.direction = 0;
	this.pause = 0;
	this.interval = '';
	
	this.doSlide = function ()
	{
		if( ( this.direction == -1 && this.opacity1 == 0 ) || ( this.direction == 1 && this.opacity2 == 0 ) )
		{
			if( this.maxImg > 2 )
			{
				this.actImg++;
				if( this.actImg == this.maxImg )
					this.actImg = 0;
				if( this.opacity1 == 0 )
					this.object1.src = this.images[this.actImg];
				if( this.opacity2 == 0 )
					this.object2.src = this.images[this.actImg];
			}
			this.direction *= -1;
			this.pause = 0;
		}
		if( this.pause < delay )
			this.pause++;
		else
		{
			this.opacity1 = this.opacity1 + this.direction * this.step;
			this.opacity2 = this.opacity2 - this.direction * this.step;
			this.setOpacity( 1, this.opacity1 );
			this.setOpacity( 2, this.opacity2 );
		}
	}
	
	this.init = function ()
	{
		this.object1.src = this.images[0];
		this.object2.src = this.images[1];
		this.actImg = 1;
		this.direction = -1;
		this.opacity1 = 100;
		this.opacity2 = 0;
		this.setOpacity( 1, 100 );
		this.setOpacity( 2, 0 );
		eval("window."+this.name+" = this;" );
		this.interval = window.setInterval( "window."+this.name+".doSlide()", this.fade );
	}
	
	this.setOpacity = function (num,opacity)
	{
		switch( num )
		{
			case 1:
				object = this.object1.style;
				break;
			case 2:
				object = this.object2.style;
				break;
			default:
				return null;
				break;
		}
		object.opacity = (opacity / 100);
		object.MozOpacity = (opacity / 100);
		object.KhtmlOpacity = (opacity / 100);
		object.filter = "alpha(opacity=" + opacity + ")";
	}
}


