$(function(){
  $(".rateclick").bind('click', function(){
    var button = this.id.substr(1).split('v');
    var rateButton = $(this).parents(".ratingButton-active");
    var postvars = {};
    postvars.ajax = true;
    //postvars.note = button[0];
    postvars.rating = button[1];
    //postvars.article = $(".ratingButton-active a.ratingButton").attr('id').substr(2);
    postvars.note = $(rateButton).attr('id').substr(2);
    clearTimeout(RATING_MENU_TIMER);
		$(".ratingButton div").appendTo("#rating-options");
    //$(".ratingButton-active").replaceWith('<p id="ar'+postvars.article+'"><img src="'+document.base_url+'images/ajax-rating.gif" style="float:right;" /></p>');
    
    $(rateButton).css("width", $(rateButton).width() + "px");
    $(rateButton).html("&nbsp;");
    $(rateButton).addClass("wait");
    $(rateButton).unbind();
    /*
    $.post(url+'groupyit/rate_note/', postvars, function(data) {
      var id = $(data).attr('id');
      //$("#"+id).replaceWith(data);
      $(rateButton).html(data);
    	$(rateButton).css("width","auto");
	    $(rateButton).removeClass("wait");
	    $(rateButton).parent().addClass("ratingButtonVoted");
    });
		*/
		$.post(url+"groupyit/rate_note", postvars, 
				function(data){	
					if(data!=0) {
						/*
						$('#actrating').html(data);
						$('#opsirating').hide();
						*/
						window.location.reload();
					} 
				});
  });
  $("body").append('<img src="'+url+'images/loading_circle.gif" style="display:none;" />');
});

var RATING_MENU_ACTIVE;
var RATING_MENU_TIMER;

$("document").ready(function() {
	
	/* RATING BUTTON */
	$(".ratingButton a").hover(
		function(){
			RATING_MENU_ACTIVE = this;
			RATING_MENU_TIMER = setTimeout(function(){
				$("#rating-options div").appendTo(RATING_MENU_ACTIVE);
				$(RATING_MENU_ACTIVE).addClass("ratingButton-active");
			}
			, 100 )
		},
		function(){
			clearTimeout(RATING_MENU_TIMER);
			$(".ratingButton div").appendTo("#rating-options");
			$(this).removeClass("ratingButton-active");
		}
	);
	
	/* END RATING BUTTON */

	
});
