$(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 trackEroClick() {
	if(typeof(pageTracker) != 'undefined') {
		
		pageTracker._initData();
		pageTracker._trackEvent('Advertising Clicks', 'EroAds', 'EroAds');
		
	} else {
		
		_gaq.push(['_trackEvent', 'Advertising Clicks', 'EroAds', 'EroAds']);

	}	
}

function eroTrack() {
	
	$('div#ero_url a').click( function() {
		trackEroClick();
	});
	
	$('a.ero_url').click( function() {
		trackEroClick();
	});
	
	
	$('div#msncontent a').click( function() {
		trackEroClick();
	})
	
	$('a.highlight').click( function() {
		trackEroClick();
	});	
}



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++;
		
	}

}
