function generateRatings(rating, nb_votes)
{
	new Starbox('ratingDiv', rating, { rerate: false, indicator: '#{total} votes', total: nb_votes });
}

function starClicked(event)
{
	var xmlHttpReq=getXmlHttpRequest();
	if(!xmlHttpReq)
		return;
	xmlHttpReq.open("POST","/ratings.php",true);
	xmlHttpReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xmlHttpReq.send('&video_id='+video_id+'&rating='+event.memo.rated.toFixed(2));
}
document.observe('dom:loaded', function()
{
	document.observe('starbox:rated', starClicked);
});

function starboxChangedText(event)
{
	var indicator = this.down('.indicator'),
	pick = (event.memo.rating || 0).round() - 1,
	indicator = this.down('.indicator');
	
	this.starboxResetText = this.starboxResetText || indicator.innerHTML;
	
	this.down('.indicator').update([
	'Poor',
	'Nothing special',
	'Worth watching',
	'Pretty cool',
	'Awesome!'
	][pick]);  
}
function starboxRatedText()
{
	var indicator = this.down('.indicator');
	this.starboxResetText = indicator.innerHTML;
}
function starboxLeftText()
{
	this.down('.indicator').update(this.starboxResetText || '');
}

document.observe('dom:loaded', function()
{
	GetElement('ratingDiv').observe('starbox:changed', starboxChangedText);
	GetElement('ratingDiv').observe('starbox:rated', starboxRatedText);
	GetElement('ratingDiv').observe('starbox:left', starboxLeftText);
});


function starboxThankYou(event)
{
	var indicator = event.findElement('.starbox').down('.indicator'),
	restore = indicator.innerHTML;
	indicator.update('Thanks for voting');
}
document.observe('dom:loaded', function() {
	GetElement('ratingDiv').observe('starbox:rated', starboxThankYou);
});