var SrgListScroller =
{
	/***************************************************
	 * Array keeping the scrollers of the current page *
	 ***************************************************/
	CurrentScrollers: null,
	
	Register: function(sKey, sScrollDivId, sListId, iWidth, iHeight, iScrollInterval, iScrollOffset)
	{
		//--- Create new scroller ---
		var oNewScroller =
			{
				CurrentPosition: 0,
				CurrentIntervalCursor: -1,
				CalculatedContentHeight: 0,
				Key: sKey,
				ScrollDivId: sScrollDivId,
				ListId: sListId,
				Width: iWidth,
				Height: iHeight,
				ScrollInterval: iScrollInterval,
				ScrollOffset: iScrollOffset
			}
		//--- Get & check the list object ---
		var oScrollDiv = document.getElementById(sScrollDivId);
		var oList = document.getElementById(sListId);
		if(typeof(oScrollDiv)=='object' && oScrollDiv!=null && typeof(oList)=='object' && oList!=null)
		{
			//--- Keep the content height ---
			oNewScroller.CalculatedContentHeight = oList.offsetHeight;
			//--- Set scroller dimensions ---
			oScrollDiv.style.width = iWidth + 'px';
			oScrollDiv.style.height = iHeight + 'px';
			oScrollDiv.style.overflow = 'hidden';
			oScrollDiv.onmouseover = new Function("SrgListScroller.OnRollOver('" + sKey + "')");
			oScrollDiv.onmouseout = new Function("SrgListScroller.OnRollOut('" + sKey + "')");
			//--- Move the list out of the viewport ---
			oList.style.marginTop = iHeight + 'px';
			oList.style.paddingBottom = iHeight + 'px';
			//--- Init array if empty ---
			if(this.CurrentScrollers==null)
			{
				this.CurrentScrollers = new Array();
			}
			//--- Start scrolling ---
			oNewScroller.CurrentIntervalCursor = window.setInterval('SrgListScroller.Step("' + sKey + '");', iScrollInterval);
			//--- Append scroller to array ---
			this.CurrentScrollers[this.CurrentScrollers.length] = oNewScroller;
		}
		else
		{
			alert("List element with ID '" + sListId + "' for list scroller '" + sKey + "' was not found!");
		}
	},
	
	OnRollOver: function(sKey)
	{
		var oCurrentScroller = this.GetScrollerByKey(sKey);
		if(oCurrentScroller.CurrentIntervalCursor>-1)
		{
			window.clearInterval(oCurrentScroller.CurrentIntervalCursor);
			oCurrentScroller.CurrentIntervalCursor = -1;
		}
	},
	
	OnRollOut: function(sKey)
	{
		var oCurrentScroller = this.GetScrollerByKey(sKey);
		if(oCurrentScroller.CurrentIntervalCursor<0)
		{
			oCurrentScroller.CurrentIntervalCursor = window.setInterval('SrgListScroller.Step("' + sKey + '");', oCurrentScroller.ScrollInterval);
		}
	},
	
	Step: function(sKey)
	{
		var oCurrentScroller = this.GetScrollerByKey(sKey);
		var oScrollDiv = document.getElementById(oCurrentScroller.ScrollDivId);
		//--- Scroll ---
		if(oScrollDiv.scrollTop>=oCurrentScroller.CalculatedContentHeight + (oCurrentScroller.Height))
		{
			oScrollDiv.scrollTop = 0;
		}
		else
		{
			oScrollDiv.scrollTop += oCurrentScroller.ScrollOffset;
		}
	},
	
	/******************************************************************
	 * Returns the scroller with the passed key or null if not found. *
	 ******************************************************************/
	GetScrollerByKey: function(sKey)
	{
		//--- Get the current rotator ---
		for(var i=0; i<this.CurrentScrollers.length; i++)
		{
			if(this.CurrentScrollers[i].Key.toLowerCase()==sKey.toLowerCase())
			{
				return this.CurrentScrollers[i];
			}
		}
		return null;
	}
}
