﻿function simplescroll(c,scrollType,addType,config) {
	this.config = config ? config : {start_delay:0, speed: 50, delay:3000, scrollItemCount:1,movecount:1};
	this.container = document.getElementById(c);
	this.pause = false;
	this.scrollType = scrollType;
	this.addType = addType;
	var _this = this;
	
	this.init = function() {
		_this.scrollTimeId = null;
		setTimeout(_this.start,_this.config.start_delay);
	}
	
	this.start = function() {
		var d = _this.container;
		var line = d.getElementsByTagName("tr")[0];
		if(line==null)
		return;
		var line_height = line.offsetHeight;
		
		if(d.scrollHeight-d.offsetHeight>=line_height) _this.scrollTimeId = setInterval(_this.scroll,_this.config.speed)
	};

	this.scroll = function() {
		if(_this.pause)return;
		var d = _this.container;d.scrollTop+=2;
		var line = d.getElementsByTagName("tr")[0];
		if(line==null)
		return;
		var line_height = line.offsetHeight;
		if(d.scrollTop%(line_height*_this.config.scrollItemCount)<=1){
		    
			if(_this.config.movecount != undefined)
				for(var i=0;i<_this.config.movecount;i++)
				{
				    var table = d.getElementsByTagName("tbody")[0];
				    var tr = table.getElementsByTagName("tr")[0];
				    table.removeChild(tr);
				    table.appendChild(tr);
				}
			else 
			    for(var i=0;i<_this.config.scrollItemCount;i++)
			    {
			        var table = d.getElementsByTagName("tbody")[0];
				    var tr = table.getElementsByTagName("tr")[0];
				    table.removeChild(tr);
				    table.appendChild(tr);
			    }
			d.scrollTop=0;
			clearInterval(_this.scrollTimeId);
			setTimeout(_this.start,_this.config.delay);
		}
	}
	
	this.container.onmouseover=function(){_this.pause = true;}
	this.container.onmouseout=function(){_this.pause = false;}
}
