/*******************************************************************
* File    : JSFX_TransSlide.js  © JavaScript-FX.com
* Created : 2002/11/04 
* Author  : Roy Whittle  (Roy@Whittle.com) www.Roy.Whittle.com 
* Purpose : To create a dynamic slide show.
*
* History 
* Date         Version        Description 
* 2002-08-04	1.0		First version
***********************************************************************/ 
if(!window.JSFX)
	JSFX = new Object();

document.write('<STYLE TYPE="text/css">.slideTrans{ filter:revealTrans(duration=1,transition=0) }</STYLE>');
document.write('<STYLE TYPE="text/css">.slideBlend{ filter:blendTrans(duration=1) }</STYLE>');

JSFX.slide = function(theImg, theUrl)
{
	this.theImg  = theImg;
	this.theUrl  = theUrl;
	this.loadImg = new Image();
}
JSFX.TransSlideShow = function()
{
	this.id		= JSFX.TransSlideShow.getId();
	this.state		= "stopped";
	this.timeId		= null;
	this.imgName	= this.id + "_I";
	this.currSlide	= -1;
	this.slides		= new Array();
	this.win		= null;

	this.startDelay   = 0;
	this.slideDelay	= 2000;
	this.transType	= 24;
	this.transDuration= 1;

	window[this.id] = this;
}
JSFX.TransSlideShow.slideNo = 0;
JSFX.TransSlideShow.getId = function()
{
	return "JSFXts" + JSFX.TransSlideShow.slideNo++;
}
JSFX.TransSlideShow.prototype.toHtml = function(offImg)
{
//   return('<IMG SRC="'+this.slides[0].theImg+'" NAME="'+this.imgName+'" class="slide'+(this.transType==24?"Blend":"Trans")+'">');
	document.write('<IMG SRC="'+this.slides[0].theImg+'" NAME="'+this.imgName+'" class="slide'+(this.transType==24?"Blend":"Trans")+'">');
}

JSFX.TransSlideShow.prototype.addSlide = function(theImg, theUrl)
{
	this.slides[this.slides.length]=new JSFX.slide(theImg, theUrl);
}
JSFX.TransSlideShow.prototype.setStartDelay    = function(startDelay)    {this.startDelay    = startDelay*1000;}
JSFX.TransSlideShow.prototype.setSlideDelay    = function(slideDelay)    {this.slideDelay    = slideDelay*1000;}
JSFX.TransSlideShow.prototype.setTransType     = function(transType)     {this.transType     = transType;}
JSFX.TransSlideShow.prototype.setTransDuration = function(transDuration) {this.transDuration = transDuration;}

JSFX.TransSlideShow.prototype.setSlide = function()
{
	var img = document.images[this.imgName];
	if(img.filters != null)
	{
		if(this.transType < 24)
			img.filters[0].Transition=this.transType;
		img.filters[0].Duration = this.transDuration;
		img.filters[0].apply();
	}
	img.src = this.slides[ this.currSlide ].theImg;
	if(img.filters != null)
		img.filters[0].play();
}

JSFX.TransSlideShow.prototype.animate = function()
{
	if(this.state=="running")
	{
		this.currSlide = (this.currSlide + 1) % this.slides.length;
		this.setSlide();
		this.timeId = this.setTimeout("animate()", this.slideDelay);
	}
}
JSFX.TransSlideShow.prototype.start = function()
{
	if(this.state == "stopped")
	{
		for(var i=0 ; i<this.slides.length ; i++)
			this.slides[i].loadImg.src = this.slides[i].theImg;
		this.currSlide = 0;
		this.state     = "running";
		var theImg     = document.images[this.imgName];
		theImg.onmousedown = this.clickFn;
		theImg.ss      = this;

		this.timeId = this.setTimeout("animate()", this.startDelay);
	}
}
JSFX.TransSlideShow.prototype.clickFn = function()
{
	var ss = this.ss;
	if(ss.win)
		if(!ss.win.closed)
			ss.win.close();
	if(ss.slides[ ss.currSlide ].theUrl)
	{
		ss.win = window.open(ss.slides[ ss.currSlide ].theUrl,"FadeSS");

	}
	return false;
}
JSFX.TransSlideShow.prototype.stop = function()
{
	clearTimeout(this.timeId);
	this.state="stopped";
}
JSFX.TransSlideShow.prototype.pause = function()
{
	if(this.state == "running")
	{
		clearTimeout(this.timeId);
		this.state="paused";
	}
}
JSFX.TransSlideShow.prototype.resume = function()
{
	if(this.state == "paused" || this.state == "stopped")
	{
		this.state="running";
		this.animate();
	}
}
JSFX.TransSlideShow.prototype.next = function()
{
	if(this.state=="paused")
	{
		this.currSlide = (this.currSlide + 1) % this.slides.length;
		this.setSlide();
	}
}
JSFX.TransSlideShow.prototype.prev = function()
{
	if(this.state=="paused")
	{
		this.currSlide = this.currSlide == 0 ? this.slides.length - 1 : this.currSlide - 1;
		this.setSlide();
	}
}
JSFX.TransSlideShow.prototype.getState = function()
{
	return this.state;
}
JSFX.TransSlideShow.prototype.getSlideCount = function()
{
	return this.slides.length;
}
JSFX.TransSlideShow.prototype.getCurrentSlide = function()
{
	return this.currSlide;
}
JSFX.TransSlideShow.prototype.setTimeout = function(f, t) 
{
	return setTimeout("window."+this.id+"."+f, t);
}