window.FTGalleries=	{
                        all: new Array()
                   	};

function FTGallery(width)
{
	this.images= new Array();
	window.FTGalleries.all[this.id= window.FTGalleries.all.length]= this;
	
	this.width= width;

	this.position= 0;
	this.velocity= -5;

	return this;
}

FTGallery.prototype.addImage= function(anImageName)
{
	this.images[this.images.length]= anImageName;
}

FTGallery.prototype.resetMotion= function(e)
{
	gallery= 
		FTGalleries.all[parseInt(this.id.substring(8,this.id.length))];
	gallery.velocity= gallery.velocity<0?-5:5;
}

FTGallery.prototype.adjustMotion= function(e)
{
	var posx = 0;
    if (!e) var e = window.event;
	if (e.pageX) posx= e.pageX;
	else if (e.clientX || e.clientY)
		posx= e.clientX+document.body.scrollLeft;
	posx-= this.offsetLeft;
	gallery= 
		FTGalleries.all[parseInt(this.id.substring(8,this.id.length))];
	gallery.velocity= -(200*posx/gallery.width-100);
}

function FTGallerySlide()
{
	for(i= 0;i<FTGalleries.all.length;++i)
	{
		gallery= FTGalleries.all[i];
		gallery.position= gallery.position+gallery.velocity;
		if(-gallery.position>=200*(gallery.images.length))
			gallery.position+= 200*(gallery.images.length);
		else if(gallery.position>=0)
			gallery.position-= gallery.images.length*200;
		gallery.imagelist.style.left= gallery.position+"px";
	}
	window.setTimeout(FTGallerySlide,100);
}

function changeTo(newName)
{
	document.images["gallery_spotlight_0"].src= newName+".jpg";
}

FTGallery.prototype.print= function()
{
	document.writeln("<center><img name='gallery_spotlight_"+this.id+"' src='"+this.images[0]+".jpg' class='spotlight' width='500' height='332'/></center>");

	this.extra= Math.ceil(this.width/200);
	this.position= -this.extra*200;

	document.writeln("<div id='gallery_"+this.id+"' class='gallery' style='width: "+this.width+"'>");
	document.writeln("<div style='width:"+(this.extra*2+this.images.length)*200+"px; padding: 0px;'>");
	document.writeln("<div id='gallery_imagelist_"+this.id+"' style='left:"+this.position+"px'>");

	for(i= this.images.length-this.extra;i<this.images.length;++i)
		document.write("<img src='"+this.images[i]+"_thumbnail.jpg' width='200' height='133' onClick='changeTo(\""+this.images[i%this.images.length]+"\")'/>");
	for(i= 0;i<this.images.length+this.extra;++i)
		document.write("<img src='"+this.images[i%this.images.length]+"_thumbnail.jpg' width='200' height='133' onClick='changeTo(\""+this.images[i%this.images.length]+"\")'/>");

	document.writeln("</div>");
	document.writeln("</div></div>");

	container= document.getElementById?
			document.getElementById("gallery_"+this.id):
			document.all["gallery_"+this.id];

	this.imagelist= document.getElementById?
			document.getElementById("gallery_imagelist_"+this.id):
			document.all["gallery_imagelist_"+this.id];

	container.onmousemove= this.adjustMotion;
	container.onmouseover= this.adjustMotion;
	container.onmouseout= this.resetMotion;

	window.onload= FTGallerySlide();
}