// Performer ertekelesehez hasznalt csillagok

var sMax = 5;	// Isthe maximum number of stars
var preSet; // Is the PreSet value onces a selection has been made
var rated;

// Rollover for image Stars //
function rating(id, pname){
	for (i = 1; i <= sMax; i++){		
		if (i<=id){
			document.getElementById("x"+i+pname).className = "star_full";	
		}
		else{
			document.getElementById("x"+i+pname).className = "star_empty";
		}
	}
}

// For when you roll out of the whole thing //
function off(id, sum, pname){	
	for (i = 1; i <= sMax; i++){
		if (i > sum){
			document.getElementById("x"+i + pname).className = "star_empty";
		}
		else{
			document.getElementById("x"+i + pname).className = "star_full";
		}
	}
}

function updatePerformerRate(rate, performerId)
{
  $.ajax({
   type: "GET",
   url: "ajax/response.php?module=rates&action=setPerformerRate&params[performerid]="+performerId+"&params[rate]="+rate,
   success: function(msg){
   actualRate = rate;
   var starElement = $("a.star_full, a.star_empty");
   
   for (i=0; i<starElement.length; i++){
     starElement[i].className = "star_empty";
   }
   
   for (i=0; i<rate; i++){
     starElement[i].className = "star_full";
   }
   },
   error: function(){
      alert("Error while saving rate!");
   }
 });
}

$(document).ready(function()
{
  $("a.star_full, a.star_empty").click(function() 
  {
    if (loggedin == true){
		updatePerformerRate(this.id.substr(1,1), this.id.substr(2, this.id.length));  
	}
    return false;
  });
  
  $("a.star_full, a.star_empty").mouseout(function() 
  {
    var pname = this.id.substr(2,this.id.length);
    off(this.id, actualRate, pname);
    return false;
  });
  
  $("a.star_full, a.star_empty").mouseover(function() 
  {
    var id = this.id.substr(1,1);
	var pname = this.id.substr(2,this.id.length);
	rating(id, pname)  
    return false;
  });
});