﻿function initEventHandler() {
	//검색어완성 창 닫기
	$("#gnb_hide").bind("click", function(e) { $(".autoWord").css({ "display": "none" }); return false; });

	//카테고리 그룹 마우스 오버 처리
	$(".gnb dt[gnb^='gnbMenu']").each(function() {
		$(this).bind("mouseover", function(e) {
			$(".gnb dd").each(function() {
				$(this).addClass("disNone");
			});
			$("#" + $(this).attr("gnb")).removeClass("disNone");
			return false;
		});
	});

	$(".gnb").bind("mouseout", function(e) {
		$(".gnb dd").each(function() {
			$(this).addClass("disNone");
		});
	});

	$(".gnb dd").each(function() {
		$(this).bind("mouseover", function(e) {
			$(this).removeClass("disNone"); return false;
		});
		$(this).bind("mouseout", function(e) {
			$(this).addClass("disNone"); return false;
		});
	});

	//카테고리 열고 닫기
	$("#gnbCateBtn").bind("click", function(e) {
		if ($(this).attr("class") == "cateClose") {
			$(".subMenu").css({ "display": "none" });
			$(this).addClass("cateOpen");
			$(this).removeClass("cateClose");
		}
		else {
			$(".subMenu").css({ "display": "" });
			$(this).addClass("cateClose");
			$(this).removeClass("cateOpen");
		}
		return false;
	});

	//메인 윈도우 이미지 클릭 처리
	$(".mainVisual a").each(function() {
		$(this).bind("mouseover", function(e) {
			$("#mainVisualImg").attr({ "src": $(this).attr("image") });
			$("#mainVisualImgHref").attr({ "href": $(this).attr("link") });
			if ($(this).attr("title") != "")
				$("#mainVisualDescription").html($(this).attr("title"));
			return false;
		});
	});

	$(".mainVisual ul li a[lititle^='mainV']").each(function() {
		$(this).bind("mouseover", function(e) {
			$(".mainVisual ul li").removeClass("selected");
			$("#" + $(this).attr("lititle")).addClass("selected");
			return false;
		});
	});

	//카테고리별 몰리소스 마우스 오버 처리
	$(".cateInfo a[to^='cateInfo']").each(function() {
		$(this).bind("mouseover", function(e) {
			$("#" + $(this).attr("to")).attr({ "src": $(this).attr("image") });
			$("#" + $(this).attr("URLto")).attr({ "href": $(this).attr("link") });
			return false;
		});
	});

	//카테고리 그룹 마우스 오버 처리
	$(".chanceEvent .tab li").each(function() {
		$(this).bind("mouseover", function(e) {
			if ($(this).attr("name") == "DailyChance") {
				$(".chanceEvent .tab li[name='DailyChance']").addClass("on");
				$(".chanceEvent .tab li[name='GstampEvent']").removeClass("on");
				$("#DailyChance").css({ "display": "" });
				$("#GstampEvent").css({ "display": "none" });
			}
			else {
				$(".chanceEvent .tab li[name='GstampEvent']").addClass("on");
				$(".chanceEvent .tab li[name='DailyChance']").removeClass("on");
				$("#DailyChance").css({ "display": "none" });
				$("#GstampEvent").css({ "display": "" });
			}
			return false;
		});
	});

	//Weekly Special (MD's Pick)
	$("a[name=MDsPickRoll]").click(function() {
		var idx;
		if ($(this).attr("class") == "left") {
			if ($(this).attr("idx") == 0)
				idx = $(this).attr("max");
			else
				idx = $(this).attr("idx") - 1;
		} else {
			if ($(this).attr("idx") == $(this).attr("max"))
				idx = 0;
			else
				idx = parseInt($(this).attr("idx")) + 1;
		}

		$("a[name=MDsPickRoll]").attr({ "idx": idx });

		$("#MDsPick_a1").attr({ "href": $("a[name=MDsPickList]").eq(idx).attr("link") });
		$("#MDsPick_a2").attr({ "href": $("a[name=MDsPickList]").eq(idx).attr("link") });
		$("#MDsPick_a2").html($("a[name=MDsPickList]").eq(idx).attr("title"));
		$("#MDsPick_img").attr({ "src": $("a[name=MDsPickList]").eq(idx).attr("image"), "alt": $("a[name=MDsPickList]").eq(idx).attr("title") });
		$("#MDsPick_dd").html($("a[name=MDsPickList]").eq(idx).attr("d_price"));
		return false;
	});

	//Auction Goods
	$("a[name=AuctionGoodsRoll]").click(function() {
		var idx;
		if ($(this).attr("class") == "left") {
			if ($(this).attr("idx") == 0)
				idx = $(this).attr("max");
			else
				idx = $(this).attr("idx") - 1;
		} else {
			if ($(this).attr("idx") == $(this).attr("max"))
				idx = 0;
			else
				idx = parseInt($(this).attr("idx")) + 1;
		}

		$("a[name=AuctionGoodsRoll]").attr({ "idx": idx });

		$("#AuctionGoodsImg").attr({ "src": $("span[name=AuctionGoodsList]").eq(idx).attr("image"), "alt": $("span[name=AuctionGoodsList]").eq(idx).attr("gd_nm") });
		$("#AuctionGoods_a2").html($("span[name=AuctionGoodsList]").eq(idx).attr("title"));
		$("#AuctionGoods_a1").attr({ "href": $("span[name=AuctionGoodsList]").eq(idx).attr("link") });
		$("#AuctionGoods_a2").attr({ "href": $("span[name=AuctionGoodsList]").eq(idx).attr("link") });
		$("#AuctionGoodsPrice").html($("span[name=AuctionGoodsList]").eq(idx).attr("price"));
		$("#AuctionGoodsTimeLeft").removeClass("colorType01");
		$("#AuctionGoodsTimeLeft").removeClass("colorType02");
		$("#AuctionGoodsTimeLeft").html($("span[name=AuctionGoodsList]").eq(idx).attr("time_left") + $("span[name=AuctionGoodsList]").eq(idx).attr("time_left_str"));
		if ($("span[name=AuctionGoodsList]").eq(idx).attr("left_hour") <= 3)
			$("#AuctionGoodsTimeLeft").addClass("colorType01");
		else if ($("span[name=AuctionGoodsList]").eq(idx).attr("left_hour") > 3 && $("span[name=AuctionGoodsList]").eq(idx).attr("left_hour") <= 6)
			$("#AuctionGoodsTimeLeft").addClass("colorType02");

		return false;
	});

	if(window.initEventHandlerSub!=undefined)
		initEventHandlerSub();

}

function GetNotice(nid, link_kind, link) {
	if (link_kind == "P") {
		$(".notice a").attr({ 'href': "javascript:;" });
		$(".notice a").attr({ 'target': "_self" });

		var url = Public.getWWWServerUrl("/Main/PopupNotice.aspx?nid=" + nid, false)
		window.open(url, "popup_notice", "top=100,left=100,Width=470, Height=432,scrollbars=no,resizable=yes");
	}
	else if (link_kind == "N") {

		$(".notice a").attr({ 'target': "_blank" });
		$(".notice a").attr({ 'href': link });
	}
	else {
		$(".notice a").attr({ 'href': link });
		$(".notice a").attr({ 'target': "_self" });
	}
	return false;
}
