function imageRotator(holderId, timer, step)
{
	if ((!timer) || (typeof(timer)=='undefined'))
		timer=5;
	if ((!step) || (typeof(step)=='undefined'))
		step=5;
	
	if(typeof(holderId)=='string')
	{
		if (!window.imageRotator)
			window.imageRotator = array();
		var iR = window.imageRotator[window.imageRotator.length] = document.getElementById(holderId);
		if (!iR) return;
	}
	
	if (typeof(holderId)=='object')
	{
		if (!window.imageRotator)
			window.imageRotator = array();
		var iR = holderId;
	}
	iR.iRstep = step;
	iR.iRtimer = timer;
	
	var DIVs = iR.getElementsByTagName('DIV');
	for (var i=0; i < DIVs.length; i++)
	{
		if (DIVs[i].className.match(/arrow/))
		{
			if (DIVs[i].className.match(/arrowRight/))	iR.arrowRight = DIVs[i];
			if (DIVs[i].className.match(/arrowLeft/))		iR.arrowLeft = DIVs[i];
		}
	}
	
	var LIs = iR.getElementsByTagName('LI');
	if (!LIs||!LIs[0]) return;
	UL = LIs[0].parentNode;
	UL.style.width = (LIs[0].offsetWidth*LIs.length)+'px';
	
	if (UL.offsetWidth>iR.offsetWidth)
		iR.className += ' active';
	
	var LI = LIs[0];
	for (var i=0; i < LIs.length; i++)
	{
		if (LIs[i].className.match(/active/))
			LI = LIs[i];
	}
	
	toPos	= -Math.ceil(LI.offsetLeft-(UL.parentNode.offsetWidth-LI.offsetWidth)/2);
	t = UL.offsetWidth-UL.parentNode.offsetWidth;
	if ((-toPos)>(t)) toPos = -t;
	if ((-toPos)<0) toPos = 0;
	
	if (LI) window.setTimeout(function(){imageRotatorPositionChange(UL,toPos,timer,step)},1000);
	
	// onmouseover/onmouseout event handler
	{
		var hoverClassReg = new RegExp("\\bhighlight\\b");
		
		iR.onmouseover = iR.onmouseout = function(e)
		{
			if (!e) e = window.event;
			var elem = e.target || e.srcElement;
			while (!elem.tagName || !elem.tagName.match(/div/i)) elem = elem.parentNode;
			
			if (elem.className.match(/arrow/))
			{	
				elem.className = e.type=="mouseover"?elem.className+" highlight":elem.className.replace("highlight"," ");
				
				UL = elem.parentNode.getElementsByTagName('UL');
				t = elem.parentNode.iRtimer; 
				s = elem.parentNode.iRstep; 
				if ((e.type=="mouseover")&&UL&&UL[0])
				{	if (elem.className.match(/arrowRight/)) imageRotatorPositionChange(UL[0],-(UL[0].offsetWidth-UL[0].parentNode.offsetWidth),t,s)
					else imageRotatorPositionChange(UL[0],0,t,s)
				}
				else window.clearInterval(UL[0].posChangeMemInt);
			}
		};
	}
	
}

function imageRotatorPositionShift(elem,startPos,endPos,intervals,step) {
	if (!elem) return;
	if (!elem.currentPos&&(elem.currentPos!=0)) elem.currentPos = 0;
	if (elem.posChangeMemInt)
		window.clearInterval(elem.posChangeMemInt);

	elem.posChangeMemInt = window.setInterval(
		function()
		{ 
			var sign = endPos>elem.currentPos?1:(endPos<elem.currentPos?-1:0);
			if ((elem.currentPos>=endPos-sign*step)||(elem.currentPos<=endPos+sign*step))
			{
				elem.currentPos = elem.currentPos+(sign*step);
				if (elem.style) elem.style.left = elem.currentPos + "px";
			}
			else
			{
				window.clearInterval(elem.posChangeMemInt);
			}
		} 
	,intervals);
}

function imageRotatorPositionChange(elem,targ,msec,step) {
	if (!elem.currentPos) elem.currentPos = 0; 
	imageRotatorPositionShift(elem,elem.currentPos,targ,msec,step); 
}
