/* VisualMIX vote routines ; thanks to jquery-tutorial-simple-ajax-star-rating-with-php for the css tricks! */


	$(document).ready(function() {

                function getRateXML(responseXML) {
                  if ($('novote',responseXML).text()) { $("#ratelinks").hide(); }
                  if ($('report',responseXML).text()) { $("#result-rating").hide().html($('rating',responseXML).text() + "/5" +  " (<i><span title=\"" + $('voters',responseXML).text() + " voted\">" + $('pct',responseXML).text() + "% like this!</i>)</span>&nbsp;").fadeIn("slow"); } 
		      $("#current-rating").css({ width: "" + $('pct',responseXML).text() + "%" }); 
                }


		function getRating(){
			$.ajax({
				type: "POST",
				url: "/ajax/vote/get/",
				cache: false,
				async: false,
                                datatype: 'xml',
				success: function(responseXML) {
                                  if ($('novote',responseXML).text()) { getRateXML(responseXML); }
                                  if ($('msg',responseXML).text()) { 
                                      $.jGrowl($('msg',responseXML).text(), { header: "vote", life: 10000 });
                                  }
                                },
				error: function(result) {
                                  $.jGrowl("There has been an error with your voting process while receiving data!", { header: "vote", life: 10000 });
                                  $("#result-rating").html("<span title=\"" + result + "\">Vote error (RX)</span>");
				}
			});
		}
		
		$('#ratelinks li a').click(function(){
			$.ajax({
				type: "POST",
				url: "/ajax/vote/do/isrc/" + $(this).attr("id") + "/" + $(this).text(),
				cache: false,
				async: false,
                                datatype: 'xml',
				success: function(responseXML) {
    			          $("#ratelinks").hide();
                                  if ($('msg',responseXML).text()) { 
                                      $.jGrowl($('msg',responseXML).text(), { header: "vote", life: 10000 });
                                  }
                                  getRateXML(responseXML);
				},
				error: function(result) {
                                  $("#result-rating").html("<span title=\"" + result + "\">Vote error (TX)</span>");
                                  $.jGrowl("There has been an error with your voting process while transmitting data!", { header: "vote", life: 10000 });
				}
			});
			
		});
	});

