
function ratepostVote(post_id, vote) {
	jQuery.ajax({
		type: 'POST',
		data: {'rating_post_id': post_id, 'rating_vote': vote},
		url: 'http://www.btvnoticies.cat/index.php?ak_action=ratepost_vote',
		timeout: 2000,
		error: function() {},
		success: function(r) {
			   jQuery("#text_vot_"+post_id).html(r);
			   getMediaVotos(post_id);
		}
	})
	return false;
}

function getMediaVotos(post_id){
  var media=jQuery.ajax({
							type: 'POST',
							data: {'post_id': post_id},
							async: false,
							url: 'http://www.btvnoticies.cat/index.php?ak_action=get_ratepost_vote_avg',
							timeout: 2000
				 	 }).responseText; 
   rating_obj=jQuery("ul#_rating_post_"+post_id + " li");
   rating_obj.each(function(){
      jQuery(this).unbind();
      currentVote=jQuery(this).attr('rel');
      if (currentVote<=media){
       	  jQuery(this).find("img").attr("src","http://www.btvnoticies.cat/wp-content/plugins/vote-the-post/star.gif");
      }else{
       	  jQuery(this).find("img").attr("src","http://www.btvnoticies.cat/wp-content/plugins/vote-the-post/star-dim.gif");
      }
   });
}

jQuery(document).ready(function() {
	jQuery("ul._star_rating_ li:not(.vots)").mouseover(function(){
       jQuery(this).find("img").attr("src","http://www.btvnoticies.cat/wp-content/plugins/vote-the-post/star-over.gif");
  });
  jQuery("ul._star_rating_ li:not(.vots)").mouseout(function(){
    if (jQuery(this).attr("select")=="0"){
      jQuery(this).find("img").attr("src","http://www.btvnoticies.cat/wp-content/plugins/vote-the-post/star-dim.gif");
    }else{
      jQuery(this).find("img").attr("src","http://www.btvnoticies.cat/wp-content/plugins/vote-the-post/star.gif");
    }
  });
  jQuery("ul._star_rating_ li").click(function(){
     var parentID=jQuery(this).parent().attr("id");
     post_id=parentID.substr(13,parentID.length);
     vote=jQuery(this).attr('rel');
     ratepostVote(post_id, vote);
     //setTimeout("getMediaVotos()",500);
  });
});
