/************************
* JsMarquee可移植版 for Site MagicSquare (SiteMagic)
* Coding By Ridge Wong @ 2008-2-16
* Demo Code:
* 	-----------------
* 	var myUpDiv1 = new SiteMagic.WebUI.JsMarquee("UpDownDiv", "myUpDiv1");
*   // myUpDiv1.setAutoOverflow(true);
* 	myUpDiv1.DoMove();
*
*	// Right To Left Move
* 	var myUpDiv3 = new SiteMagic.WebUI.JsMarquee("LeftRightDiv", "myUpDiv3", false);
* 	myUpDiv3.Step = 2;
* 	myUpDiv3.DoMove();
* 	---------------------
**************************/
if (typeof(SiteMagic.WebUI)=="undefined") {registerNamespace("SiteMagic.WebUI");}
SiteMagic.WebUI.JsMarquee = function(){
	var args = arguments, argc = arguments.length;
	if (argc<2 || argc>3) { return; }
	var marID=args[0], instanceID=args[1];
	var bindObject = null;
	var autoOverflow = false;
	var iFrequence = 25;
	var isUpDown = (argc==3)?false:true;

	this.setAutoOverflow = function(isAuto) { autoOverflow = isAuto; };
	this.setFrequence = function(n) { iFrequence = n; };
	this.IsStoped = function() { return bindObject.getAttribute("IsStoped");};
	this.InstanceID = instanceID;
	this.Step = 1;
	this.DoMove = function() {
		bindObject = document.getElementById(marID);
		if (bindObject == null) return;
		bindObject.onmouseover = function() { 
			bindObject.setAttribute("IsStoped",true); 
			if (autoOverflow == true) { bindObject.style.overflow="auto";  }
		}
		bindObject.onmouseout = function() { 
			bindObject.setAttribute("IsStoped",false); 
			if (autoOverflow == true) { bindObject.style.overflow="hidden";  }
		}
		if (this.isUpDown){bindObject.scrollTop = 0;}else{bindObject.scrollLeft = 0;}
		window.setInterval( this.InstanceID + ".Moving()", iFrequence);
	};
	this.Moving = function() {
		if(this.IsStoped()) return;
		var fPoint = (isUpDown) ? bindObject.scrollHeight-parseInt(bindObject.style.height) : bindObject.scrollWidth-parseInt(bindObject.style.width);
		if (isUpDown)
		{
			bindObject.scrollTop += this.Step; 
			if (bindObject.scrollTop >= fPoint) { bindObject.scrollTop = 0; }
		}
		else
		{
			bindObject.scrollLeft += this.Step; 
			if (bindObject.scrollLeft >= fPoint) { bindObject.scrollLeft = 0; }
		}
	}
};
