/**This is a rating system with images**/

$(document).ready(function() 
{
	// get current rating
	getRating(siteID);
	// get rating function
	function getRating(siteID)
	{
		$.ajax(
		{
			type: "GET",
			url: "/scripts/rateWebsite.php",
			data: "do=getRating&siteID="+siteID,
			cache: false,
			async: false,
			success: function(result)
			{
				// apply star rating to element
				$("#current-rating").css({ width: "" + result + "%" });
			document.getElementById("current-rating").title = "Here is the average rating from all our visitors ("+ result/20 + " / 5)";
			},
			error: function(result) 
			{
				alert("Sorry, there was an error loading the rating system.");
			}
		});
	}

	// link handler
	$('#ratelinks li a').click(function()
	{
		$.ajax(
		{
			type: "GET",
			url: "/scripts/rateWebsite.php",
			data: "rating="+$(this).text()+"&do=addRating&siteID="+siteID,
			cache: false,
			async: false,
			success: function(result)
			{
				// remove #ratelinks element to prevent another rate
				$("#ratelinks").remove();
				// get rating after click
				getRating(siteID);

			document.getElementById("current-rating").style.display = 'block';
			document.getElementById("rateComment").innerHTML = "Thank you for your rating";
			//document.getElementsByTagName("star-rating").title = "Here is the rating from all our visitors ("+ result + ")";
			//document.getElementById("star-rating").title = "test"
			},
			error: function(result)
			{
				alert("Your rating could not be saved, sorry for any inconvenience. Please try again later.");
			}
		});

	});
});
