/**
 * @author m_simard
 */

$(document).ready(function(){
	$(".bigstar_system a ").hover(
		function(){	//Hover
			var rater = $(this).parents("ul.bigstar_system");
			var hoverScore = $(this).attr("href").replace("#", "");
			var curScore = rater.find("input[name=currentScore]").val();

			if(!rater.data("cScore")){
					rater.data("cScore", curScore);
			}
			rater.removeClass("bscore"+curScore).addClass("bscore" + hoverScore);
		},
		function(){	//Out
			var rater = $(this).parents("ul.bigstar_system");
			var curScore =	rater.data("cScore");
			var hoverScore = $(this).attr("href").replace("#", "");

			rater.removeClass("bscore" + hoverScore).addClass("bscore"+curScore);;
		});


	$(".bigstar_system a ").click(function(){
		var box = $(this).parents(".rating_box");
		var rater = $(this).parents("ul.bigstar_system");
		var setting = rater.attr("id").split("-");
		var curScore = rater.find("input[name=currentScore]").val();

		var url = "?guimode=ajax&action=dorating";
		var params = {
			method: "get",
			id: setting[2],
			type:setting[1],
			rating: $(this).attr("href").replace("#", "")
		}

		$.get(url, params, function(response){
			rater.find("a").unbind("click");
			var curScore = rater.find("input[name=currentScore]").val();

			responses = response.split(" ");
			box.find("strong").html("Thank you");
			rater.data("cScore", Math.round(responses[0]));
			rater.removeClass("bscore" + curScore).addClass("bscore" + rater.data("cScore"));
			box.find(".overallscore").html(responses[0]);
			box.find(".numofrating").html(responses[1]);
			box.find(".vote").html(responses[2]);
		});
		return false;
	});
});

