var clipWidth = new Array(4);
var clipBottom = new Array(4);
var topper = new Array(4);
var layernames = new Array(4);
var lyrheight = new Array(4);
var clipTop = new Array(4);
var time,amount,theTime,theHeight,DHTML;

DHTML = (document.getElementById || document.all || document.layers);

function prepLyrNoShow(layername, imgname, varindex)
{
	if (!DHTML) return;
	var x = new getObj(layername);
	if (!x) return;
	layernames[varindex] = layername;
	var img=MM_findObj(imgname)
	if (!img) return;
	if (document.layers)
	{		
		// set the vars
		clipWidth[varindex] = img.width;
		clipBottom[varindex] = img.height;
		topper[varindex] = img.y;	
		lyrheight[varindex] = x.style.clip.bottom;
		lyrheight[varindex] += 20;
		clipTop[varindex] = 0;
		
		//move the div
		x.style.top = img.y;
		x.style.left =  img.x;
		x.style.width = img.width;
		
		//set the clipping rect		
		x.style.clip.top = clipTop[varindex];
		x.style.clip.left = 0;
		x.style.clip.right = clipWidth[varindex];		
		x.style.clip.bottom = clipBottom[varindex];
	}
	else if (document.getElementById || document.all)
	{
		// set the vars
		clipWidth[varindex] = img.width;
		clipBottom[varindex] = img.height;
		topper[varindex] = img.offsetTop;	
		lyrheight[varindex] = x.obj.offsetHeight;
		clipTop[varindex] = 0;
		
		//move the div
		x.style.top = img.offsetTop;
		x.style.left =  img.offsetLeft;		
		x.style.width =  img.width;
				
		//set the clipping rect		
		x.style.clip = 'rect('+clipTop[varindex]+' '+clipWidth[varindex]+' '+clipBottom[varindex]+' 0)'
	}
	return x;
}

function prepLyr(layername, imgname, varindex)
{
	var x = prepLyrNoShow(layername, imgname, varindex);
	x.style.visibility = 'visible';
	return x;
}

function scrollayer(amt,tim,varindex)
{
	if (!DHTML) return;	
	if (layernames[varindex] == null) return;		
	thelayer = new getObj(layernames[varindex]);
	if (!thelayer) return;
	amount = amt;
	theTime = tim;
	realscroll(varindex);
}

function realscroll(varindex)
{
	if (!DHTML) return;
	clipTop[varindex] += amount;
	clipBottom[varindex] += amount;
	topper[varindex] -= amount;
	if (clipTop[varindex] < 0 || clipBottom[varindex] > lyrheight[varindex])
	{
		clipTop[varindex] -= amount;
		clipBottom[varindex] -= amount;
		topper[varindex] += amount;
		return;
	}
	if (document.getElementById || document.all)
	{
		clipstring = 'rect('+clipTop[varindex]+' '+clipWidth[varindex]+' '+clipBottom[varindex]+' 0)'
		thelayer.style.clip = clipstring;
		thelayer.style.top = topper[varindex];
	}
	else if (document.layers)
	{
		thelayer.style.clip.top = clipTop[varindex];
		thelayer.style.clip.bottom = clipBottom[varindex];
		thelayer.style.top = topper[varindex];
	}
	time = setTimeout('realscroll(' + varindex + ')',theTime);
}

function stopScroll()
{
	if (time) clearTimeout(time);
}

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 hideLyr(varindex) {
	if (!DHTML) return;	
	if (layernames[varindex] == null) return;		
	var x = new getObj(layernames[varindex]);
	if (!x) return;		
	x.style.visibility = 'hidden';
}

function showFindr(xpos, ypos)
{
	if (!DHTML) return;
	var finder = new getObj('indfinder');
	var img = new getObj('indbutton');
	//if (!finder) return;
	//if (!img) return;
	finder.style.visibility = 'visible';	
	img.style.visibility = 'hidden';
	var x = prepLyrNoShow('indfinderlist','imgfinder', 4);	
	if (document.layers) {		
		x.style.left = xpos;
		x.style.top = ypos;
	}
	else {
		x.style.left = xpos + 'px';
		x.style.top = ypos + 'px';
	}
	topper[4] = ypos;	
	x.style.visibility = 'visible';
}

function hideFindr()
{
	if (!DHTML) return;
	var finder = new getObj('indfinder');
	var img = new getObj('indbutton');
	var lyr = new getObj('indfinderlist');
	if (!finder) return;
	if (!img) return;
	if (!lyr) return;
	img.style.visibility='visible';
	finder.style.visibility = 'hidden';	
	lyr.style.visibility = 'hidden';	
}
