//Author : kingthy
//Date	 : 2008/07/16
//*************************************************************

jslib.namespace("jslib.effect");
if(typeof(jslib.effect.scroll) == 'undefined'){
	var __jslib_effect_scroll =[];
	jslib.effect.__startscroll = function(o,h){
		o.scrollTop += h;	
		if((o.scrollTop % o.clientHeight) == 0 || (o.scrollTop % o.clientHeight) > (o.clientHeight - h + 1)){
			var data = __jslib_effect_scroll[o];		
			clearInterval(data.timer);
			data.starting = false;
			data.stoped = false;
			data.index ++;
			var childs = jslib.dom.getchilds(o);
			if(data.index >= childs.length){
				var node = jslib.dom.removenode(childs[childs.length - 1]);
				o.insertBefore(node,childs[0]);
				o.scrollTop = 0;
				data.index = 1;
			}
			setTimeout(function(){
				data.starting = true;
				data.stoped = false;
				data.timer = setInterval(function(){
					jslib.effect.__startscroll(o,data.height);
				},data.speed);
			},data.delay);
		}
	}
	jslib.effect.scroll = function(id,h,s,d){
		var o = jslib.$(id);
		if(o == null || !o.childNodes || o.childNodes.length < 2)return;
		if(h == undefined)h = 5;
		if(s == undefined)s = 20;
		if(d == undefined)d = 3000;
		
		if(__jslib_effect_scroll[o] != undefined)return;
		__jslib_effect_scroll[o] = {timer : 0, starting : false, stoped : true, height : h, speed : s, delay : d, index : 1};

		setTimeout(function(){
			var data = __jslib_effect_scroll[o];
			data.timer = setInterval(function(){
				jslib.effect.__startscroll(o,data.height);
			},data.speed);

			data.starting = true;
			data.stoped = false;
			o.onmouseover = function(){
				if(data.starting){
					data.stoped = true;
					clearInterval(data.timer);
				}
			};
			o.onmouseout = function(){
				if(data.starting && data.stoped){
					data.stoped = true;
					data.timer = setInterval(function(){
						jslib.effect.__startscroll(o,data.height);
					},data.speed);
				}
			};
		},d);
	}
}