// JavaScript Document
	$(document).ready(function() {
		// get current rating
		getRate();
		// get rating function
		function getRating(){
			$.ajax({
				type: "GET",
				url: "../../../vote_article.php",
				data: "do=getrate&articleId=" + $("#articleId").val(),
				cache: false,
				async: false,
				success: function(result) {
				// apply star rating to element
				$("#current-rating").css({ width: "" + result + "%" });
				},
				error: function(result) {
					alert("some error occured, please try again later");
				}
			});
		}
		
		// get rate function
		function getRate(){
			$.ajax({
				type: "GET",
				url: "../../../vote_article.php",
				data: "do=getrate&articleId=" + $("#articleId").val(),
				cache: false,
				async: false,
				success: function(result) {
				
				// apply star rating to element
				$("#current-rating").css({ width: "" + result + "%" });
				
				},
				error: function(result) {
					alert("some error occured, please try again later");
				}
			});
		}
		
		// link handler
		$('#ratelinks li a').click(function(){
			$.ajax({
				type: "GET",
				url: "../../../vote_article.php",
				data: "rating="+$(this).text()+"&do=rate&articleId=" + $("#articleId").val(),
				cache: false,
				async: false,
				success: function(result) {
				// remove #ratelinks element to prevent another rate
				$("#ratelinks").remove();
				// get rating after click
				$("#idcounter").html(result);
				if(result == "Thanks for your vote.")
					getRating();
				},
				error: function(result) {
					alert("some error occured, please try again later");
				}
			});
			
		});
	});
