// JavaScript Document

var choiceArr = new Array(20);
var maxChoices = 20;
var choiceCounter = 20;

function voteFor(id) {
	var choices = document.getElementById("choices");
	var celeb = document.getElementById("celeb"+id);
	var c = isChosen(id);
	if(c > -1) {
		celeb.style.backgroundColor = "transparent";
		choiceArr.splice(c,1);
		choiceCounter++;
	} else if(choiceCounter > 0) {
		celeb.style.backgroundColor = "#8D0000";
		choiceArr[maxChoices-choiceCounter] = id;
		choiceCounter--;
	} else {
		document.getElementById('tabnav').tabber.tabShow(6);
	}
	choices.value = choiceArr.join(",");
	updateCounter();
}

function updateCounter() {
	var counter = document.getElementById("counter");
	counter.innerHTML = choiceCounter;
}

function isChosen(id) {
	for(var i=0; i<= choiceArr.length; i++) {
		//alert("i:"+i+" choiceArr[i]:"+choiceArr[i]);
		if(choiceArr[i] == id) return i;
	}
	return -1;
}
