/*
*starvote object
*/
var max_stars = 5;
var star_on = '/fg/public/img/ratesmall.gif';
var star_off = '/fg/public/img/ratesmall-bgg.gif';
function printStars(identity, curvote){
	var starscontent = "";
	for(var i = 1; i <= max_stars; i++){
		if(i <= curvote){
			//aggiungo stellina on
			starscontent += "<em onclick='vote("+identity+","+i+","+curvote+");'  id='star_"+identity+"_"+i+"' onmouseover='lighter("+identity+","+i+")' onmouseout='lighter("+identity+","+curvote+")' class='starvote'>+</em>";
		} else {
			//stellina off
			starscontent += "<em  onclick='vote("+identity+","+i+","+curvote+");' style='background: transparent url(/fg/public/img/ratesmall-bgg.gif) no-repeat scroll 0 0;' id='star_"+identity+"_"+i+"' onmouseout='lighter("+identity+","+curvote+")'  onmouseover='lighter("+identity+","+i+")' class='starvote'>*</em>";
		}
	}
	$('stars_'+identity).innerHTML="<strong>"+starscontent+"</strong>";
};
var success = 0;
function vote (identity, vote, oldvote){
	var url = "/fotogallery/starvote.php?mode=vote&entity="+identity+"&vote="+vote;
	url2 = document.location;
	//memorizzo il voto
	printStars(identity, vote);
	if(identity >= 1 && vote >= 1){
		success = 1;
		new Ajax.Request(
			url, {
				method: 'get',
				onSuccess: function (transport){
					success = 0;
					if(transport.responseText >= 1){
						//voto memorizzato con successo
						printStars(identity,vote);
					} else if (transport.responseText == -1){
						//non sei loggato
						printStars(identity, oldvote);
			                $j('#starvote-overlay-login').show()
					} else {
						//problemi durante la memorizzazione del voto
						printStars(identity,oldvote);
			                $j('#starvote-overlay-voted').show()
					}	
				},
				on404: function(){},
				on500: function(){},
				on503: function(){}
			}
		);
	}	
	//illumino le stelline con l'ultima media voti
};
function lighter (identity, numstar){
	for(var i = 1; i <= max_stars; i++){
		if(i<=numstar){
			//accendo
			$j('#star_'+identity+'_'+i).css('background-image', 'url(/fg/public/img/ratesmall.gif)');
		} else {
			//spengo
			$j('#star_'+identity+'_'+i).css('background-image', 'url(/fg/public/img/ratesmall-bgg.gif)');	
		}
	}
}




