function imageset(name,preload){
	this.name=name;
	this.images=new Array();
	this.preloads=new Array();
	this.preload=preload;
	this.curindex=0;
	this.curimg=0;
	this.prepared=false;
}

function img(url,caption){
	this.url=url;
	this.caption=caption;
	this.current;
}	

imageset.prototype.getNext = function(){
	if(this.curindex==this.images.length-1){
		return(0);
	}
	else {
		return(parseInt(this.curindex+1));
	}
}

imageset.prototype.nextImg = function(maxlen){
	if(this.curimg==maxlen){
		return(0);
	}
	else {
		return(parseInt(this.curimg+1));
	}
}

imageset.prototype.cascade = function (imagenames,speed,delay){
	imgs=imagenames.split(",");
	if(this.prepared==false){
		idx=imgs.length;
		this.prepared=true;
	}
	else {
		idx=this.getNext();
	}
	this.getImg(imgs[this.curimg],idx);
	this.curindex=idx;
	this.curimg=this.nextImg(imgs.length-1);
	if(this.curimg==0 && this.prepared==true){
		this.playFilters(imagenames);
		setTimeout(this.name+'.cascade(\''+imagenames+'\','+speed+','+delay+')',delay);
	}
	else {
		this.cascade(imagenames,speed,delay);
		//setTimeout(this.name+'.cascade(\''+imagenames+'\','+speed+','+delay+')',speed);
	}
}

imageset.prototype.addImage = function(url,caption){
	ptr=this.images.length;
	this.images[ptr]=new img(url,caption);
	this.images[ptr].current=ptr;
	if(this.preload==true){
		this.preloads[ptr]=new Image();
		this.preloads[ptr].src=url;
	}
}

imageset.prototype.getShow = function(image,speed,delay){
	next=this.getNext();
	this.getImg(image,next);
	if(document.images[image].filters){
		document.images[image].filters.blendTrans.Play();
	}
	this.curindex=next;
	setTimeout(this.name+'.getShow(\''+image+'\',\''+speed+'\','+delay+')',speed);
}

imageset.prototype.getImg = function (replace,index){
	document.images[replace].style.filter="blendTrans(duration=1)";
	document.images[replace].style.filter="blendTrans(duration=crossFadeDuration)";
	if(document.images[replace].filters){
		document.images[replace].filters.blendTrans.Apply();
	}
	document.images[replace].src=this.preloads[index].src;
	if(this.images[index].caption!="" && document.getElementById(this.name+"_caption")){
		rExp = /\|/gi;
		document.getElementById(this.name+"_caption").innerHTML=this.images[index].caption.replace(rExp,"<BR>");	
	}
}

imageset.prototype.playFilters = function(images){
	imgs=images.split(",");
	setTimeout(this.name+'.playNow(\''+images+'\',0)',1000);
}

imageset.prototype.playNow = function(images,index){
	imgs=images.split(",");
	if(!this.curplay){
		this.curplay=0;
	}
	if(this.curplay==imgs.length){
		this.curplay=0;
		return(false);
	}
	else {
		if(document.images[this.curplay] && document.images[imgs[this.curplay]].filters){
			document.images[imgs[this.curplay]].filters.blendTrans.Play();
		}
		this.curplay++;
		setTimeout(this.name+'.playNow(\''+images+'\','+this.curplay+')',1000);
	}
	
}

function getImage(image,src,caption){
	document.images[image].style.filter="blendTrans(duration=1)";
	document.images[image].style.filter="blendTrans(duration=crossFadeDuration)";
	if(document.images[image].filters){
		document.images[image].filters.blendTrans.Apply();
	}
	document.images[image].src=src;
	if(document.images[image].filters){
		document.images[image].filters.blendTrans.Play();
	}
	if(document.getElementById(image+"_caption")){
		rExp = /\|/gi;
		document.getElementById(image+"_caption").innerHTML=caption.replace(rExp,"<BR>");	
	}
}

function delayStart(wait,name,image,speed,delay){
	setTimeout(name+'.getShow(\''+image+'\',\''+speed+'\','+delay+')',wait);
}