var layoutController = {
	frontMenu : ['', 'seller_list', 'style_index', 'product_handmade', 'product_onsale', 'product_new_arrivals'],
	frontMenuIndex : 0,

	// 페이지 이동시 frontMenu 에 등록된 컨트롤러_액션 일 경우엔 이벤트 효과를 준다.
	serviceMoveFocusEvent : function () {
		current_service = CONTROLLER+"_"+ACTION;
		index = layoutController.frontMenu.indexOf(current_service);

		if (index >= 0) {
			$("service-menu").style.backgroundPosition = "0px -"+((index*15))+"px";
			layoutController.frontMenuIndex = index;
		}
	},

	// 헤더 메뉴 마우스 온 오버 이벤트 등록
	// 옵저버 사용
	serviceMenuOverEvent : function () {
		$$("#service-menu a.link").each(function(e, i) {
			e.observe('mouseover', function () {
				$("service-menu").style.backgroundPosition = "0px -"+((i+1)*15)+"px";
			});

			e.observe("mouseout", function () {
				$("service-menu").style.backgroundPosition = "0px -"+((layoutController.frontMenuIndex*15))+"px";
			});
		});
	},

    // 헤더에 카테고리 레이어 메뉴의 wrap 별 사이즈를 리사이징한다.
    categoryReSizeProcess : function () {
        // div wrap 처리
        div_wrap    = $$("div#holic_category-layer div.category-wrap");
        div_height  = 0;

		// left div 처리
		div_wrap.each(function (div) {
			ul_wrap = $(div).getElementsBySelector('div.category-list');
			temp_height = 0;

			ul_wrap.each(function(ul, i) {
				if ((i+1)%2 == 0) {
					if (ul.getHeight() > temp_height) {
						ul_wrap[i-1].setStyle("height:"+ul.getHeight().toString()+"px");
						ul.setStyle("height:"+ul.getHeight().toString()+"px");

					} else {
						ul.setStyle("height:"+temp_height.toString()+"px");
						ul_wrap[i-1].setStyle("height:"+ul.getHeight().toString()+"px");
					}

					temp_height = 0;
				}

				temp_height = ul.getHeight();
			});
		});

		// div wrap 처리
        div_wrap.each(function(div) {
            if (div.getHeight() > div_height) {
                div_height = div.getHeight();
            }
        });

        div_wrap.each(function(div){
            div.setStyle("height:" + div_height.toString() + "px");
        });
    },

	// 메뉴 상단 See more 클릭 이벤트
	serviceMenuMoreClickEvent : function () {
		layer = $("holic_category-layer");

		if (layer.style.display == 'none') {
			layer.style.display = 'block';
			this.categoryReSizeProcess();

		} else {
			layer.style.display = 'none';
		}
	},

	// 셀러 리스트 펼침
	sellerListViewEvent : function () {
		layer = $("seller_alp-list");
		layer.style.display = 'block';
	},

	sellerListViewCloseEvent : function () {
		layer = $("seller_alp-list");
		layer.style.display = 'none';
	},

	// 셀러 페이지 레이어를 닫는다.
	sellerDetailViewCloseEvent : function (index) {
		wrap = $("seller-info"+index);
		wrap.update('');
		wrap.hide();
	},

	// 셀러 페이지 레이어를 띄운다
	sellerDetailViewEvent : function () {
		$$("div#main_second-1 a.pvd-sellers").each(function(e){

			e.observe("click", function () {
				index = $$("div#main_second-1 li.pvd-sellers").indexOf(e.parentNode);

				new Ajax.Request(WEBROOT+"/seller/top_list/", {method : 'POST', parameters: {'index':index}, onComplete: function (originalRequest) {
					html = originalRequest.responseText;
					wrap = $("seller-info"+index);

					$$("div#main_second-1 div.pvd-info_box").each(function (v) {
						v.hide();
					});

					wrap.update(html);
					wrap.show();

				}});	
			});
		});
	},

	spotOpacityEvent : function () {
		wrap = $$("div#main_third-items ul li");

		wrap.each(function (li) {
			li.observe('mouseover', function () {
				li.down().next().style.display = 'block';
			});

			li.observe('mouseout', function () {
				li.down().next().style.display = 'none';
			});
		});
	},

	spotItemOverEvent : function () {
		$$("div#main_third-menus a").each(function (e) {
			e.observe('mouseover', function () {
				index = $$("div#main_third-menus a").indexOf(e);
				$("main_third-menus").style.backgroundPosition = "0px -"+(index*27)+"px";
			});

			e.observe('click', function () {
				index = $$("div#main_third-menus a").indexOf(e);
				$$("div#main_third-items div.spotl-items").each(function (div) {
					div.style.display = 'none';
				});

				$$("div#main_third-items div.spotl-items")[index].show();
			});
		});

		
	},

	newApparelList : function () {
		opacity_layer = $$("div#main_4th-wrap div.forinfo");

		first_layer = $$("div#main_4th-wrap li.first");
		first_layer.each(function (f) {
			f.observe('mouseover', function () {
				index = first_layer.indexOf(f);
				opacity_layer[index].style.display = 'block';
			});

			f.observe('mouseout', function (){
				index = first_layer.indexOf(f);
				opacity_layer[index].hide();
			});
		});
	},

	searchProviderAlphEvent : function () {
		/**
			TODO : 알파벳 키워드 클릭은 일단 more 이벤트에 의하여 전체 레이어 뜨드록함
		**/
		list = $$("div#alp-list a.pvd_keyword-call");
		list.each(function (a) {
			a.observe('click', function () {
				/*
                new Ajax.Request(WEBROOT+"/seller/keyword_list/", {method : 'POST', parameters: {'keyword':a.title}, onComplete: function (originalRequest) {
					html = originalRequest.responseText;
					$("seller_keyword-list").update(html);
					$("seller_keyword-list").show();
                }});
				*/
				layoutController.sellerListViewEvent();
			});
		});
	},

	// 니미 팝업은 맨날 오픈하고 집에갈때 주구 난리야
	// 아래 temp 로 시작하는 메소드들은 임시 메소드임...-_- 씨부랄
	tempPopupClose : function () {
		$('temp_first-popup').up().update('');	
	},

	tempPopupLink : function () {
		window.location.href = WEBROOT + '/product/view/id/4454';
	}
};

