var RangkGoodsControll =  {
	rangkCache : {},

	init : function () {
		$$("#latest_goods_list .rangk_menu-box li").each(function (e) {
			e.observe("click", function () {
				index = $$("#latest_goods_list .rangk_menu-box li").indexOf(e);

				// 클릭한 아이템을 굵게 표현
				RangkGoodsControll.fontWeight(e);

				// 화살표를 이동시킴
				RangkGoodsControll.moveArrow(index);

				// 해당 데이터를 가죠옴
				RangkGoodsControll.getItem(index);

				// 혹시 열려있는 계산기가 있으면 닫히도록 추가. 함승목. 2010.11.18.
				calc.close();
			});
		});
	},

	fontWeight : function (obj) {
		$$("#latest_goods_list .rangk_menu-box li.current").each(function (e) {
			e.removeClassName('current');
		});

		obj.addClassName("current");
	},

	moveArrow : function (i) {
		pointer = $("rangk_arrow-point");

		if (i > 0) {
			pointer.style.backgroundPosition = ((i*90)+20) + "px 0px";
		} else {
			pointer.style.backgroundPosition = "0px 0px";
		}
	},

	manualHide : function (oid) {
		if ($(oid)) {
			$(oid).hide();
		}
	},

	manualShow : function (oid) {
		$$("#rangk_goods-list div.rangk_goods-manuals").each(function(e){
			e.hide();
		});

		if ($(oid)) {
			$(oid).style.display = 'block';
		}

	},

	getItem : function (i) {
		item_result = function (originalRequest) {
			res = originalRequest.responseText;
			param_type = originalRequest.request.parameters.type;			


			if (res.length > 0) {
				$('rangk_goods-list').update(res);

				if (param_type >= 0) {
					RangkGoodsControll.rangkCache[param_type] = res;
				}
			}

		};
		this.rangkCache[i] = ''; // 매번 가져오도록 추가한 라인. 함승목. 2010.11.10.

		if (this.rangkCache[i]) {
			$("rangk_goods-list").update(this.rangkCache[i]);
			return;
		}

		new Ajax.Request(WEBROOT + '/index/rangk_list/', {method:'POST', parameters:{'type':i}, onComplete: item_result});
	}
};

