$(document).ready( function() {
	
	// Bind actions to rate stars
	$('div.ratestars').hover( 	function() { $(this).toggleClass('ratestars_over'); }, function() {$(this).toggleClass('ratestars_over');});
	$('div.ratestar').hover( 	function() { ratestarOver(this)}, function() {ratestarOut(this)} );
	$('div.ratestar').click( 	function() { castrate(this);} );
	
	// Lets tell the system we're not a spider ;)
	$.get(LINKROOT+'/index.php?action=frontend_handshake');

	
});



function castrate(star) {
	id = star.id;
	var parts = id.split('_'); 
	
	$('#ratethanks_'+parts[1]).show();
	$('#ratestars_'+parts[1]).unbind();
	$('#ratestars_'+parts[1]+' div.ratestar').unbind();	
	$('#ratestars_'+parts[1]).toggleClass('ratestars_over');
	
	var url = LINKROOT+'/?action=frontend_rate';
	var data = 'movie='+parts[1]+'&rating='+parts[2];
	
	$.post(url, data);

}

function ratestarOver(star) {
	
	id = star.id;
	parts = id.split('_');
	pfx = parts[0]+'_'+parts[1];
	
	
	i=1;
	while(i <= parts[2])
	{
		var thisid = pfx+'_'+i
		
		$('#'+thisid).toggleClass('ratestar_over');
		i++;
		
	}
}

function ratestarOut(star) {
	id = star.id;
	parts = id.split('_');
	pfx = parts[0]+'_'+parts[1];
	
	
	i=1;
	while(i <= parts[2])
	{
		var thisid = pfx+'_'+i
		
		$('#'+thisid).toggleClass('ratestar_over');
		i++;
		
	}

}