/**
 * @Cotyright 2008 SHANGHAI PANTOSOFT CO., LTD. ALL RIGHTS RESERVED.
 * @AUTHOR : Unone.
 * @LASE MODIFIED BY :Chenghaojun
 * @WARNNING : DOT NOT TRY TO INSERT ANY CHINESE CHARACTER INTO THIS FILE.
 * @VERSION 1.0
 * @ANY PROBLEM PLEASE CONTACT {chhj_292@163.com}
 * 
 * This is a scoller. and it suports any Web Browser(include IE7.0+,Firefox,NetScape,Google).
 * And the first vertion is from internet, belows are modified by Chenghaojun.
 * if there are other modifications needness plesse contact Author.
 */

var Scroller = {
	scrollerx : [],
	scrollery : [],
	offsetHeight : [],
	offsetWidth : [],
	//function userd as horizontal scroll
	myscrollx : [],
	//function userd as vertical scroll
	myscrolly : [],
	//speed of horizontal scroll
	scrollspeedx : [],
	//speed of vertical scroll
	scrollspeedy : [],
	x : 0,
	y : 0,
	//summary of horizontal scroll components
	i : -1,
	//summary of vertical scroll components
	ii : -1,
	
	$ : function (o) {
		return typeof (o) == "string" ? document.getElementById(o) : o;
	},
	/*
	 * Method of vertical scroll
	 */
	scrolly : function() {
		var _this = this;
		for (var i = 0; i < this.scrollery.length; i++) {
			var _scroll = function(){
				if (_this.y >= _this.scrollery.length) {
					_this.y = 0;
				}
				if (/true/.test(_this.scrollery[_this.y].getAttribute("run"))) {
					_this.scrollery[_this.y].scrollTop = (_this.scrollery[_this.y].scrollTop) % _this.offsetHeight[_this.y];
					_this.scrollery[_this.y].scrollTop++;
				}
				_this.y++;
			}
			this.myscrolly[i] = setInterval(_scroll, this.scrollspeedy[i]);
			
			this.scrollery[i].onmouseover = function () {
				this.setAttribute("run", false);
			};
			this.scrollery[i].onmouseout = function () {
				this.setAttribute("run", true);
			};
		}
	},
	/*
	 * Method of horizontal scroll
	 */
	scrollx : function() {
		var _this = this;
		for (var i = 0; i < this.scrollerx.length; i++) {
			var _scroll = function(){
				if (_this.x >= _this.scrollerx.length) {
					_this.x = 0;
				}
				if (/true/.test(_this.scrollerx[_this.x].getAttribute("run"))) {
					_this.scrollerx[_this.x].scrollLeft = (_this.scrollerx[_this.x].scrollLeft) % (_this.offsetWidth[_this.x]);
					_this.scrollerx[_this.x].scrollLeft++;
				}
				_this.x++;
			}
			this.myscrollx[i] = window.setInterval(_scroll, this.scrollspeedx[i]);
			this.scrollerx[i].onmouseover = function () {
				this.setAttribute("run", false);
			};
			this.scrollerx[i].onmouseout = function () {
				this.setAttribute("run", true);
			};
		}
	},
	/*
	 * Start to scroll.
	 */
	start : function() {
		for (var i = 0, _div = this.getAllDivs(), ii = _div.length; i < ii; i++) {
			var _marquees = _div[i].getAttribute("scroll");
			var spliter = /\d+,\d+,\d+/;
			if (spliter.test(_marquees)) {
				var _marqueesPram = _marquees.split(",");
				if (_marqueesPram[3] == "x") {
					_div[i].style.width = _marqueesPram[0] + "px";
					_div[i].style.height = _marqueesPram[1] + "px";
					_div[i].style.overflow = "hidden";
					_div[i].style.whiteSpace = "nowrap";
					_div[i].setAttribute("run", true);
					
					this.i++;
					this.scrollerx[this.i] = _div[i];
					this.offsetWidth[this.i] = _div[i].offsetWidth;
					this.scrollspeedx[this.i] = _marqueesPram[2];
					//this.scrollerx[this.i].innerHTML += this.scrollerx[this.i].innerHTML;
				}
				if (_marqueesPram[3] == "y") {
					_div[i].style.width = _marqueesPram[0] + "px";
					_div[i].style.height = _marqueesPram[1] + "px";
					_div[i].style.overflow = "hidden";
					_div[i].setAttribute("run", true);
					
					this.ii++;
					this.scrollery[this.ii] = _div[i];
					this.offsetHeight[this.ii] = _div[i].offsetHeight;
					this.scrollspeedy[this.ii] = _marqueesPram[2];
					//this.scrollery[this.ii].innerHTML += this.scrollery[this.ii].innerHTML;
				}
			}
		}
		if (this.scrollerx.length > 0) {
			this.scrollx();
		}
		
		if (this.scrollery.length > 0) {
			this.scrolly();
		}
	},
	/*
	 * Get all div components from this page.
	 */
	getAllDivs : function(){
		var scroll = new Array();
		var _divs = document.body.getElementsByTagName("div");
		for(var i=0 ; i < _divs.length ; i++){
			scroll.push(_divs[i]);
		}
		return scroll
	}
};
