// JavaScript Document
// Charset : UTF-8


var marqueeIntervalProcess = null;
var marqueeTimeoutProcess = null;
var marquee = {
	oDom:null,
	isOnOver:false,
	oItemCollector:null,
	interval:null,
	timeout:null,
	startup:function(dom){
		
		this.oDom = dom.getElementsByTagName("ul")[0];
		this.registerActions();
		this.oItemCollector = dom.getElementsByTagName("li");
		this.clearDom(this.oDom);
		if(this.oDom.childNodes.length <= 1){
			return;
		}
		this.play();
		//this.move();
		
	},
	registerActions:function(){
		this.setDomAttr(this.oDom,"onmouseover","marquee.mouseover()");
		this.setDomAttr(this.oDom,"onmouseover","marquee.mouseout()");
		
		
	},
	removeActions:function(){
		this.setDomAttr(this.oDom,"onmouseover","return false;");
		this.setDomAttr(this.oDom,"onmouseover","return false");
	},
	mouseover:function(){
		
	},
	mouseout:function(){
		
	},
	play:function(){
		var _this = marquee;
		//_this.removeActions();
		if(marqueeTimeoutProcess){
			clearTimeout(marqueeTimeoutProcess);
		}
		marqueeIntervalProcess = setInterval(
			function(){
				var oDom = _this.oDom;
				if(oDom.style.marginTop == "")oDom.style.marginTop ="0px";
				var marginTopNum = parseInt(oDom.style.marginTop);
				var stepLength = null;
				if(Math.abs(marginTopNum) >= _this.options.moveRange){
					clearInterval(marqueeIntervalProcess);
					marqueeIntervalProcess = null;
					_this.pause();
				}else{
		
					if(Math.abs(marginTopNum - _this.options.step) >= _this.options.moveRange){
						stepLength = -_this.options.moveRange;
					}else{
						stepLength = marginTopNum - _this.options.step;
					}
					oDom.style.marginTop = stepLength+"px";
				}
			},_this.options.speed*100);
	}
	,
	pause:function(){
		//this.registerActions();
		this.oDom.style.marginTop="0px";
		this.oDom.appendChild(this.oDom.childNodes[0]);
		marqueeTimeoutProcess = setTimeout(this.play,this.options.stopTime);
	}
	,
	setDomAttr:function(oDom,aName,aValue){
		oDom.setAttribute(aName,aValue);
	}
	,
	clearDom:function(element){
		for(var i=0; i<element.childNodes.length; i++){
			var node = element.childNodes[i];
			if(node.nodeType == 3 && !/\S/.test(node.nodeValue)){
				node.parentNode.removeChild(node);
			}
		}
	},
	options:{
			speed:1,
			step:2,
			moveRange:25,
			stopTime:4000,
			direction:"top" // top or right or down or left
			}
	
}