// depth1 ¸Þ´º on ÀÌ¹ÌÁö

var d1MenuImgOn = new Array("","./images/main/top_menu_01_on.jpg", "./images/main/top_menu_02_on.jpg", "./images/main/top_menu_03_on.jpg", "./images/main/top_menu_04_on.jpg", "./images/main/top_menu_05_on.jpg", "./images/main/top_menu_06_on.jpg", "./images/main/top_menu_07_on.jpg", "./images/main/top_menu_08_on.jpg", "./images/main/top_menu_09_on.jpg");

// depth1 ¸Þ´º off ÀÌ¹ÌÁö

var d1MenuImgOff = new Array("","./images/main/top_menu_01.jpg", "./images/main/top_menu_02.jpg", "./images/main/top_menu_03.jpg", "./images/main/top_menu_04.jpg", "./images/main/top_menu_05.jpg", "./images/main/top_menu_06.jpg", "./images/main/top_menu_07.jpg", "./images/main/top_menu_08.jpg", "./images/main/top_menu_09.jpg");


$(document).ready(function() { 
	
		// topmenu 
	
		for (var i = 1; i < d1MenuImgOn.length; i++) {
		// Depth 1 mouseover ½Ã
		
		$('ul#topmenu li.menu' + i + '>a').bind("mouseover", i, function(e){
			var i = e.data;
			$('ul#topmenu>li>ul').addClass('haze');
			$('ul#topmenu>li.menu' + i + '>ul').removeClass('haze');
			
			// Depth 1 Menu 
			
			for (var j = 1; j < d1MenuImgOn.length; j++) {
				$("ul#topmenu>li.menu" + j + ">a>img").attr('src', d1MenuImgOff[j]);			
			}
			$("ul#topmenu>li.menu" + i + ">a>img").attr('src', d1MenuImgOn[i]);								
		});

		// focus ½Ã
		
		$('ul#topmenu>li.menu' + i + '>a').bind("focus", i, function(e){
			$('ul#topmenu>li> ul').addClass('haze');;
			$('ul#topmenu>li.menu' + e.data + '>ul').removeClass('haze');;
			
			// Depth 1 Menu 
			
			for (var j = 1; j < d1MenuImgOn.length; j++) {
				$("ul#topmenu>li.menu" + j + ">a>img").attr('src', d1MenuImgOff[j]);			
			}
			$("ul#topmenu>li.menu" + e.data + ">a>img").attr('src', d1MenuImgOn[e.data]);				
		});					
		
		// Depth 2 mouseout ½Ã
		
		$('ul#topmenu>li.menu' + i+ '>ul').bind("mouseout", i, function(e){
			if($.browser.msie){
				to = $(e.toElement); 
			   }else if($.browser.mozilla){
				to = $(e.currentTarget);
			   }
			if(to.attr("class") == $(this).attr("class") || to.parent().attr("class") == $(this).attr("class") ||  to.parent().parent().attr("class")  == $(this).attr("class") ){ return false;}
			var i = e.data;
			$('ul#topmenu>li.menu' + i+ '>ul').addClass('haze');;
			$("ul#topmenu>li.menu" + i + ">a>img").attr('src', d1MenuImgOff[i]);			
		});
	};
				

	// »õ¼Ò½Ä, º¸µµÀÚ·á

	$(".board_navi > a").hover(function(){

		$(this).siblings().each(function(){
	   $(">img", $(this)).attr("src",  $(">img", $(this)).attr("src").replace(/_on\./, "_off."));
		});
		$(">img", $(this)).attr("src", $(">img", $(this)).attr("src").replace(/_off\./, "_on."));
		
		$(".board_con").addClass("haze");
		thisIdx = $(">a", $(this).parent()).index($(this));
		$(".board_con").eq(thisIdx).removeClass("haze")
		return false;
	});
	
	
//---------------------------------------
	$(".issue_navi > a").hover(function(){

		$(this).siblings().each(function(){
	   $(">img", $(this)).attr("src",  $(">img", $(this)).attr("src").replace(/_on\./, "_off."));
		});
		$(">img", $(this)).attr("src", $(">img", $(this)).attr("src").replace(/_off\./, "_on."));
		
		$(".major_issue_con").addClass("haze");
		thisIdx = $(">a", $(this).parent()).index($(this));
		$(".major_issue_con").eq(thisIdx).removeClass("haze")
		return false;
	});
//---------------------------------------

	// main °¢Á¾ ÆË¾÷ Á¦¾î (2009.7.29)
	
	$("p#popupC1 > a").click(function(){
		popup1(this);
	});
	var timer1;
	$(".btn_pop_play").click(function(){
		if(timer1){return;}
		playPop1();
		timer1 = setInterval("playPop1()", 5000);// ½½¶óÀÌµù Å¸ÀÓ Á¶Àý msec, 5ÃÊ = 5000
		
	});
	
	$(".btn_pop_pause").click(function(){
		clearInterval(timer1);
		timer1 = null;
	});
	
	$("#bannerPrev").click(function(){
		 prevmTicker(1); 
	});
	
	$("#bannerNext").click(function(){
		 nextmTicker(1); 
	});	
	
});

function stopEvent(evnt){
      if(evnt.stopPropagation){
             evnt.stopPropagation();
      }else{
              evnt.cancelbubble = true;
      }
}

// ¼ø¼­´ë·Î ½½¶óÀÌµå

function playPop1(){
	nowOn = $("p#popupC1 > a[nowOn*='on']");
	if(!nowOn.get(0)){
		nowOn = $("p#popupC1 > a").eq(0);
		nowOn = nowOn.next();
	}
	else if(!nowOn.next().get(0)){
		nowOn = $("p#popupC1 > a").eq(0);
	}else{
		nowOn = nowOn.next();
	}
	popup1(nowOn);
}

// ¼±ÅÃµÈ ÅÂ±×¸¦ ±âÁØÀ¸·Î °ü·Ã µð½ºÇÃ·¹ÀÌ on, off

function popup1(tag){
	tagA = $(tag);
	tagA.siblings("a").each(function() {
		image = $(">img", $(this));
		image.attr("src",  image.attr("src").replace(/_on\./, "_off."));
		$(this).attr("nowOn", "off");
	});
	image = $(">img", tagA);
	image.attr("src",  image.attr("src").replace(/_off\./, "_on."));
	tagA.attr("nowOn", "on");
	$("p#popupV1 > a").addClass('haze');
	$("p#popupV1 > a").eq($("p#popupC1 > a").index(tagA)).removeClass('haze');
}
/*µû¶ó´Ù´Ï´Â ¸Þ´º*/

function initMoving(target, position, topLimit, btmLimit) {
	if (!target)
		return false;

	var obj = target;
	obj.style.position = "absolute";
	obj.initTop = position;
	obj.topLimit = topLimit;
	//obj.bottomLimit = document.documentElement.scrollHeight - btmLimit; // Àß¸øµÈ ºÎºÐ
	obj.bottomLimit = btmLimit;
	obj.top = obj.initTop;
	obj.left = obj.initLeft;

	if (typeof(window.pageYOffset) == "number") {
		obj.getTop = function() {
			return window.pageYOffset;
		}
	} else if (typeof(document.documentElement.scrollTop) == "number") {
		obj.getTop = function() {
			return document.documentElement.scrollTop;
		}
	} else {
		obj.getTop = function() {
			return 0;
		}
	}

	if (self.innerHeight) {
		obj.getHeight = function() {
			return self.innerHeight;
		}
	} else if(document.documentElement.clientHeight) {
		obj.getHeight = function() {
			return document.documentElement.clientHeight;
		}
	} else {
		obj.getHeight = function() {
			return 00;
		}
	}

	obj.move = setInterval(function() {		
		if (obj.initTop > 0) {
			pos = obj.getTop() + obj.initTop;
		} else {
			pos = obj.getTop() + obj.getHeight() + obj.initTop;
			//pos = obj.getTop() + obj.getHeight() / 2 - 15;
		}
		if (pos > obj.bottomLimit)
			pos = obj.bottomLimit;
		if (pos < obj.topLimit)
			pos = obj.topLimit;
		interval = obj.top - pos;
		obj.top = obj.top - interval / 3;
		obj.style.top = obj.top + "px";
	}, 30)
}
