var SlideShowSpeed = 10000;
var CrossFadeDuration = 3;
var tss;
var iss;
var jss = 1;
var pss = Picture.length-1;
var left = 0;
var amount = 0;
var theTime = 0;
var time = 0;
var thelayer;
var imageWidth = 80;
var clipLeft = 0;
var clipRight = 8 * imageWidth;
var running = 0;

var preLoad = new Array();
for (iss = 1; iss < pss+1; iss++) {
	preLoad[iss] = new Image();
	preLoad[iss].src = Picture[iss];
}

var prevSel = -1;

function runSlideShow(){
	if (document.images) 
	{ 
		document['playpause'].src= '/images/vt/pause.gif'; 
	} 

	if (document.all){
		document.images.PictureBox.style.filter="blendTrans(duration=2)";
		document.images.PictureBox.style.filter="blendTrans(duration=CrossFadeDuration)";
		document.images.PictureBox.filters.blendTrans.Apply();
	}
	selectimage(jss);

	if (document.all) document.images.PictureBox.filters.blendTrans.Play();
	tss = setTimeout('runSlideShow()', SlideShowSpeed);
}

function startSlideShow(){

	if (running == 0) {
		runSlideShow();
		running = 1;
	}
	else {
		stopSlideShow();
		running = 0;
	}
}

function stopSlideShow() {
	if (document.images) 
	{ 
		document['playpause'].src= '/images/vt/play.gif'; 
	} 
	
	if (tss) clearTimeout(tss);
}

function resetSlideShow() {
	jss = 1;
	selectimage(jss);
}

function previousSlide() {
	selectimage(jss - 2);
}

function nextSlide() {
	selectimage(jss);
}

function selectimage(i) {
    if (i > 0) {
		document.images.PictureBox.src = preLoad[i].src;
		if (document.getElementById) {
			document.getElementById("CaptionBox").innerHTML= Caption[i];
			highlight(i);
		}
		jss = i + 1;
		if (jss > (pss)) jss=1;
	}
}

function highlight(i) {
	if (document.getElementById) {
		if (i * imageWidth > clipRight) {
			amount = (i * imageWidth) - clipRight;
			scrollayer('pictureChooser',amount * 4,1000)
		}
		else if ((i * imageWidth) < (clipLeft + imageWidth)) {
			amount = (i * imageWidth) - (clipLeft + imageWidth);
			scrollayer('pictureChooser',amount,1000);
		}

		document.getElementById("if" + i).style.background = "url(/images/photoframehigh-small.gif) no-repeat";
		if (prevSel > -1) document.getElementById("if" + prevSel).style.background = "url(/images/photoframe-small.gif) no-repeat";
		prevSel = i;
		
	}
}

function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}

function scrollayer(layername,amt,tim)
{
	thelayer = new getObj(layername);
	if (!thelayer) return;
	amount = amt;
	theTime = tim;
	t = 0;
	if (amount > 0) {
		inc = 6;
	}
	else {
		inc = -6;
	}
	realsmoothscroll();
}

function realscroll()
{
	clipLeft += amount;
	clipRight += amount;
	left -= amount;
	if (clipLeft < 0 || clipRight > (imageWidth * pss))
	{
		clipLeft -= amount;
		clipRight -= amount;
		left += amount;
		return;
	}
	if (document.getElementById || document.all)
	{
		clipstring = 'rect(0,'+clipRight+'px,60px,'+clipLeft+'px)';
		thelayer.style.clip = clipstring;
		thelayer.style.left = left + 'px';
	}
	else if (document.layers)
	{
		thelayer.style.clip.left = clipLeft;
		thelayer.style.clip.right = clipRight;
		thelayer.style.left = left;
	}
}

var t;
var inc;
var stss;

function realsmoothscroll()
{
	if (Math.abs(t + inc) > Math.abs(amount)) {
		inc = amount - t;
	}
	
	clipLeft += inc;
	clipRight += inc;
	left -= inc;
	if (clipLeft < 0 || clipRight > (imageWidth * pss))
	{
		clipLeft -= inc;
		clipRight -= inc;
		left += inc;
		return;
	}
	if (document.getElementById || document.all)
	{
		clipstring = 'rect(0,'+clipRight+'px,100px,'+clipLeft+'px)';
		thelayer.style.clip = clipstring;
		thelayer.style.left = left + 'px';
	}
	else if (document.layers)
	{
		thelayer.style.clip.left = clipLeft;
		thelayer.style.clip.right = clipRight;
		thelayer.style.left = left;
	}
	t = t + inc;
	if (Math.abs(t) < Math.abs(amount)) {
		stss = setTimeout('realsmoothscroll()', 2);
	}
}

function stopScroll()
{
	if (time) clearTimeout(time);
}
