Scroller = {
	Animation : {interval : 100, offset : 10, direction : 'none', activate : {on : 'mouseover', off : 'mouseout'}}
	, Timer : null
	, items : []
	, selectedIndex : new Number(-1)
	, selectedItem : function(){return ((this.selectedIndex < this.items.length && this.selectedIndex > -1) ? this.items[this.selectedIndex] : null)}
	, init : function()
	{
		var allTables = document.getElementsByTagName('table');
		var reClass = /(containerScrollerMaster)/;
		for (var i=0; i<allTables.length; i++)
		{
			if (reClass.test(allTables[i].className))
			{
				//var instance = parseScrollerInstance(allTables[i]);
				
				var ScrollerInstance = {};
				
				ScrollerInstance.CmdUp = allTables[i].rows[3].getElementsByTagName('a')[0];
				ScrollerInstance.ContentArea = allTables[i].rows[2].getElementsByTagName('div')[0];
				ScrollerInstance.CmdDn = allTables[i].rows[1].getElementsByTagName('a')[0];	

				//instance.ID = i;
				ScrollerInstance.ID = Scroller.items.length;
				ScrollerInstance.CmdUp.ScrollerId = ScrollerInstance.ID;
				ScrollerInstance.CmdDn.ScrollerId = ScrollerInstance.ID;
				
				if (ScrollerInstance.CmdUp.addEventListener)
				{
					ScrollerInstance.CmdUp.addEventListener(Scroller.Animation.activate.on, Scroller.ScrollUp, false);
					ScrollerInstance.CmdUp.addEventListener(Scroller.Animation.activate.off, Scroller.ScrollStop, false);
					ScrollerInstance.CmdDn.addEventListener(Scroller.Animation.activate.on, Scroller.ScrollDown, false);
					ScrollerInstance.CmdDn.addEventListener(Scroller.Animation.activate.off, Scroller.ScrollStop, false);
				}
				else if(ScrollerInstance.CmdUp.attachEvent)
				{
					ScrollerInstance.CmdUp.attachEvent('on'+Scroller.Animation.activate.on, Scroller.ScrollUp.bindAsEventListener(ScrollerInstance.CmdUp));
					ScrollerInstance.CmdUp.attachEvent('on'+Scroller.Animation.activate.off, Scroller.ScrollStop);
					ScrollerInstance.CmdDn.attachEvent('on'+Scroller.Animation.activate.on, Scroller.ScrollDown.bindAsEventListener(ScrollerInstance.CmdDn));
					ScrollerInstance.CmdDn.attachEvent('on'+Scroller.Animation.activate.off, Scroller.ScrollStop);
				}
				ScrollerInstance.ContentArea.style.overflow = 'hidden';	
				Scroller.items.push(ScrollerInstance);
			}
		}
		
	}
	, ScrollUp : function()
	{
		Scroller.ScrollStop();
		Scroller.selectedIndex = this.ScrollerId;
		Scroller.Animation.direction = 'up';
		debugWrite('Scroller.Animation.direction = ' + Scroller.Animation.direction + ' : ID = ' + Scroller.selectedIndex);
		Scroller.Timer = window.setInterval(Scroller.onInterval, Scroller.Animation.interval);
	}
	, ScrollDown : function()
	{
		Scroller.ScrollStop();
		Scroller.selectedIndex = this.ScrollerId;
		Scroller.Animation.direction = 'down';
		debugWrite('Scroller.Animation.direction = ' + Scroller.Animation.direction + ' : ID = ' + Scroller.selectedIndex);
		Scroller.Timer = window.setInterval(Scroller.onInterval, Scroller.Animation.interval);
	}
	, ScrollStop : function()
	{
		debugWrite('ScrollStop');
		Scroller.selectedIndex = -1
		Scroller.Animation.direction = 'none';
		Scroller.Timer = window.clearInterval(Scroller.Timer);
	}
	, onInterval : function()
	{
		//debugWrite('Scroller.Animation.direction = ' + Scroller.Animation.direction);
		switch(Scroller.Animation.direction)
		{
			case 'up' 	: Scroller.selectedItem().ContentArea.scrollTop += Scroller.Animation.offset; break;
			case 'down'	: Scroller.selectedItem().ContentArea.scrollTop -= Scroller.Animation.offset; break;
			case 'none'	: Scroller.ScrollStop(); break;
			default 	: Scroller.ScrollStop();
		}
	}
}

function parseScrollerInstance(parentTable)
{
	var ScrollerInstance = {};
	
	ScrollerInstance.CmdUp = parentTable.rows[1].getElementsByTagName('a')[0];
	ScrollerInstance.ContentArea = parentTable.rows[2].getElementsByTagName('div')[0];
	ScrollerInstance.CmdDn = parentTable.rows[3].getElementsByTagName('a')[0];	
	
	return ScrollerInstance;

}


if (window.addEventListener){window.addEventListener('load',Scroller.init,false);}
else if(window.attachEvent){window.attachEvent('onload',Scroller.init)}


function debugWrite(msg)
{
	try{
		document.getElementById("debugInfo").appendChild(document.createTextNode(msg));
		document.getElementById("debugInfo").appendChild(document.createElement('br'));
		document.getElementById("debugInfo").scrollTop += document.getElementById("debugInfo").style.height.replace('px', '');		
	}catch(e){}
}
//window.onerror = function(e){debugWrite(e);return false;}


/*--required-prototype-extensions------------------------------------------------------------------------*/


var $A = function(iterable) 
{
	if (!iterable) return [];
	var results = [];
	for (var i = 0, length = iterable.length; i < length; i++)
	  results.push(iterable[i]);
	return results;
}

Function.prototype.bindAsEventListener = function(object) {
  var __method = this, args = $A(arguments), object = args.shift();
  return function(event) {
    return __method.apply(object, [( event || window.event)].concat(args).concat($A(arguments)));
  }
}
