function init_rating() {
		
	getRating();
	
	$('#ratelinks li a').click(function(){  
		urlPathArray = window.location.pathname.split('/');
		// Get the first section of your path
		tvshow=urlPathArray[1];
	
		$.ajax({
			url:        '/'+tvshow+'/rate',
			data: "rating="+$(this).text()+"&do=rate",
			type:       'GET',
			timeout:    '5000',
			dataType: "json",
			cache: false,  
			async: false,  
			success: function(data) {
				$("#ratelinks").remove();
				getRating(); 
			},
			
			// We're gonna hide everything when get error
			error: function(result) {
				//alert("some error occured, please try again later");
			}
		});
	
	});
	
	$('.broken').click(function(event){  
		
		current_id = $(this);
		
		$.ajax({
			url:        $(this).attr("href"),
			data: "link="+$(this).attr("rel"),
			type:       'GET',
			timeout:    '5000',
			dataType: "html",
			cache: false,  
			async: false,  
			success: function(data) {
				current_id.parent().html(data);
				$(".suggest_link").colorbox({width:"60%", height:"80%", iframe:true});
			},
			
			// We're gonna hide everything when get error
			error: function(result) {
				//alert("some error occured, please try again later");
			}
		});
		
	event.preventDefault();
	
	});

}

function getRating() {
	
	urlPathArray = window.location.pathname.split('/');
	// Get the first section of your path
	tvshow=urlPathArray[1];

	$.ajax({
		url:        '/'+tvshow+'/rate',
		data: "do=getrate",
		type:       'GET',
		timeout:    '5000',
		dataType: "json",
		cache: false,  
		async: false,  
		success: function(data) {
			$("#current-rating").css({ width: "" + data.rating.rating + "%" });
			$("#total-votes").replaceWith('<em id="total-votes">'+data.rating.total_votes+' votes');
		},
		
		// We're gonna hide everything when get error
		error: function(result) {
			//alert("some error occured, please try again later");
		}
	});

}

$(document).ready(function() {
	init_rating();
});

