var Cash;
var Slot = 
{
	ITEM : { '13' : 500, '14' : 1300, '15' : 2100, '16' : 4000},
	start : function()
	{
		var SlotPriceArrayLayer = $$('.slot_price_off');
		SlotPriceArrayLayer[0].className = 'slot_price_on';
		SlotPriceArrayLayer.each(Slot.build, this);
		
		document.SLOT_FORM.ITEM_NUM[0].checked = true;
		Slot.setPriceSpan(form.getRadioValue(document.SLOT_FORM.ITEM_NUM));
	},
	build : function(el)
	{
		el.addEvent(
			'click', function(event){
				Slot.setOff();
				this.className = 'slot_price_on';
				var item = this.getElement('.ITEM');
				item.checked = true;
				Slot.setPriceSpan(item.value);
			}
		);
	},
	setOff : function()
	{
		$$('.slot_price_on').each(function(el)
		{
			el.className = 'slot_price_off';
		}, this);
	},
	setPriceSpan : function(ITEM_NUM)
	{
		$('price_span').setText(money(this.ITEM[ITEM_NUM]));

		if(Cash < this.ITEM[ITEM_NUM])
		{
			if (!Login.getLogin())
			{
				$('SLOT_LINK').href = 'javascript:Slot.submit();';
			}
			else
			{
				$('SLOT_LINK').href = '/Store/Cash';
			}
			$('SLOT_LINK').setText('충전하기');
			$('Cash_alert').setText('캐시 잔액이 부족 합니다! 충전하기 버튼을 클릭하세요!');
		}
		else
		{
			$('SLOT_LINK').href = 'javascript:Slot.submit();';
			$('SLOT_LINK').setText('결제하기');
			$('Cash_alert').setText('');
		}
	},
	submit : function()
	{
		if(!Login.getLogin())
		{
			alert('로그인 후 이용하시기 바랍니다.');
			location.href = '/Login/?DIR=' + document.location.href;
			return false;
		}
		if(!confirm('정말 구매 하시겠습니까?'))
		{ 
			//location.href = './';
			return;
		}
		
		var Result = Ajax.exec('SlotBuy.php',
							{ "ITEM_NUM" : form.getRadioValue(document.SLOT_FORM.ITEM_NUM)} );
		if(Result.text == "OK")
		{
			var Windows = _Window.showPopUp();
			Windows.style.width    = '454px';
			
			var Param = {  'MODE' : 'Call'  };
			
			Param["Type"] =  "Page";
			Param.onComplete = function ()
			{
				UI.setScreenCenter(this);
			}.bind(Windows);
		    	  
		    AutoRun.setDocument(Windows, Param, '/Store/Slot/EndLayer.php');
		}
		else alert(Result.text);
	},
	close : function ()
	{
		_Window.closePopUp();
	}
}

addEvent(window, 'load', Slot.start);

