// ImageShow version 1.0-12-jan-2003
// by Tw3ty (c) 2003

var Buffers = new Array();
var Loaders = new Array();
var Viewers = new Array();

var type = "";

if (navigator.userAgent.indexOf("Opera")!=-1
    && document.getElementById) type="OP"; 
if (!document.all && document.getElementById) type="MO"; 
if (document.layers) type="NN"; 
if (document.all) type="IE"; 

function ImageBuffer( Name, MaxLen, Path, Head, Tail )
{
	this.name=Name;
	if( MaxLen<1 || MaxLen>100 ){ this.maxlen=100; }else{ this.maxlen=MaxLen; }
	this.path=Path;
	this.head=Head;
	this.tail=Tail;
	this.buf=new Array();
	for( i=0; i<=MaxLen; i++ ){
		this.buf[i] = new Image();
		this.buf[i].status = "not loaded";
		this.buf[i].loader = null;
	}
	this.buf[0].src=BaseHref+"images/loading.jpg";
	this.buf[0].status = "loaded";
	
	this.Index = function( Start, Current, Step )
	{
	var r = 0;
		var m = Current-Start+Step; if( m<0 ) m=m*-1;
		if( Current!=Start && ((m >= this.maxlen) || ((Current-Start)*(Current-Start+Step) <= 0)) ){
			r=0;
		}
		else {
			r = Current+Step;
			if( r > this.maxlen ) r = r - this.maxlen;
			if( r < 1 ) r = r + this.maxlen;
		}
		return r;
	}
	
	this.IsLoaded = function( Index )
	{
	var r = 0;
		if( (Index>=0) && (Index<=this.maxlen) )
			if( this.buf[Index].status=="loaded" ) r = 1;
		return r;
	}

	this.GetSrc = function( Index )
	{
	var r = "";
		if( (Index>=0) && (Index<=this.maxlen) )
			r = this.buf[Index].src;
		return r;
	}

	this.GetWidth = function( Index )
	{
	var r = 0;
		if( (Index>=0) && (Index<=this.maxlen) )
			r = this.buf[Index].width;
		return r;
	}

	this.GetHeight = function( Index )
	{
	var r = 0;
		if( (Index>=0) && (Index<=this.maxlen) )
			r = this.buf[Index].height;
		return r;
	}
}

function ImageLoader( Name, Buf, Start, Step )
{
	this.name=Name;
	this.buffer=Buf;
	this.start=Start;
	this.index=Start;
	this.step=Step;
	if( Step<-1 ) this.step=-1;
	if( Step>1 ) this.step=1;
	
	this.Start = function()
	{
		if( this.buffer.buf[this.index].status=="not loaded" ){
			this.buffer.buf[this.index].status="loading";
			this.buffer.buf[this.index].loader=this;
			this.buffer.buf[this.index].onerror=LoadOnError;
			this.buffer.buf[this.index].onload=LoadOnLoad;
			this.buffer.buf[this.index].src = this.buffer.path+this.buffer.head+this.index+this.buffer.tail;
		}
		else{
			this.index = this.buffer.Index( this.start, this.index, this.step );
			if( this.index!=0 ){
		//		var thisobj = this;
		//		var timeoutfunc = function() { thisobj.Start(); };
		//		this.timer = window.setTimeout(timeoutfunc, 1);
				this.timer = window.setTimeout("ImageLoaderCall('"+this.name+"','Start')",1);
			}
		}
	}
}

function ImageLoaderCall( Name, Method )
{
var i=0;
	for( i=0; i<Loaders.length; i++ )
	{
		if( Loaders[i].name == Name )eval("Loaders["+i+"]."+Method+"()");
	}
}

function LoadOnError()
{
	this.status="not found";
	this.loader.index = this.loader.buffer.Index( this.loader.start, this.loader.index, this.loader.step );
	if( this.loader.index!=0 ){
	//	var thisobj = this;
	//	var timeoutfunc = function() { thisobj.loader.Start(); };
	//	this.loader.timer = window.setTimeout(timeoutfunc, 1);
		this.loader.timer = window.setTimeout("ImageLoaderCall('"+this.loader.name+"','Start')",1);
	}
}

function LoadOnLoad()
{
	this.status="loaded";
	this.loader.index = this.loader.buffer.Index( this.loader.start, this.loader.index, this.loader.step );
	if( this.loader.index!=0 ){
	//	var thisobj = this;
	//	var timeoutfunc = function() { thisobj.loader.Start(); };
	//	this.loader.timer = window.setTimeout(timeoutfunc, 1);
		this.loader.timer = window.setTimeout("ImageLoaderCall('"+this.loader.name+"','Start')",1);
	}
}

function ImageViewer( Name, Width, Height, Align, Left, Top, Zindex, Buf, Start, Step, Interval, Controls, Visibility, Flip )
{
var ihtml;
	this.name=Name;
	this.width=Width;
	this.height=Height;
	if( (Align!="relative") && (Align!="absolute") ){
		this.align="absolute";
	}
	else{
		this.align=Align;
	}
	this.left=Left;
	this.top=Top;
	this.zindex=Zindex;
	this.buffer=Buf;
	this.start=Start;
	this.step=Step;
	if( Step<-1 ) this.step=-1;
	if( Step>1 ) this.step=1;
	if( Interval<0 ){
		this.interval=0;
	}
	else{
		this.interval=Interval;
	}
	this.controls=Controls;
	this.visibility=Visibility;
	if( Flip==Name ){ this.flip=""; }else{ this.flip=Flip; }
	
	this.index=0;
	this.layid=  "Layer"+this.name;
	
	ihtml="<DIV ID=\""  +this.layid+  "\" style=\"";
	ihtml=ihtml+"position:"  +this.align+  ";";
	ihtml=ihtml+"visibility:"  +this.visibility+  ";";
	ihtml=ihtml+"top:"  +this.top+  "px;";
	ihtml=ihtml+"z-index:"  +this.zindex+  ";";
	if( this.left=="center" ){ 
		ihtml=ihtml+"width:'100%';\" align=\"center\">";
	}
	else{
		ihtml=ihtml+"left:"  +this.left+  "px;\">";
	}
	ihtml=  ihtml+"</DIV>";
	document.write(ihtml);
				
	this.Contents = function()
	{
	var w, h;
	var ihtml;

		wfac = this.buffer.GetWidth( this.index ) / this.width;
		hfac = this.buffer.GetHeight( this.index ) / this.height;
		if( wfac>=hfac ){
			w = this.width;
			h = Math.round(this.buffer.GetHeight( this.index )/wfac);
		}
		else{
			h = this.height;
			w = Math.round(this.buffer.GetWidth( this.index )/hfac);
		}

		ihtml=  "<table align=\"center\" border=0><tr height="  +(this.height+2)+  "><td width="  +(this.width+2)+  " align=\"center\" valign=\"middle\">";
		if( this.flip!="" && this.flip.substr(0,8)!="<a href=" ){
			ihtml=ihtml+  "<a href=\"#\" onclick=\"ShowSyncFlip('"  +this.flip+  "','"  +this.name+  "');\">";
		}else if( this.flip!="" && this.flip.substr(0,8)=="<a href=" ){
			ihtml=ihtml+  this.flip;
		}
		ihtml=ihtml+  "<IMG SRC=\""  +this.buffer.GetSrc( this.index )+  "\" WIDTH="  +w+  " HEIGHT="  +h+  " border=0>";
		if( this.flip!="" ){
			ihtml=ihtml+  "</a>";
		}
		ihtml=ihtml+  "</td></tr>";
		if(this.controls){
			ihtml=ihtml+  "<tr><td align=\"center\">";
			ihtml=ihtml+  "<a href=\"#\" onclick=\"ShowPrev('"  +this.name+  "');\"><img src=\"./images/left.gif\" border=0></a>";
			ihtml=ihtml+  "<a href=\"#\" onclick=\"ShowNext('"  +this.name+  "');\"><img src=\"./images/right.gif\" border=0></a>";
			ihtml=ihtml+  "</td></tr></table>";
		}
		else{
			ihtml=ihtml+  "<tr><td></td></tr></table>";
		}
		return ihtml;
	}
	
	this.View = function()
	{
	var r = 0;
	var ihtml = "";
		ihtml = this.Contents();
		if( this.buffer.IsLoaded( this.index ) ){
			if (type=="IE") {
				document.all[this.layid].innerHTML = ihtml;
			}
			if (type=="NN") {
				document.layers["content"].document.layers[this.layid].document.open();
				document.layers["content"].document.layers[this.layid].document.write(ihtml);
				document.layers["content"].document.layers[this.layid].document.close();
			}
			if (type=="MO") {
				document.getElementById(this.layid).innerHTML = ihtml;
			}
			r=1;
		}
		return r;
	}

	this.Start = function()
	{
		var index;
		if( this.interval ) clearTimeout( this.timer );
		if( this.index==0 ) this.index=this.start;
		index = this.index;
		while( !this.View() ) this.index = this.buffer.Index( index, this.index, this.step );
		if( this.interval ){
		//	var thisobj = this;
		//	var timeoutfunc = function() { thisobj.Next(); };
		//	this.timer = window.setTimeout(timeoutfunc, this.interval);
			this.timer = window.setTimeout("ImageViewerCall('"+this.name+"','Next')", this.interval);
		}
	}

	this.Stop = function()
	{
		if( this.interval ) clearTimeout( this.timer );
	}
	
	this.Next = function()
	{
		var index;
		if( this.interval ) clearTimeout( this.timer );
		if( this.index==0 ) this.index=this.start;
		index = this.index;
		this.index = this.buffer.Index( index, this.index, this.step );
		while( !this.View() ) this.index = this.buffer.Index( index, this.index, this.step );
		if( this.interval ){
		//	var thisobj = this;
		//	var timeoutfunc = function() { thisobj.Next(); };
		//	this.timer = window.setTimeout(timeoutfunc, this.interval);
			this.timer = window.setTimeout("ImageViewerCall('"+this.name+"','Next')", this.interval);
		}
	}

	this.Prev = function()
	{
		var index;
		if( this.interval ) clearTimeout( this.timer );
		if( this.index==0 ) this.index=this.start;
		index = this.index;
		this.index = this.buffer.Index( index, this.index, this.step*-1 );
		while( !this.View() ) this.index = this.buffer.Index( index, this.index, this.step*-1 );
		if( this.interval ){
		//	var thisobj = this;
		//	var timeoutfunc = function() { thisobj.Next(); };
		//	this.timer = window.setTimeout(timeoutfunc, this.interval);
			this.timer = window.setTimeout("ImageViewerCall('"+this.name+"','Next')", this.interval);
		}
	}
	
	this.Visibility = function( action )
	{
		this.visibility=action;
		
		if (type=="IE")
			eval("document.all." + this.layid + ".style.visibility='" + action + "'");
		if (type=="NN")
			eval("document.content.document." + this.layid + ".visibility='" + action + "'");
		if (type=="MO" || type=="OP") 
			eval("document.getElementById('" + this.layid + "').style.visibility='" + action + "'");
	}
}

function ImageViewerCall( Name, Method )
{
var i=0;
	for( i=0; i<Viewers.length; i++ )
	{
		if( Viewers[i].name == Name )eval("Viewers["+i+"]."+Method+"()");
	}
}

function ShowPrev( Name )
{
var i=0;
	for( i=0; i<Viewers.length; i++ )
		if( Viewers[i].name==Name )
			Viewers[i].Prev();
}

function ShowNext( Name )
{
var i=0;
	for( i=0; i<Viewers.length; i++ )
		if( Viewers[i].name==Name )
			Viewers[i].Next();
}

function ShowVisibility( Name, Visibility )
{
var i=0;
	for( i=0; i<Viewers.length; i++ )
		if( Viewers[i].name==Name )
			Viewers[i].Visibility(Visibility);
}

function ShowStop()
{
var i=0;
	for( i=0; i<Loaders.length; i++ )clearTimeout( Loaders[i].timer );
	for( i=0; i<Viewers.length; i++ )clearTimeout( Viewers[i].timer );
}

function ShowSyncFlip( Name1, Name2 )
{
var i=0;
var a=-1;
var b=-1;
	for( i=0; i<Viewers.length; i++ ){
		if( Viewers[i].name==Name1 )a=i;
		if( Viewers[i].name==Name2 )b=i;
	}
	if( a>=0 && b>=0 ){
		Viewers[b].Stop();
		Viewers[a].index = Viewers[b].index;
		Viewers[a].Start();
		Viewers[a].Visibility("visible");
		Viewers[b].Visibility("hidden");
	}
}