// JavaScript to "scroll" through a layer

// Variables for vertical scrolling
var clipTop = 0;
var clipWidth = 114;
var clipBottom = 50;
var topper = 450; // The top edge of the layer
var lyrheight = 0;
var time,amount,theTime,theHeight,DHTML;

// For Horizontal scrolling

var clipLft = 0;
var clipRgt = 508; // The width of the clipping frame
var clipHeight = 100; // The height of the clipping frame
// var leftmost = 58 // The left edge of the layer
// var leftmost = 240; // The left edge of the layer MUST MATCH VALUE SET IN CSS!!
var leftmost = 202; // The left edge of the layer MUST MATCH VALUE SET IN CSS!!
var lyrwidth = 0; //

/* 
	The init() function initializes the clipping rectangle of the scrolling thumbnails
	then turns on the layer to display only the thumbs which fit within the clipping area
*/


function init()
{

	ns4 = (document.layers) ? true:false 
	ie4 = (document.all) ? true:false 
	ng5 = (document.getElementById) ? true:false 

//	alert('ns4='+ns4+', ie4='+ie4+', ng5='+ng5);
	DHTML = (ng5 || ie4 || ns4)
	if (!DHTML) return;
	var x = new getObj('scrollthumbs');
	if (ns4)
	{
//		lyrheight = x.style.clip.bottom;
//		lyrheight += 20;
		lyrwidth = x.style.clip.right;
		lyrwidth += 20;
//		x.style.clip.top = clipTop;
//		x.style.clip.left = 0;
//		x.style.clip.right = clipWidth;
//		x.style.clip.bottom = clipBottom;
		x.style.clip.top = 0;
		x.style.clip.left = clipLft;
		x.style.clip.right = clipRgt;
		x.style.clip.bottom = clipHeight;
	}
	else if (ng5 || ie4)
	{

//		lyrheight = x.obj.offsetHeight;
		lyrwidth = x.obj.offsetWidth;
//		x.style.clip = 'rect('+clipTop+'px,'+clipWidth+'px,'+clipBottom+'px, 0)';
		x.style.clip = 'rect(0px, '+clipRgt+'px, '+clipHeight+'px, '+clipLft+'px)';
	}
	
	showlayer('scrollthumbs');	
}

function scrollayer(layername,amt,tim)
{
	if (!DHTML) return;
	thelayer = new getObj(layername);
	if (!thelayer) return;
	amount = amt;
	theTime = tim;
	hscroll();
//	realscroll();
}

function hscroll()
{
// alert("hscroll: DHTML="+DHTML);
	if (!DHTML) return;
	clipLft += amount;
	clipRgt += amount;
	leftmost -= amount;
//	alert("clipLft="+clipLft+" clipRgt="+clipRgt+" leftmost="+leftmost);
	if (clipLft < 0 || clipRgt > lyrwidth)
	{
		clipLft -= amount;
		clipRgt -= amount;
		leftmost += amount;
		return;
	}
	if (ng5 || ie4 )
	{
//	alert("ng5||ie4: hscrolling...");
//		clipstring = 'rect('+clipTop+'px,'+clipWidth+'px,'+clipBottom+'px,0)';
		clipstring = 'rect(0px, '+clipRgt+'px, '+clipHeight+'px, '+clipLft+'px)';
		thelayer.style.clip = clipstring;
//		thelayer.style.top = topper + 'px';
		thelayer.style.left = leftmost + 'px';
	}
	else if (ns4)
	{
//		alert("ns4");
		thelayer.style.clip.top = clipTop;
		thelayer.style.clip.bottom = clipBottom;
		thelayer.style.top = topper;
	}
	time = setTimeout('hscroll()', theTime);
}

function realscroll()
{
	if (!DHTML) return;
	clipTop += amount;
	clipBottom += amount;
	topper -= amount;
	if (clipTop < 0 || clipBottom > lyrheight)
	{
		clipTop -= amount;
		clipBottom -= amount;
		topper += amount;
		return;
	}
	if (ng5 || ie4)
	{
		clipstring = 'rect('+clipTop+'px,'+clipWidth+'px,'+clipBottom+'px,0)';
		thelayer.style.clip = clipstring;
		thelayer.style.top = topper + 'px';
	}
	else if (ns4)
	{
		thelayer.style.clip.top = clipTop;
		thelayer.style.clip.bottom = clipBottom;
		thelayer.style.top = topper;
	}
	time = setTimeout('realscroll()',theTime);
}

function stopScroll()
{
	if (time) clearTimeout(time);
}

function getObj(name)
{
  if (ng5)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (ie4)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (ns4)
  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}

function hidelayer(layer) { 
	if (ng5) document.getElementById(layer).style.visibility = "hidden" 
	else if (ns4) document.layer.visibility = "hide" 
	else if (ie4) layer.style.visibility ="hidden" 
}

function showlayer(layer) { 
	if (ng5) document.getElementById(layer).style.visibility = "visible" 
	else if (ns4) document.layer.visibility = "show" 
	else if (ie4) layer.style.visibility ="visible" 
}


