var message_count = 3;	  // 몇개의 message를 출력할 것인가?
var interval = 15;	  // 움직이는 속도를 조절할 수 있음


function get_rtquery(count, start_index){	return true;}

function get_rtquery0(count, start_index){}

function scroll_up(obj){	obj.go_dest();
}
var timer_id2;
function scroll_rerun(){
	clearInterval(timer_id2);
	scroll_run();
}

function scroll_run(obj_name)
{		
	timer_id = setInterval("scroll_up("+obj_name+")", interval);
}

function scroll_stop()
{
	if (timer_id2)
		clearInterval(timer_id2);
	    	
		clearInterval(timer_id);
}




//클래스 만들기
function obj_rolling(){
	this.childs = new Array();
	this.scroll_type = "h";			//수평 스크롤
	this.scroll_height = 50;		//크기
	this.scroll_width = 260;		//크기
	
	this.num_show_panel = 2;		//화면에 보이는 페널수
	this.scroll_step 		= 1;		//이동될 화면수
	
	this.first_child = null;
	this.rolling_dest = 0;			//롤링될 지점

	this.num_move_frame = 20;		//이동 프래임수
	
	this.count_move = 0;			//남은 이동 프래임수
	
	this.drection = null;			//방향

	
	this.reset_position = function(){
		for(var i=0;i<this.childs.length;i++){
			if(this.scroll_type=="h")
				this.childs[i].style.left = this.scroll_width * (i) +"px";
			else
				this.childs[i].style.top = this.scroll_width * (i) +"px";
		}
	}

	//이동시작 type=> "prev" and other
	this.start_dest = function(obj_name, type){
		if(this.childs.length < this.num_show_panel+this.scroll_step) return;
		
		idrection =  (type == "prev")? -1:1;
		
		//이동 도중 누르면 가중시키거나 뺀다
		if(this.count_move>0){
			//방향이 같다면
			if(this.drection == idrection){
				this.count_move += this.num_move_frame;
			}else{
				this.count_move = this.num_move_frame - this.count_move;
			}
				
		}
		//그냥 새로운 시작
		else{
			this.count_move = this.num_move_frame;
		}
		this.drection = idrection;
		scroll_run(obj_name);
	}
	this.go_dest = function(){
		//카운트 오버시 정지시키기
		if(this.count_move-- <=0){
			scroll_stop();
			return;
		}

		for(var i=0;i<this.childs.length;i++){
			if(this.scroll_type=="h"){
				left = parseInt(this.childs[i].style.left);
				this.childs[i].style.left = (left + this.move_point * this.drection)+"px";
				//alert(left + this.move_point * this.drection);
			}else{
				top = parseInt(this.childs[i].style.top);
				this.childs[i].style.top = (top + this.move_point * this.drection)+"px";
			}
		}

		//첫 자식의 벗어남 체크
		left = parseInt(this.childs[this.first_child].style.left);
		//top =  parseInt(this.childs[this.first_child].style.top);
		//좌측으로 벗어남 => 첫번째 자식을 끝으로 보내고 새로운 자식을 첫자식으로 설정
		if(left<-this.scroll_width+this.move_point){
			if(this.scroll_type=="h"){
				this.childs[this.first_child].style.left = (left + this.childs.length * this.scroll_width) + "px";
			}else{
				this.childs[this.first_child].style.top = (top + this.childs.length * this.scroll_width) + "px";
			}
			
			this.first_child++;
			if(this.first_child >= this.childs.length) this.first_child = 0;
		}
		//우측으로 벗어남 => 첫번째 자식을 앞으로 맨 뒷 자식을 가져오구 첫자식을 변경함
		if(left >0-this.move_point){
			last_child = this.first_child-1
			if(last_child < 0) last_child = this.childs.length - 1;
			last_left = parseInt(this.childs[last_child].style.left);
			last_top = parseInt(this.childs[last_child].style.top);
			

			if(this.scroll_type=="h"){
				this.childs[last_child].style.left = (last_left - this.childs.length * this.scroll_width) + "px";
			}else{
				this.childs[last_child].style.top = (last_top - this.childs.length * this.scroll_width) + "px";
			}

			this.first_child--;
			if(this.first_child < 0) this.first_child = this.childs.length-1;
		}
		
		
	}
	this.init = function(tar, className){


		//obj_roller = new obj_rolling();
		this.move_point = ((this.scroll_type == "h")? 
			this.scroll_width*this.scroll_step : this.scroll_height*this.scroll_step)/this.num_move_frame;		//이동 프래임수
		
		for(var i=0; i<tar.childNodes.length ; i++){
			//스크롤 시킬 자식들을 배열에 담는다
			if(tar.childNodes[i].tagName && tar.childNodes[i].className.indexOf(className) != -1){
				this.childs.push(tar.childNodes[i]);
			}
		}
		this.first_child = 0;
		this.reset_position();
	

	}
	
	return this;
}


