var runningindex = 1;
var raounds = 1;
var runner;
var couldrun = true;
function consumer() {
	if (couldrun) {
		var myRequest = new Request( {
			url :page_root + '/lottery/lottery.do',
			method :'get',
			onSuccess : function(responseText, responseXML) {
				if (isNaN(responseText)) {
					alert(responseText);
				} else {
					runner = setInterval("rolling('good','" + responseText + "')", 120);
					couldrun = false;
				}
			}
		}).send('action=consumer&lotterynum=' + $random(0, 9999999) + '&lotterynumber=' + $('lotterynumber').value);
	}else{
		alert("很抱歉，您已经抽过奖了！");
	}
}
function gezi() {
	if (couldrun) {
		var myRequest = new Request( {
			url :page_root + '/lottery/lottery.do',
			method :'get',
			onSuccess : function(responseText, responseXML) {
				if (isNaN(responseText)) {
					alert(responseText);
				} else {
					runner = setInterval("rolling('gezigood','" + responseText + "')", 120);
					couldrun = false;
				}
			}
		}).send('action=gezi&lotterynum=' + $random(0, 9999999));
	}else{
		alert("很抱歉，您已经抽过奖了！");
	}
}

function rolling(obj, index) {

	if (runningindex > 16) {
		$(obj + '16').src = page_root + "/images/lottery/" + obj + "16_1.jpg";
		runningindex = 1;
		raounds++;
	}

	var begfor = runningindex - 1;
	if ($(obj + begfor)) {
		$(obj + begfor).src = page_root + "/images/lottery/" + obj + begfor + "_1.jpg";
	}
	$(obj + runningindex).src = page_root + "/images/lottery/" + obj + runningindex + "_2.jpg";

	if (raounds == 3 && runningindex == index) {
		if (obj == "good") {
			if (index == 6) {
				alert("恭喜你，你获得了一等奖，51logou客服人员将在24小时内根据您的注册资料与您取得联系！");
			} else if (index == 10 || index == 16) {
				alert("恭喜你，你获得了二等奖，51logou客服人员将在24小时内根据您的注册资料与您取得联系！");
			} else if (index == 1 || index == 7 || index == 15) {
				alert("恭喜你，你获得了三等奖，51logou客服人员将在24小时内根据您的注册资料与您取得联系！");
			} else {
				alert("感谢参与，购物再次抽奖！");
			}
		} else if (obj == "gezigood") {
			if (index == 10) {
				alert("恭喜你，你获得了一等奖，51logou客服人员将在24小时内根据您的注册资料与您取得联系！");
			} else if (index == 2 || index == 8) {
				alert("恭喜你，你获得了二等奖，51logou客服人员将在24小时内根据您的注册资料与您取得联系！");
			} else if (index == 3 || index == 12 || index == 15) {
				alert("恭喜你，你获得了三等奖，51logou客服人员将在24小时内根据您的注册资料与您取得联系！");
			} else {
				alert("感谢参与！");
			}
		}
		clearInterval(runner);
	}
	runningindex++;
}