old_vote = 0;
$(document).ready(function(){
if ($('.vote-star')) {
   $('.vote-star').hover(
      function(){
	 if (old_vote == 0)
	    old_vote = findVote();
	 obj = $(this);
	 objid = (obj.attr('id')).replace(/vote/, '');

	 for (i = 1; i <= 5; i++) {
	    $('#vote'+i).attr('src', '/images/general-imgs/star-off.gif');
	 }

	 for (i = 1; i <= objid; i++) {
	    $('#vote'+i).attr('src', '/images/general-imgs/star-on.gif');
	 }

      }, 
      function(){
      }
   );
   $('.vote').hover(
      function(){
      }, 
      function(){
	 if (old_vote != 0) {
	    for (i = 1; i <= 5; i++) {
	       $('#vote'+i).attr('src', '/images/general-imgs/star-off.gif');
	    }

	    for (i = 1; i <= old_vote; i++) {
	       $('#vote'+i).attr('src', '/images/general-imgs/star-on.gif');
	    }
	    old_vote = 0;
	 }
      }
   );

   $('.vote-star').click (function(){
      obj = $(this);
      id = obj.attr('id').replace(/vote/, '');

      $.ajax({
	 type: "POST",
	 url: "/ajax/vote.php",
	 data: "obj_id="+getRequest('id', 0, true)+"&vote="+id,
	 success: function (msg) {
	    if (msg == '')
	       myAlert(get_text('Message'), get_text('I psifos sas kataxwrithike'));
	 }
      });
   });
}
});

function findVote () {
   stars = $('.vote:first').children('img');
   max = 0;
   $.each (stars, function(){
      obj = $(this);
      if ((obj.attr('src')).indexOf('-on') > 0) {
	 id = obj.attr('id');
	 id = id.replace(/vote/, '');
	 if (id > max)
	    max = id;
      }
   });

   return max;
}

