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];
  }
}

var initialized = false;
var clipTop = 0;
var clipWidth = 100;
var clipBottom = 342;
var topper = 0;
var lyrheight = 0;
var autotime,time,amount,theTime,theHeight,DHTML;
var curdir = 1;
var auto = false;

function init()
{
	DHTML = (document.getElementById || document.all || document.layers)
	if (!DHTML) return;
	var x = new getObj('example');
	if (document.layers)
	{
		lyrheight = x.style.clip.bottom;
		lyrheight += 20;
		x.style.clip.top = clipTop;
		x.style.clip.left = 0;
		x.style.clip.right = clipWidth;
		x.style.clip.bottom = clipBottom;
	}
	else if (document.getElementById || document.all)
	{
		lyrheight = x.obj.offsetHeight;
		var clipstring = 'rect('+clipTop+'px,'+clipWidth+'px,'+clipBottom+'px,0)';
		x.style.clip = clipstring;
	}
	vis('visible');
	autotime = setTimeout('autoScroll()',500);
	initialized = true;
	x.obj.onmousemove = grabMouse;
}

function autoScroll()
{
	if (auto) return;
	
	auto = true;
	scrollayer("example", curdir, 100);
}

function scrollayer(layername,amt,tim)
{
	if (!DHTML) return;
	thelayer = new getObj(layername);
	if (!thelayer) return;

	auto = false;
	if (autotime) clearTimeout(autotime);

	if (amt > 0)
		curdir = 1;
	else
		curdir = -1;
			
	amount = amt;
	theTime = tim;
	realscroll();
}



function realscroll()
{
	if (!DHTML) return;
	clipTop += amount;
	clipBottom += amount;
	topper -= amount;
	if (clipTop < 0 || clipBottom > lyrheight)
	{
		if (clipTop < 0)
			curdir = 1;
		else
			curdir = -1;

		clipTop -= amount;
		clipBottom -= amount;
		topper += amount;

		if (amount == 1 || amount == -1)
		{
			auto = false;
			autotime = setTimeout('autoScroll()',500);
		}
		
		return;
	}
	if (document.getElementById || document.all)
	{
		clipstring = 'rect('+clipTop+'px,'+clipWidth+'px,'+clipBottom+'px,0)'
		thelayer.style.clip = clipstring;
		thelayer.style.top = topper + 'px';
	}
	else if (document.layers)
	{
		thelayer.style.clip.top = clipTop;
		thelayer.style.clip.bottom = clipBottom;
		thelayer.style.top = topper;
	}
	time = setTimeout('realscroll()',theTime);
}

function vis(val)
{
	if (!DHTML) return;
	var f = new getObj('example');
	f.style.visibility = val;
}

function visset(elem, val)
{
	if (!DHTML) return;
	var f = new getObj(elem);
	f.style.visibility = val;
}

function stopScroll()
{
	auto = false;
	if (autotime) clearTimeout(autotime);
	if (time) clearTimeout(time);
	
	//if (auto)
	//{
	//	auto = false;
	//	autotime = setTimeout('autoScroll()',500);
	//}
}




var IE = document.all?true:false
// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

function grabMouse(e) {
	var posx = 0;
	var posy = 0;
	var relheight = 342;
	if (IE) { // grab the x-y pos.s if browser is IE
		posy = event.clientY + document.body.scrollTop
	} else {  // grab the x-y pos.s if browser is NS
		posy = e.pageY
	}  

	var cc = new getObj('outer');
	// get relative percent from middle
	var relpos = ((cc.obj.offsetTop + (relheight / 2)) - posy) / (relheight / 2);
	if (relpos < 0)
	{
		curdir = 1;
		amount = (Math.round(25 * Math.abs(relpos)));
	}
	else
	{
		amount = -(Math.round(25 * Math.abs(relpos)));
		curdir = -1;
	}
}
