var categoryGoodsControll = {
	'_category1st'	: null,
	'_category_position' : null,
	'_more_cid' : null,//메인 '더보기' 위한 추가. 함승목. 10.09.14.
	'_ajax_latest_list' : {},

	'init' : function (category1st) {
		this._category1st = category1st;

		// 대분류 상퓸 메뉴 위치값
		this._category_position = $$("#category_goods_menu li");

		// 대분류 상품 메뉴 설정
		var seq = 0;

		this._category1st.each(function(c){
			var category_menu_item = categoryGoodsControll._category_position[seq];
			category_menu_item.update(c.category_title);
			category_menu_item.observe('click', function () {categoryGoodsControll.getGoods(category_menu_item, c.id)});
			seq++;
		});

	},

	'moveMorePage' : function() { //메인 더보기 메서드 추가. 함승목. 10.09.14.
		var href = WEBROOT+'/product/list';
		if(categoryGoodsControll._more_cid != null) {
			href += '/category_id/'+categoryGoodsControll._more_cid+'/';
		}
		location.href = href;
	},

	'getGoods' : function (obj, category_id) {
		var latest_result = function (originalRequest) {
			var html = originalRequest.responseText;

			categoryGoodsControll._more_cid = category_id;//메인 '더보기' 위한 추가. 함승목. 10.09.14.

			if (html.length > 0) {
				$('latest_product-list').update(html);
				categoryGoodsControll._ajax_latest_list[originalRequest.request.parameters['category_id']] = html;
			}
		};

		// category_id 에 따라서 ajax 요청
		// 결과값을 ajax_latest_list 에 담아놓고, 다시 요청이 있을 경우엔 list 에서 반환
		if (this._ajax_latest_list[category_id]) {
			$('latest_product-list').update(this._ajax_latest_list[category_id]);
		} else {
			new Ajax.Request(WEBROOT + '/index/latest_product/', {method:'POST', parameters:{'category_id':category_id}, onComplete : latest_result});
		}
	
		var total_width = 0;

		for (var i=0; i<= this._category_position.length;i++) {
			if (this._category_position[i] == obj) {
				break;
			}
			total_width = total_width + this._category_position[i].getWidth();
		}	

		cursor_position = ((obj.getWidth()/2) + total_width + 12).toString() + 'px 0px';
		$('category_active').style.backgroundPosition = cursor_position;
	},

	verticalImg : function (mheight, obj) {
		var img = new Image();
		img.src = obj.src;

		obj_height = img.height;

		if (obj_height != mheight && obj_height > 0) {
			margin_height = (mheight - obj_height) / 2;
			obj.style.marginTop = margin_height +'px';
		}
	}
};

