// JavaScript Document
	$(document).ready(function() {
		
		function getRating(get_id){		
			$.ajax({
				type: "GET",
				url: "http://www.litera.ro/json/rating_update.php",
				data: "do=getrate&id_carte="+get_id,
				cache: false,
				async: false,
				success: function(result) {
					// apply star rating to element
					$("#current-rating_top").css({ width: "" + result + "%" });
				},
				error: function(result) {
					alert("some error occured, please try again later");
				}
			});
		}
		
		// link handler
		$('#ratelinks li a').click(function(){
		var get_joc_id = $(this).attr('id');
		
			$.ajax({
				type: "GET",
				url: "http://www.litera.ro/json/rating_update.php",
				data: "rating="+$(this).text()+"&do=rate&id_carte="+ $(this).attr('id'),
				cache: false,
				async: false,
				success: function(result) {
					// remove #ratelinks element to prevent another rate
					$("#ratelinks").remove();
					// get rating after click
					getRating(get_joc_id);
				},
				error: function(result) {
					alert("some error occured, please try again later");
				}
			});
			
		});
	});

