
// gnb서브
  var gcEl;
	function gnbControl(){
		if(gcEl == 1){ //열릴때
			document.getElementById('header_container').style.height="249px";
			document.getElementById('gnbWrap').className="gnbWrapOn";
			document.getElementById('gnbWrapBg').className="gnbWrapBgOn";
			document.getElementById('menuCloseBtn').className="menuCloseBtnOn";
			document.getElementById('menuCloseBtn').childNodes[0].childNodes[0].src=document.getElementById('menuCloseBtn').childNodes[0].childNodes[0].src.replace("_on.gif", "_off.gif");
			document.getElementById('menuCloseBtn').childNodes[0].childNodes[0].alt="CLOSE MENU";
			gcEl=0;
			//alert(gcEl);
			deleteMyCookie();
		}else {	      //닫힐때
			document.getElementById('header_container').style.height="137px";
			document.getElementById('gnbWrap').className="gnbWrapOff";
			document.getElementById('gnbWrapBg').className="gnbWrapBgOff";
			document.getElementById('menuCloseBtn').className="menuCloseBtnOff";
			document.getElementById('menuCloseBtn').childNodes[0].childNodes[0].src=document.getElementById('menuCloseBtn').childNodes[0].childNodes[0].src.replace("_off.gif", "_on.gif");
			document.getElementById('menuCloseBtn').childNodes[0].childNodes[0].alt="OPEN MENU";
			gcEl=1;
    	//alert(gcEl);
			setCookie();
		}
	}
	
	function gnbControl_close(){
			document.getElementById('header_container').style.height="137px";
			document.getElementById('gnbWrap').className="gnbWrapOff";
			document.getElementById('gnbWrapBg').className="gnbWrapBgOff";
			document.getElementById('menuCloseBtn').className="menuCloseBtnOff";
			document.getElementById('menuCloseBtn').childNodes[0].childNodes[0].src=document.getElementById('menuCloseBtn').childNodes[0].childNodes[0].src.replace("_off.gif", "_on.gif");
			gcEl=1;
	}

//이미지 replace
	function imageReplace(el,ext) {
		var target = document.getElementById(el);		 
		var allImg = target.getElementsByTagName("IMG");
	 
		for(var i=0; i< allImg.length; i++){
			allImg[i].parentNode.onmouseover=allImg[i].parentNode.onfocus=function(){
				for(var j=0; j< allImg.length; j++){
					
					allImg[j].src = allImg[j].src.replace("_on."+ext, "_off."+ext);
					//alert(this.childNodes[0]);
					this.childNodes[0].src = this.childNodes[0].src.replace("_off."+ext, "_on."+ext);
				}
			}

			allImg[i].parentNode.onmouseout=allImg[i].parentNode.onblur=function(){
				for(var j=0; j< allImg.length; j++){
					allImg[j].src = allImg[j].src.replace("_on."+ext, "_off."+ext);
				}
			}	
		
		}
	}

//메인tab
function mainTab(num){

	var c_target01 = document.getElementById('content1');
	var c_target02 = document.getElementById('content2');
	var c_target03 = document.getElementById('content3');
	var c_target04 = document.getElementById('content4');

	var t_target01 = document.getElementById('tit01');
	var t_target02 = document.getElementById('tit02');
	var t_target03 = document.getElementById('tit03');
	var t_target04 = document.getElementById('tit04');

	if(num == 1) {
	
		c_target01.style.display="block";
		c_target02.style.display="none";
		c_target03.style.display="none";
		c_target04.style.display="none";
		t_target01.src=t_target01.src.replace("_off.gif","_on.gif");
		t_target02.src=t_target02.src.replace("_on.gif","_off.gif");
		t_target03.src=t_target03.src.replace("_on.gif","_off.gif");
		t_target04.src=t_target04.src.replace("_on.gif","_off.gif");
	}else if(num == 2){
	
		c_target01.style.display="none";
		c_target02.style.display="block";
		c_target03.style.display="none";
		c_target04.style.display="none";
		t_target01.src=t_target01.src.replace("_on.gif","_off.gif");
		t_target02.src=t_target02.src.replace("_off.gif","_on.gif");
		t_target03.src=t_target03.src.replace("_on.gif","_off.gif");
		t_target04.src=t_target04.src.replace("_on.gif","_off.gif");
	}else if(num == 3){
	
		c_target01.style.display="none";
		c_target02.style.display="none";
		c_target03.style.display="block";
		c_target04.style.display="none";
		t_target01.src=t_target01.src.replace("_on.gif","_off.gif");
		t_target02.src=t_target02.src.replace("_on.gif","_off.gif");
		t_target03.src=t_target03.src.replace("_off.gif","_on.gif");
		t_target04.src=t_target04.src.replace("_on.gif","_off.gif");
	}else if(num == 4){
	
		c_target01.style.display="none";
		c_target02.style.display="none";
		c_target03.style.display="none";
		c_target04.style.display="block";
		t_target01.src=t_target01.src.replace("_on.gif","_off.gif");
		t_target02.src=t_target02.src.replace("_on.gif","_off.gif");
		t_target03.src=t_target03.src.replace("_on.gif","_off.gif");
		t_target04.src=t_target04.src.replace("_off.gif","_on.gif");
	
	
	}
}

//메인tab
function mainTab2(num){

	var c_target01 = document.getElementById('content11');
	var c_target02 = document.getElementById('content12');
	var c_target03 = document.getElementById('content13');

	var t_target01 = document.getElementById('tit11');
	var t_target02 = document.getElementById('tit12');
	var t_target03 = document.getElementById('tit13');

	if(num == 1) {
	
		c_target01.style.display="block";
		c_target02.style.display="none";
		c_target03.style.display="none";
		t_target01.src=t_target01.src.replace("_off.gif","_on.gif");
		t_target02.src=t_target02.src.replace("_on.gif","_off.gif");
		t_target03.src=t_target03.src.replace("_on.gif","_off.gif");
	}else if(num == 2){
	
		c_target01.style.display="none";
		c_target02.style.display="block";
		c_target03.style.display="none";
		t_target01.src=t_target01.src.replace("_on.gif","_off.gif");
		t_target02.src=t_target02.src.replace("_off.gif","_on.gif");
		t_target03.src=t_target03.src.replace("_on.gif","_off.gif");
	}else if(num == 3){
	
		c_target01.style.display="none";
		c_target02.style.display="none";
		c_target03.style.display="block";
		t_target01.src=t_target01.src.replace("_on.gif","_off.gif");
		t_target02.src=t_target02.src.replace("_on.gif","_off.gif");
		t_target03.src=t_target03.src.replace("_off.gif","_on.gif");
	}
}

/*----------------------------*/

var bannerRolling = function(bannerContainer){
	// 시간단위는 ms로 1000이 1초
	if(bannerContainer.nodeType==1){
		this.bannerContainer = bannerContainer;
	}else{
		this.bannerContainer = document.getElementById(bannerContainer);
	}
	this.is_rolling = false;
	this.direction = 1; //1:top, 2:right, 3:bottom, 4:left (시계방향) // 1번과 4번만 됨
	this.children = null;
	this.move_gap = 1; //움직이는 픽셀단위
	this.timeDealy = 20; //움직이는 타임딜레이
	this.timeDealyPause = 2000;//하나의 대상이 새로 시작할 때 멈추는 시간, 0 이면 적용 안함
	this.time_timer=null;
	this.time_timer_pause=null;
	this.mouseover=false;
	this.user_stop=false;
	this.init();
	this.setDirection(this.direction);
}

bannerRolling.prototype.init = function(){
	this.bannerContainer.style.position='relative';
	this.bannerContainer.style.overflow='hidden';
	var children = this.bannerContainer.childNodes;
	for(var i=(children.length-1);0<=i;i--){
		if(children[i].nodeType==1){
			children[i].style.position='relative';
			children[i].style.padding='0 5px 0 0';
		}else{
			this.bannerContainer.removeChild(children[i]);
		}
	}
	var bannerContainer=this;
	this.bannerContainer.onmouseover=function(){
		bannerContainer.mouseover=true;
		if(!bannerContainer.time_timer_pause){
			bannerContainer.pause();
		}
	}
	this.bannerContainer.onmouseout=function(){
		bannerContainer.mouseover=false;
		if(!bannerContainer.time_timer_pause){
			bannerContainer.resume();
		}
	}
	
}

bannerRolling.prototype.setDirection = function(direction){
	this.direction=direction;
	if(this.direction==2 ||this.direction==4){
		this.bannerContainer.style.whiteSpace='nowrap';
	}else{
		this.bannerContainer.style.whiteSpace='normal';
	}
	var children = this.bannerContainer.childNodes;
	for(var i=(children.length-1);0<=i;i--){
		if(this.direction==1){
			children[i].style.display='block';
		}else if(this.direction==2){
			children[i].style.textlign='right';
			children[i].style.display='inline';
		}else if(this.direction==3){
			children[i].style.display='block';
		}else if(this.direction==4){
			children[i].style.display='inline';
		}
	}
	this.init_element_children(); 
}

bannerRolling.prototype.init_element_children = function(){
	var children = this.bannerContainer.childNodes;
	this.children = children;
	for(var i=(children.length-1);0<=i;i--){
		if(this.direction==1){
			children[i].style.top='0px';
		}else if(this.direction==2){
			children[i].style.left='-'+this.bannerContainer.firstChild.offsetWidth+'px';
		}else if(this.direction==3){
			children[i].style.top='-'+this.bannerContainer.firstChild.offsetHeight+'px';
		}else if(this.direction==4){
			children[i].style.left='0px';
		}
	}
}

bannerRolling.prototype.act_move_up = function(){
	for(var i=0, m=this.children.length; i<m; i++){
		var child = this.children[i];
		child.style.top=(parseInt(child.style.top)-this.move_gap)+'px';
	}
	if((this.children[0].offsetHeight+parseInt(this.children[0].style.top))<=0){
		this.bannerContainer.appendChild(this.children[0]);
		this.init_element_children();
		this.pause_act();  
	}
}

bannerRolling.prototype.move_up = function(){
	if(this.direction!=1&&this.direction!=3){return false;}
	this.bannerContainer.appendChild(this.children[0]);
	this.init_element_children();
	this.pause_act(); 
}

bannerRolling.prototype.act_move_down = function(){
	for(var i=0, m=this.children.length; i<m; i++){
		var child = this.children[i];
		child.style.top=(parseInt(child.style.top)+this.move_gap)+'px';
	}
	if(parseInt(this.children[0].style.top)>=0){
		this.bannerContainer.insertBefore(this.bannerContainer.lastChild,this.bannerContainer.firstChild);
		this.init_element_children();
		this.pause_act(); 
	}
}

bannerRolling.prototype.move_down = function(){
	if(this.direction!=1&&this.direction!=3){return false;} 
	this.bannerContainer.insertBefore(this.bannerContainer.lastChild,this.bannerContainer.firstChild);
	this.init_element_children();
	this.pause_act();
}

bannerRolling.prototype.act_move_left = function(){
	for(var i = 0,m=this.children.length;i<m;i++){
		var child = this.children[i];
		child.style.left=(parseInt(child.style.left)-this.move_gap)+'px';
	}
	if((this.children[0].offsetWidth+parseInt(this.children[0].style.left))<=0){
		this.bannerContainer.appendChild(this.bannerContainer.firstChild);
		this.init_element_children();
		this.pause_act();  
	}
}

bannerRolling.prototype.move_left = function(){
	if(this.direction!=2&&this.direction!=4){return false;}  
	this.bannerContainer.appendChild(this.bannerContainer.firstChild);
	this.init_element_children();
	this.pause_act();  
}

bannerRolling.prototype.act_move_right = function(){
	for(var i = 0,m=this.children.length;i<m;i++){
		var child = this.children[i];
		child.style.left=(parseInt(child.style.left)+this.move_gap)+'px';
	}

	if(parseInt(this.bannerContainer.lastChild.style.left)>=0){
		this.bannerContainer.insertBefore(this.bannerContainer.lastChild,this.bannerContainer.firstChild);
		this.init_element_children();
		this.pause_act();  
	}
}

bannerRolling.prototype.move_right = function(){
	if(this.direction!=2&&this.direction!=4){return false;}   
	this.bannerContainer.insertBefore(this.bannerContainer.lastChild,this.bannerContainer.firstChild);
	this.init_element_children();
	this.pause_act();
}

bannerRolling.prototype.start = function(){ //롤링 시작
	var bannerContainer = this;
	this.stop();
	this.is_rolling = true;
	var act = function(){
		if(bannerContainer.is_rolling){
			if(bannerContainer.direction==1){bannerContainer.act_move_up();}
			else if(bannerContainer.direction==2){bannerContainer.act_move_right();}
			else if(bannerContainer.direction==3){bannerContainer.act_move_down();}
			else if(bannerContainer.direction==4){bannerContainer.act_move_left();}
		}
	}
	this.time_timer = setInterval(act,this.timeDealy);
}

bannerRolling.prototype.pause_act = function(){ //일시 동작
	if(this.timeDealyPause){
		var bannerContainer = this;
		var act = function(){bannerContainer.resume();bannerContainer.time_timer_pause=null;}
		if(this.time_timer_pause){clearTimeout(this.time_timer_pause);}
		this.time_timer_pause = setTimeout(act,this.timeDealyPause);
		this.pause();
	}
}

bannerRolling.prototype.pause = function(){ //일시 멈춤
	this.is_rolling = false;
}

bannerRolling.prototype.resume = function(){ //일시 멈춤 해제
	if(!this.mouseover && !this.user_stop){
		this.is_rolling = true;
	}
}

bannerRolling.prototype.stop = function(){ //롤링을 끝냄
	this.is_rolling = false;
	if(!this.time_timer){
		clearInterval(this.time_timer);
	}
	this.time_timer = null;
}
	
bannerRolling.prototype.user_pause = function(){ //일시 멈춤
	this.user_stop = true;
	this.pause();
}

bannerRolling.prototype.user_resume = function(){ //일시 멈춤 해제
	this.user_stop = false;
	this.resume();
}




/*  롤팝업용 자바 스크립트 파일 (roll_popup.js)
---------------------------------------------------------*/
var popRolling = function(popContainer){
	// 시간단위는 ms로 1000이 1초
	if(popContainer.nodeType==1){
		this.popContainer = popContainer;
	}else{
		this.popContainer = document.getElementById(popContainer);
	}
	this.is_rolling = false;
	this.counter = 0;
	this.pop_children = null;
	this.timeDealy = 3000; //움직이는 타임딜레이
	this.time_timer = null;
	this.time_timer_pause=null;
	this.mouseover=false;
	this.init();
}

popRolling.prototype.init = function(){
	var pop_children = this.popContainer.childNodes;

	for(var i=(pop_children.length-1); 0<=i; i--){
		if(pop_children[i].nodeType==1){
			//pop_children[i].style.position='relative';
		}else{
			this.popContainer.removeChild(pop_children[i]);
		}
	}

	this.pop_children = this.popContainer.childNodes;
	var oRoll = this;

	for (var i=0; i<this.pop_children.length; i++) {

		for (var k=0; k<this.pop_children[i].childNodes.length; k++) {

			if (this.pop_children[i].childNodes[k].nodeType == 1) {

				this.pop_children[i].childNodes[k].onclick = function() {
					oRoll.moveAt(this.firstChild);
					return false;
				}
				this.pop_children[i].childNodes[k].onfocus = function() {
					oRoll.moveAt(this.firstChild);
					return false;
				}
				break;	// 첫번째 링크(A)에만 이벤트 할당
			}
		}
	}
}

popRolling.prototype.moveAt = function(oBtn){
	//var i = oBtn.id.substring(6);
	var i = oBtn.className.substring(6);
	this.mouseover = true;
	if(!this.time_timer_pause){
		this.counter = (i-1);
		this.move_right();
		this.pause();
	}
}

popRolling.prototype.move_right = function(){
	var oRoll = this;
	var nTemp = 0;
	for(var i=0, m=oRoll.pop_children.length; i<m; i++){

		nTemp = 0;
		for (var k=0; k<this.pop_children[i].childNodes.length; k++) {

			if (this.pop_children[i].childNodes[k].nodeType == 1) {
				nTemp++;
				if (nTemp == 1) {
					var child_1 = oRoll.pop_children[i].childNodes[k].childNodes[0];	//버튼이미지
					child_1.src = child_1.src.replace(/_on.gif/gi,"_off.gif");

					if (i == oRoll.counter) {
						child_1.src = child_1.src.replace(/_off.gif/gi,"_on.gif");
					}
				}
				else {
					var child_2 = oRoll.pop_children[i].childNodes[k];	//배너이미지

					var aaa = oRoll.pop_children[i].childNodes[k];

					child_2.style.display = "none";

					if (i == oRoll.counter) {
						child_2.style.display = "block";
					}
				}

			}
		}
	}

	oRoll.counter++;
	if (oRoll.counter >= oRoll.pop_children.length) {
		oRoll.counter = 0;
	}
}


popRolling.prototype.start = function(){ //롤링 시작
	var oRoll = this;
	this.stop();
	this.is_rolling = true;

	var act = function(){
		if(oRoll.is_rolling){
			oRoll.move_right();
		}
	}
	if (!this.time_timer) {
		act();	// 처음 로딩시 첫번째 버튼이 즉시 선택되도록
	}
	this.time_timer = setInterval(act,this.timeDealy);
}

popRolling.prototype.pause = function(){ //일시 멈춤
	this.is_rolling = false;
}
popRolling.prototype.resume = function(){ //일시 멈춤 해제
	//if(!this.mouseover){
		this.is_rolling = true;
	//}
}

popRolling.prototype.stop = function(){ //롤링을 끝냄
	this.is_rolling = false;
	if(!this.time_timer){
		clearInterval(this.time_timer);
	}
	this.time_timer = null;
}

