if(typeof (addOnLoadEvent) == 'undefined'){ alert('Javascript Plug-in is not found. : common.js'); }

function checkSearchForm(f){
	if(f.skey.value==""){ alert("°Ë»öÇÒ ´Ü¾î¸¦ ÀÔ·ÂÇØ ÁÖ¼¼¿ä."); f.skey.focus(); return false; }
}

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=="on") obj.parentNode.childNodes[i].className="";
	obj.className = "on";
} 

function changeTab2(obj, div, idx){
	obj.className = "on";
	document.getElementById("btn"+div+"Tab"+idx).className="";
	roller.gotoDiv(div, idx);
}


/**************************************************************************
 *  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; 
  } 
};


/***********************************************************************
 * Scrolling
 *
 ***********************************************************************/


		function scrollMotion(){
      		this.target = arguments[0];
      		this.scrollsize = arguments[1];
      		this.type = (arguments[2]) ? arguments[2] : 'h';
      		this.totalsize = (this.type=="h") ? parseInt(this.target.style.width) : parseInt(this.target.style.height);
      		this.movepoint;
      		this.moving = false;
      	}
      	
      	scrollMotion.prototype = {
      		prev : function(){
      			if(this.moving || this.totalsize<=this.scrollsize) return;
      			var pos = (this.type=='h') ? parseInt(this.target.style.left) : parseInt(this.target.style.top);
      			if(pos==0){ alert("Ã¹ ÆäÀÌÁöÀÔ´Ï´Ù."); return; }
      			if((pos + this.scrollsize)>0) this.movepoint = 0;
      			else this.movepoint = pos + this.scrollsize;
      			this.moving = true;
      			this.scrollContent();
      		},
      		next : function(){
      			if(this.moving || this.totalsize<=this.scrollsize) return;
      			var pos = (this.type=='h') ? parseInt(this.target.style.left) : parseInt(this.target.style.top);
      			if((pos - this.scrollsize)<-this.totalsize+this.scrollsize){
      				this.movepoint = -this.totalsize+this.scrollsize;
      				if(this.movepoint == pos){ alert("¸¶Áö¸· ÆäÀÌÁöÀÔ´Ï´Ù."); return; }
      			}
      			else this.movepoint = pos-this.scrollsize;
      			this.moving = true;
      			this.scrollContent();
      		},
      		scrollContent : function(){
      			var pos = (this.type=='h') ? parseInt(this.target.style.left) : parseInt(this.target.style.top);
      			if(this.movepoint == pos){
      				this.moving = false;
      			} else {
      				var speed = (this.movepoint-pos) / 8;
      				var space = (speed>0) ? Math.ceil(speed) : Math.floor(speed);
      				if(this.type=='h') this.target.style.left = (pos+space) + 'px';
      				else this.target.style.top = (pos+space) + 'px';
      				var tmp = this;
      				setTimeout(function(){ tmp.scrollContent(); }, 40);
      			}
      		}
      	}
      	
      	
/**************************************
 * Vertical Scrolling
 **************************************/
 
 function setVerticalScrolling(id, baseTop, limitHeightID){
		var tg = Math.floor(document.documentElement.scrollTop) - baseTop;
		var limitHeight = document.getElementById(limitHeightID).clientHeight;
		if(tg<0) tg = 0;
		else if(tg>(limitHeight-document.getElementById(id).clientHeight)) tg = limitHeight-document.getElementById(id).clientHeight;
		var _current = parseInt(document.getElementById(id).style.top);
		if(tg != _current){
			var dist = (tg - _current) /4;
			var mv = (dist>0) ? Math.floor(dist) : Math.ceil(dist);
			document.getElementById(id).style.top = (_current+mv)+'px';
			setTimeout(function(){setVerticalScrolling(id, baseTop, limitHeightID)},50);
		} else setTimeout(function(){setVerticalScrolling(id, baseTop, limitHeightID)},100);
	}

