var MouseDownNow = false;

function starSwitcher(star_id,star,msie) {
	// makes stars show a vote of whatever user is hovering on, called by onmouseover
	setStars(star_id,star,msie);
	MouseDownNow = true;
}

function resetStars(star_id,curStar,msie) {
	// onmouseout
	MouseDownNow = false;
	setTimeout('resetStarsNow("'+star_id+'","'+curStar+'","'+msie+'")', 50);
}

function resetStarsNow(star_id,curStar,msie){
	// return stars to previously stored value.  That's usually the original value, but it can also become
	// whatever rating the user just voted.
	var table;
	if(MouseDownNow == false) {
		if (table=$(star_id)) {
			// 10/5/10 don't use curstar param anymore
			curStar=Number(table.getAttribute('x-score'));
			setStars(star_id,curStar,msie);
		}
	}
}

function setStars(star_id,rating,msie) {
	for (var i=1;i<=5;i++) {
		star=$(star_id+'_'+i);
		if (star) {
			if(msie == 'y') {
				star=star.filters(0);
			}
			if (i> rating)
				star.src='/editorial/images/star_off.png';
			else
				star.src='/editorial/images/star_on.png';
		}
	}

}

function voteNow(star_id,vote_for,vote,token) {
	var table;
	if (table=$(star_id)) {
		table.setAttribute('x-score',vote); // so the mouseout will restore the user's current vote, instead of the previous rating
	}
	if (stat_area=$(star_id+'_voteResults')) {
		stat_area.style.display = '';
		stat_area.innerHTML = 'Saving Vote, Please Wait...';
	} else {
		// need to do some effect so that they know something is happening
		new Effect.Highlight(table,{duration:0.5,startcolor: "#7f7fff", endcolor: "#ffffff"});
	}
	//ajax_request('/','vote_for='+vote_for+'&vote='+vote+'&ajax=1','hideVoteResults(\''+star_id+'\')');
	new Ajax.Request('/', {
		method: 'get',
		parameters: 'request_type=vote&vote_for='+vote_for+'&vote='+vote+'&token='+token+'&ajax_request=1',
		onSuccess: function(transport) { hideVoteResults(transport,star_id); }
	});

	return false;
}

function hideVoteResults(transport,id) {
	if (stat_area=$(id+'_voteResults')) {
		stat_area.innerHTML = transport.responseText;
		stat_area.style.display = '';
	}

	setTimeout(
		function() {
			if (stat_area=$(id+'_voteResults')) {
				stat_area.innerHTML = '';
				stat_area.style.display = 'none';
			}
		}, 2000
	);
}


