var scroller;
function Scroller(){
	var containerID='newsscroller';
	var direction='left';
	var speed=1;
	var interval=60;
	var width,height,wrapperWidth,wrapperHeight,timeout,scrollLayer;
	this.start=function(){
		if(timeout){
			clearTimeout(timeout);
		}
		timeout=setInterval('scroller.scroll()',interval);
	}
	this.stop=function(){
		if(timeout){
			clearTimeout(timeout);
		}
	}
	this.scroll=function(){
		if(timeout){
			clearTimeout(timeout);
		}
		var newPos;
		switch(direction){
			case 'left':
				newPos=parseInt(scrollLayer.style.left,10)-speed;
				if(newPos<(width*-1)){
					newPos=wrapperWidth;
				}
				scrollLayer.style.left=newPos+'px';
				break;
			case 'right':
				newPos=parseInt(scrollLayer.style.right,10)-speed;
				if(newPos<(width*-1)){
					newPos=wrapperWidth;
				}
				scrollLayer.style.right=newPos+'px';
				break;
			case 'up':
				newPos=parseInt(scrollLayer.style.top,10)-speed;
				if(newPos<(height*-1)){
					newPos=wrapperHeight;
				}
				scrollLayer.style.top=newPos+'px';
				break;
			case 'down':
				newPos=parseInt(scrollLayer.style.bottom,10)-speed;
				if(newPos<(height*-1)){
					newPos=wrapperHeight;
				}
				scrollLayer.style.bottom=newPos+'px';
				break;
		}
		timeout=setInterval('scroller.scroll()',interval);
	}
	this.prepare=function(){
		if (!document.getElementsByTagName) return false;
		if (!document.getElementById) return false;
		if (!document.getElementById(containerID)) return false;
		scrollLayer=document.getElementById(containerID);
		wrapperWidth=scrollLayer.parentNode.offsetWidth;
		wrapperHeight=scrollLayer.parentNode.offsetHeight;
		scrollLayer.style.position='absolute';
		if(scrollLayer.className.indexOf('left')>-1){
			direction='left';
			scrollLayer.style.left=wrapperWidth+'px';
			removeClass(scrollLayer,'noscript');
		}else if(scrollLayer.className.indexOf('right')>-1){
			direction='right';
			scrollLayer.style.right=wrapperWidth+'px';
		}else if(scrollLayer.className.indexOf('up')>-1){
			direction='up';
			scrollLayer.style.top=wrapperHeight+'px';
			removeClass(scrollLayer,'noscript');
		}else if(scrollLayer.className.indexOf('down')>-1){
			direction='down';
			scrollLayer.style.bottom=wrapperHeight+'px';
		}else{
			direction='left';
			scrollLayer.style.left=wrapperWidth+'px';
			removeClass(scrollLayer,'noscript');
		}
		width=scrollLayer.offsetWidth;
		height=scrollLayer.offsetHeight;
		scrollLayer.parentNode.onmouseover=function(){
			scroller.stop();
		}
		scrollLayer.parentNode.onmouseout=function(){
			scroller.start();
		}
		scroller.start();
		return true;
	}
}

addLoadEvent(function(){
	scroller=new Scroller();
	scroller.prepare();
});
