
var obj = new Object();

var menuImg = "";
var menusub = ""; 

/**
 * JQUERY 확장 함수 구현
 * comment : alert 창을 띄운후 해당 객체에 포커싱 된다.
 * 사용법 : $(name).alert(메시지);
 * date : 2011. 6
 * msg : 메시지 
 */

/**
 * php nl2br 구현
 */


$(function(){

	// 메뉴 안에서는 on 되도록 구현.. 외부 off 구현..
	$("body").mouseover(function(event){
		var on = $(this).attr("menu-on");
		if(typeof(on) == "undefined" || on == null || on == false){
		}else{
			// 메뉴 히든
			var i = event.target.id;
			
			$target = $(event.target);
			
			try{
				var j = $target.parent().parent().parent().attr("id");
				var k = $target.parent().attr("id");
				
				if(i.indexOf("m_i_") < 0 && i.indexOf("m_st0") < 0 && j.indexOf("m_st0") < 0 && k.indexOf("m_st0") < 0){
					obj.$subMenu.slideUp(150);
					if(obj.$parentMenu.parent().attr("alt") != "on") obj.$parentMenu.attr("src", obj.$parentMenu.attr("src").replace("_on", "_off"));
					$("body").attr("menu-on", false);
				}
			}catch(e){
				obj.$subMenu.slideUp(150);
				if(obj.$parentMenu.parent().attr("alt") != "on") obj.$parentMenu.attr("src", obj.$parentMenu.attr("src").replace("_on", "_off"));
				$("body").attr("menu-on", false);
			}				
		}
	});
	
	// 스티커 메뉴 over out
	$(".sticket").hover(function(){
		// 우선 bg0 클래스 삭제..
		$sticket = $("ul#sticket");
		$sticket.removeClass("bg01");
		$sticket.removeClass("bg02");
		$sticket.removeClass("bg03");
		var i = $(this).parent().index() + 1;
		// 각 top 클래스 추가
		$sticket.addClass("bg0" + i);
				
		// 메뉴 이미지 변경
		$(".sticket").each(function(){
			$(this).children().each(function(){
				$(this).attr("src", $(this).attr("src").replace("_on", "_off"));
				return false;
			});
		});
		// 메뉴 on 교체
		$(this).children().each(function(){
			$(this).attr("src", $(this).attr("src").replace("_off", "_on"));
			return false;
		});
		obj.parentNo = i;
	}, function(){
		var i = $(this).parent().index() + 1;
		// 다른 메뉴에서 교체돼었다면 off 로
		if(obj.parentNo != i){
			$(this).children().each(function(){
				$(this).attr("src", $(this).attr("src").replace("_on", "_off"));
				return false;
			});
		}
	});
	
	// 각 이미지 메뉴 on/off 통합 처리
	$(".rollover").hover(function(){
		$this = $(this);
		$this.attr("src", $this.attr("src").replace("_off", "_on"));
		
		// 대메뉴 오버..
		if($this.parent().parent().parent().attr("id") == "gnb"){
			// 현재꺼는 down
			$("#m_st0" + $this.attr("alt")).slideDown(80);
		
			// 서브메뉴 이미지 저장..
			$("body").attr("menu-on", true);

			// 자기 자신한테 다시 오버하는거라면 무시..
			if(typeof(obj.$parentMenu) != "undefined"){
				if(obj.$parentMenu.attr("id") != $this.attr("id")){
					// 이전 메뉴는 up
					if(typeof(obj.$subMenu) != "undefined") obj.$subMenu.slideUp(150);
					// 이전 메뉴 off
					if(obj.$parentMenu.parent().attr("alt") != "on") obj.$parentMenu.attr("src", obj.$parentMenu.attr("src").replace("_on", "_off"));
				}
			}
			// 현재 over 된 메뉴 셋팅 
			obj.$parentMenu = $this;
			obj.$subMenu = $("#m_st0" + $this.attr("alt"));
		}
	}, function(){
		$this = $(this);
		if($this.parent().parent().parent().attr("id") != "gnb"){
			if($this.parent().attr("alt") != "on") $this.attr("src", $this.attr("src").replace("_on", "_off"));
		}
	});

	if(menuImg != "" && typeof(menuImg) != "undefined") obj.$parentMenu = $("#" + menuImg);	// onoff 되는 li
	if(menusub != "" && typeof(menusub) != "undefined") obj.$subMenu = $("#" + menusub);	// display 되는 ul
	
	
	// 컨텐츠 페이지(상품) 에서 줄이기 더보기 버튼 2개가 있는 유형의 slide 이펙트 함수
	/*
	 * <h3 id="smenu07" >미등록 충원 및 추가 모집 합격(신입생군) <span><a href="#"><img src="/images/fund/btn/btn_slim.gif" alt="대미등록 충원 및 추가 모집 합격 내용 간력보기" /></a> <a href="#"><img src="/images/fund/btn/btn_more.gif" alt="미등록 충원 및 추가 모집 합격 내용 더보기" /></a></span></h3>
	 * <div class="hidden_detail"> <!-- hidden_detail : 3줄만 보이게 함. show_detail : 전체가 보임 -->
	 * 이런 구조..
	 */

	// 레이어 숨기기
	$(".layerUp").click(function(){
		$this = $(this);
		$target = $this.parent().parent().parent().parent().next().eq(0);
		
		$target.animate({
			height: "78px"
			}, {
			queue: false,
			duration : "500"
			}, function(){
				;
		 });
		$target.find("table").hide();
		
		return false;
	});
	// 레이어 더보기
	$(".layerDown").click(function(){
		$this = $(this);
		$target = $this.parent().parent().parent().parent().next().eq(0);
		
		/*
		$target.css({
			"height" : "100%",
			"overflow" : "block"
		});
		*/
		$target.animate({
			height : $target.attr("max-height")
			}, {
			queue: false,
			duration : "500"
			}, function(){
				;
		});
		
		$target.find("table").show();
		return false;
	});
	
	// 레이어 숨김 클래스 있는 애들 미리 줄이기
	$(".layerUp").each(function(){
		$this = $(this);
		
		$h3 = $this.parent().parent();
		$target = $h3.next().eq(0);
		var h = $target.attr("max-height");
		if(typeof(h) == "undefined" || h == "" || h == null) $target.attr("max-height", $target.height());
		
		$h3.wrap("<div class='tmp_h' style='display:inline;' />");
		
		$target.css({
			"height" : "78px",
			"overflow" : "hidden",
			"display" : "inlnie-block"
		});
		
		$target.find("table").hide();
	});
});


//open modal window
function openModal(obj, file_name, width, height)
{
	height=height+20;
	var rand = Math.random() * 4;
	window.showModalDialog(file_name + '?rand=' + rand, obj, 'dialogWidth=' + width + 'px;dialogHeight=' + height + 'px;resizable=0;status=0;scroll=0;help=0');
}



