//////////////////////////////////////////////////////////////////////////
//
// Slides.js script for displaying a generic multi-image slideshow.
//
// Script written by Craig Taverner
// Date: 26/03/2002

SlideWait=5000;	// time to wait between slides
Xslide=0;		// Where to draw slides
Yslide=0;		// Where to draw slides
winRelative=0;	// if 1, then keep slides relative to window view (ie move with scroll)
StartWait=0;	// if 1, then wait before placing first slide
Xoff=-500;		// Where to put 'invisible' slides
Yoff=-500;		// Where to put 'invisible' slides
SlideWidth=400;	// width to reserve for slides
SlideHeight=250;	// height to reserve for slides
SlideColor="#000000";	// color for slide background

// Initialize internal parameters
ns=(document.layers)?1:0;
ns6=(document.getElementById&&!document.all)?1:0;
slideImages=new Array();
slideLinks=new Array();
slideBackground="";
slideBackgroundLink="";
slideForeground="";
slideForegroundLink="";
winHeight=(ns||ns6)?window.innerHeight:window.document.body.clientHeight;
winWidth=(ns||ns6)?window.innerWidth-70:window.document.body.clientWidth;
hScroll=(ns||ns6)?window.pageYOffset:document.body.scrollTop;
wScroll=(ns||ns6)?window.pageXOffset:document.body.scrollLeft;
numSlides=0;	// initial image array size
currentSlide=0;
previousSlide=0;

// Add a new slide image to the array of loaded images
function addSlide(imageURL,linkURL){
	var ImageBuf=new Image();
	ImageBuf.src=slideImages[numSlides]=imageURL;
	slideLinks[numSlides]=linkURL;
	numSlides=slideImages.length;
}

// Set the background image
function setSlideBackground(imageURL,linkURL){
	var ImageBuf=new Image();
	ImageBuf.src=slideBackground=imageURL;
	slideBackgroundLink=linkURL;
}

// Set the background image
function setSlideForeground(imageURL,linkURL){
	var ImageBuf=new Image();
	ImageBuf.src=slideForeground=imageURL;
	slideForegroundLink=linkURL;
}

// Run the slide show
function runSlideShow(){
	if(StartWait){
		setTimeout('runSlideShow()',SlideWait);
		StartWait=0;
		return;
	}
	// in case user has resized, or scrolled
	if(winRelative){
		winHeight=(ns||ns6)?window.innerHeight:window.document.body.clientHeight;
		winWidth=(ns||ns6)?window.innerWidth-70:window.document.body.clientWidth;
		hScroll=(ns||ns6)?window.pageYOffset:document.body.scrollTop;
		wScroll=(ns||ns6)?window.pageXOffset:document.body.scrollLeft;
	}
	// Show next slide
	var X=Xslide;
	var Y=Yslide;
	if(winRelative) Y+=hScroll;
	if(ns){
		if((slideBackground)||(SlideColor)){
			document.layers['siB'].left=X;
			document.layers['siB'].top=Y;
		}
		document.layers['si'+previousSlide].left=Xoff;
		document.layers['si'+previousSlide].top=Yoff;
		document.layers['si'+currentSlide].left=X;
		document.layers['si'+currentSlide].top=Y;
		if(slideForeground){
			document.layers['siF'].left=X;
			document.layers['siF'].top=Y;
		}
	}else if(ns6){
		if((slideBackground)||(SlideColor)){
			document.getElementById("siB").style.left=Math.min(winWidth,X);
			document.getElementById("siB").style.top=Y;
		}
		document.getElementById("si"+previousSlide).style.left=Math.min(winWidth,Xoff);
		document.getElementById("si"+previousSlide).style.top=Yoff;
		document.getElementById("si"+currentSlide).style.left=Math.min(winWidth,X);
		document.getElementById("si"+currentSlide).style.top=Y;
		if(slideForeground){
			document.getElementById("siF").style.left=Math.min(winWidth,X);
			document.getElementById("siF").style.top=Y;
		}
	}else{
		if((slideBackground)||(SlideColor)){
			eval("document.all.siB").style.left=X;
			eval("document.all.siB").style.top=Y;
		}
		eval("document.all.si"+previousSlide).style.left=Xoff;
		eval("document.all.si"+previousSlide).style.top=Yoff;
		eval("document.all.si"+currentSlide).style.left=X;
		eval("document.all.si"+currentSlide).style.top=Y;
		if(slideForeground){
			eval("document.all.siF").style.left=X;
			eval("document.all.siF").style.top=Y;
		}
	}
	previousSlide=currentSlide;
	currentSlide++;
	if(currentSlide>=numSlides) currentSlide=0;
	setTimeout('runSlideShow()',SlideWait);
}

// Place images in HTML
function initSlideShow(inXslide,inYslide,inSlideWidth,inSlideHeight,inSlideColor,inSlideWait,inRelative,inStartWait){
	Xslide=inXslide;		// Where to place slides
	Yslide=inYslide;		// Where to place slides
	SlideWait=inSlideWait;	// time to wait between slides
	SlideWidth=inSlideWidth;	// width to reserve for slides
	SlideHeight=inSlideHeight;	// height to reserve for slides
	SlideColor=inSlideColor;	// color for slide background
	winRelative=inRelative;	// whether slides should be relative to current scroll or not
	StartWait=inStartWait;	// whether or not to start by waiting the SlideWait time
	// Place images in HTML document in <DIV> or <LAYER> tags
	if(ns){
		if(slideBackground)
			document.write("<LAYER NAME='siB' LEFT="+Xoff+" TOP="+Yoff+"><table border=0 cellpadding=0 cellspacing=0><tr><td align='left' valign='top'><a href='"+slideBackgroundLink+"'><img border=0 width="+SlideWidth+" height="+SlideHeight+" src='"+slideBackground+"'></a></td></tr></table></LAYER>");
		else if(SlideColor)
			document.write("<LAYER NAME='siB' LEFT="+Xoff+" TOP="+Yoff+"><table border=0 cellpadding=0 cellspacing=0 width="+SlideWidth+" height="+SlideHeight+" bgcolor='"+SlideColor+"'><tr><td><font color='"+SlideColor+"'>.</font></td></tr></table></LAYER>");
		for(i=0;i<numSlides;i++){
			document.write("<LAYER NAME='si"+i+"' LEFT="+Xoff+" TOP="+Yoff+"><table border=0 width="+SlideWidth+" height="+SlideHeight+"><tr><td align='center' valign='middle'><a href='"+slideLinks[i]+"'><img border=0 src='"+slideImages[i]+"'></a></td></tr></table></LAYER>");
		}
		if(slideForeground)
			document.write("<LAYER NAME='siF' LEFT="+Xoff+" TOP="+Yoff+"><table border=0 cellpadding=0 cellspacing=0><tr><td align='left' valign='top'><a href='"+slideForegroundLink+"'><img border=0 width="+SlideWidth+" height="+SlideHeight+" src='"+slideForeground+"'></a></td></tr></table></LAYER>");
	}else{
		document.write('<div style="position:absolute;top:0px;left:0px"><div style="position:relative">');
		if(slideBackground)
			document.write('<div id="siB" style="position:absolute;top:'+Yoff+'px;left:'+Xoff+'px"><a href="'+slideBackgroundLink+'"><img width='+SlideWidth+' height='+SlideHeight+' border=0 src="'+slideBackground+'"></a></div>');
		else if(SlideColor)
			document.write('<div id="siB" style="position:absolute;top:'+Yoff+'px;left:'+Xoff+'px"><table border=0 width='+SlideWidth+' height='+SlideHeight+' bgcolor="'+SlideColor+'"><tr><td> </td></tr></table></div>');
		for(i=0;i<numSlides;i++){
			document.write('<div id="si'+i+'" style="position:absolute;top:'+Yoff+'px;left:'+Xoff+'px"><table border=0 width='+SlideWidth+' height='+SlideHeight+'><tr><td align="center" valign="middle"><a href="'+slideLinks[i]+'"><img border=0 src="'+slideImages[i]+'"></a></td></tr></table></div>');
		}
		if(slideForeground)
			document.write('<div id="siF" style="position:absolute;top:'+Yoff+'px;left:'+Xoff+'px"><a href="'+slideForegroundLink+'"><img width='+SlideWidth+' height='+SlideHeight+' border=0 src="'+slideForeground+'"></a></div>');
		document.write('</div></div>');
	}
}

// Put this in your HTML head or body
//<script language="JavaScript1.2" src="Slides.js"></script>
// Put this in your HTML body
//<script>
//	addSlide("Slide1.jpg","link1.html");
//	addSlide("Slide2.jpg","link2.html");
//	addSlide("Slide3.jpg","link3.html");
//	addSlide("Slide4.jpg","link4.html");
//	initSlideShow(50,280,400,210,"#000000",5000,1,1);	// example for slideshow that moves with scroll
//	window.onload=runSlideShow;
//</script>
