function ttSlideShow (name,imagedisplay,textdisplay,imageset){
    this.name=name;
    this.imagedisplay=imagedisplay;
    this.textdisplay=textdisplay;
    this.imageset=imageset;
    this.interval=10000;
    this.fadelength=500;
    this.startFadeIn=false;
}

ttSlideShow.prototype.init = function(){
    this.imagedisplay=document.getElementById(this.imagedisplay);
    this.textdisplay=document.getElementById(this.textdisplay);
    this.preloadImages();
    var doc='<div style="'+(this.startFadeIn ? '' : 'background-image: url('+this.imageset[0].src+');')+'background-repeat: no-repeat;" id="'+this.name+'_blenddiv">';
    doc+='<img src="'+this.imageset[0].src+'" style="filter: alpha(opacity=0); -moz-opacity: 0; opacity: 0;" id="'+this.name+'_blendimage" alt="" />';
    doc+='</div>';
	if (this.counterdisplay){
		this.onImageChange(0);
	}
    this.imagedisplay.innerHTML=doc;
    this.currentimage=0;
	if (this.textdisplay){
		this.textdisplay.innerHTML=this.imageset[this.currentimage].description;
	}
    this.imagedisplay.slideshow=this;
    this.thread=setInterval("document.getElementById('"+this.imagedisplay.id+"').slideshow.nextImage();",this.interval);
	if (this.startFadeIn){
		opacity(this.name+'_blendimage',0,100,this.fadelength);
	}
}

ttSlideShow.prototype.preloadImages = function(){
    for (i=0; i<this.imageset.length; i++){
        image=new Image();
        image.src=this.imageset[i].src;
    }
}

ttSlideShow.prototype.nextImage = function(){
    this.gotoImage((this.currentimage+1) % this.imageset.length);
}

ttSlideShow.prototype.gotoImage = function(index){
    this.currentimage=index % this.imageset.length;
	if (this.counterdisplay) {
		this.onImageChange(index);
	}
	if (this.textdisplay){
		this.textdisplay.innerHTML=this.imageset[this.currentimage].description;
	}
    blendimage(this.name+'_blenddiv',this.name+'_blendimage', this.imageset[this.currentimage].src,this.fadelength);
}

ttSlideShow.prototype.onImageChange = function(index){
    var doc="";
    for (i=0; i<this.imageset.length; i++){
        doc+='<a class="'+(index==i?"counter_selected":"counter_normal")+'" href="javascript:document.getElementById(\''+this.imagedisplay.id+'\').slideshow.gotoImage('+i+')">'+(i+1)+'</a></span>';
    }

    doc+=' | <a href="javascript:document.getElementById(\''+this.imagedisplay.id+'\').slideshow.nextImage()">NEXT</a>';

    doc+='<div style="clear:both;"></div>';
    document.getElementById(this.counterdisplay).innerHTML=doc;
}

