

function changeTab(obj, div, idx){
		roller.gotoDiv(div, idx);
		for(var i=0; i<obj.parentNode.childNodes.length; i++) if(obj.parentNode.childNodes[i].className=="r_tab_on") obj.parentNode.childNodes[i].className="r_tab_off";
		obj.className = "r_tab_on";
}


/**************************************************************************
 *  rolling Div 1.0
 *  아래의 함수로 모든 롤링 div를 사용할 수 있음.
 *
 *  사용법 : 다음과 같이 div id값을 정의한다 rollDivXXXX0 rollDivXXXX1 ....
 *            Prev 버튼 roller.previousDiv(XXXX), Next 버튼 roller.nextDiv(XXXX) 끝.
 *            roller.newRolling은 시간마다 롤링이 필요한경우만 사용. 정적인 곳에는 불필요.
 *
 *            Copyright ⓒ JKNews co. Ltd.  Programmed by Maxwell Shim.
 ***************************************************************************/
 
var roller = {
		rollDiv: new Object(),
		
		previousDiv: function(id){
			if(typeof(roller.rollDiv[id]) == 'undefined') roller.newRolling(id);
			else if(roller.rollDiv[id].timeId) roller.stopRolling(id);
			
			var idx = roller.rollDiv[id].current;
			document.getElementById("rollDiv"+id+idx).style.display = 'none';
			idx = (idx-1<0) ? roller.rollDiv[id].total : idx-1;
			document.getElementById("rollDiv"+id+idx).style.display = 'block';
			roller.rollDiv[id].current = idx;
			if(roller.rollDiv[id].term>0) roller.startRolling(id);
		},
		
		nextDiv: function(id){
			if(typeof(roller.rollDiv[id]) == 'undefined') roller.newRolling(id);
			else if(roller.rollDiv[id].timeId) roller.stopRolling(id);
				
			var idx = roller.rollDiv[id].current;
			document.getElementById("rollDiv"+id+idx).style.display = 'none';
			if(idx+1>roller.rollDiv[id].total && roller.rollDiv[id].pa){
				var nidx = parseInt(id.substr(id.length-1));
				nidx = (nidx+1>roller.rollDiv[roller.rollDiv[id].pa].total) ? 0 : nidx+1;
				var nid = id.substr(0, id.length-1)+nidx;	
				roller.nextDiv(roller.rollDiv[id].pa);
				roller.newRolling(nid, roller.rollDiv[id].term, roller.rollDiv[id].pa);
				roller.rollDiv[id].term = 0;
			}
			idx = (idx+1>roller.rollDiv[id].total) ? 0 : idx+1;
			document.getElementById("rollDiv"+id+idx).style.display = 'block';
			roller.rollDiv[id].current = idx;
			if(roller.rollDiv[id].term>0) roller.startRolling(id);
		},
		
		gotoDiv: function(id, idx){
			if(typeof(roller.rollDiv[id]) == 'undefined') roller.newRolling(id);
			else if(roller.rollDiv[id].timeId) roller.stopRolling(id);
				
			document.getElementById("rollDiv"+id+roller.rollDiv[id].current).style.display = 'none';
			document.getElementById("rollDiv"+id+idx).style.display = 'block';
			roller.rollDiv[id].current = idx;
			if(roller.rollDiv[id].term>0) roller.startRolling(id);
		},
		
		newRolling: function(){
			var id = arguments[0];
			var term = (arguments[1]) ? arguments[1] : 0;
			var pa = (arguments[2]) ? arguments[2] : '';
			for(var i=0;document.getElementById("rollDiv"+id+i)!=null; i++);
			roller.rollDiv[id] = new Object();
			roller.rollDiv[id].total = i-1;
			roller.rollDiv[id].current = 0;
			roller.rollDiv[id].term = term;
			roller.rollDiv[id].timeId = 0;
			roller.rollDiv[id].pa = pa;
			if(term>0) roller.startRolling(id);
			//if(pa) roller.newRolling(pa);
		},
	
		stopRolling: function(id){
			clearTimeout(roller.rollDiv[id].timeId)
		},
	
		startRolling: function(id){
			roller.rollDiv[id].timeId = setTimeout("roller.nextDiv('"+id+"')", roller.rollDiv[id].term);
		},
		
		autoSet: function(){
			var imgs = document.getElementsByTagName("img");
			var anchors = document.getElementsByTagName("a");
			roller.regRolling(imgs);
			roller.regRolling(anchors);
		},
		
		regRolling: function(obj){
			var i=0;
			for(i=0;i<obj.length;i++){
				if(obj[i].getAttribute("rolling")){
					var oid = obj[i].getAttribute("rolling");
					var alt = obj[i].getAttribute("alt");
					var timeset =	obj[i].getAttribute("timeset");
					if(alt.substr(0, 2)=="이전"||alt.substr(0, 2).toUpperCase()=="PR"){
						obj[i].setAttribute("onclick", "roller.previousDiv('"+oid+"');");
					}	else {
						obj[i].setAttribute("onclick", "roller.nextDiv('"+oid+"');");
					}
					if(timeset!=null) roller.newRolling(oid, timeset);
				}
			}	
		}
		
	}

//	addOnLoadEvent(roller.autoSet);
	
/*************************************************************************
 * Vertical rolling
 *
 *	Useage : var hotKeyword = new scrollingNews("JKHeadList",5000,5,1,17);
 ************************************************************************/
	
function scrollingNews(objId,sec1,sec2,speed,height){ 
  this.objId=objId; 
  this.sec1=sec1; 
  this.sec2=sec2; 
  this.speed=speed; 
  this.height=height; 
  this.h=0; 
  this.div=document.getElementById(this.objId);
  this.htmltxt=this.div.innerHTML; 
  this.div.innerHTML=this.htmltxt+this.htmltxt; 
  this.div.isover=false; 
  this.div.onmouseover=function(){this.isover=true;} 
  this.div.onmouseout=function(){this.isover=false;} 
  var self=this; 
  this.div.scrollTop=0; 
  window.setTimeout(function(){self.play()},this.sec1); 
} 
scrollingNews.prototype={ 
  play:function(){ 
    var self=this; 
    if(!this.div.isover){ 
      this.div.scrollTop+=this.speed; 
      if(this.div.scrollTop>this.div.scrollHeight/2){ 
        this.div.scrollTop=0;
        this.h = 0;
      }else{ 
        this.h+=this.speed; 
        if(this.h>=this.height){ 
          if(this.h>this.height){ //|| this.div.scrollTop%this.height !=0){ 
            this.div.scrollTop-= this.h-this.height; //this.h%this.height; 
          } 
          this.h=0; 
          window.setTimeout(function(){self.play()},this.sec1); 
          return; 
        } 
      } 
    } 
    window.setTimeout(function(){self.play()},this.sec2); 
  }, 
  prev:function(){ 
    if(this.div.scrollTop == 0) 
    this.div.scrollTop = this.div.scrollHeight/2; 
    this.div.scrollTop -= this.height; 
  }, 
  next:function(){ 
    if(this.div.scrollTop ==  this.div.scrollHeight/2) 
    this.div.scrollTop =0; 
    this.div.scrollTop += this.height; 
  } 
};

