jQuery(document).ready(function(){
 starRating.create('.stars');
 commentRating.create('.comment-karma');
});

var starRating = {
  create: function(selector) {
    jQuery(selector).each(function() {
        var $list = jQuery('<div></div>');
		jQuery(this)
		.find('input:radio')
		.each(function(i) {
		  var rating = jQuery(this).attr('id');
		  var $item = jQuery('<a href="#"></a>')
			.attr('title', rating)
			.text(rating);
		  
		  starRating.addHandlers($item);
		  $list.append($item);
		  if (jQuery(this).is(':checked')) {
			$item.prevAll().andSelf().addClass('rating');
		  }
		});
		var $item = jQuery('<a href="#"></a>')
			.attr('title', jQuery(selector).attr('id'))
			.text('rating')
			.addClass('drop');
		starRating.addHandlersDrop($item);
		$list.prepend($item);
		jQuery(this).append($list).find('input:radio').hide();
    });
  },

  addHandlers: function(item) {
    jQuery(item).click(function(link) {
      var $star = jQuery(this);
      var $allLinks = jQuery(this).parent();
        $allLinks
        .parent()
        .find('input#' + $star.text() +':radio')
        .attr('checked', true);
        
      $allLinks.children().removeClass('rating');
      $star.prevAll().andSelf().addClass('rating');
            
      link.preventDefault();
    })
    .hover(function() {
      jQuery(this).prevAll().andSelf().addClass('rating-over');
    },function() {
      jQuery(this).siblings().andSelf().removeClass('rating-over');
    });
  },
  
   addHandlersDrop: function(item) {
    jQuery(item).click(function(link) {
      var $star = jQuery(this);
      var $allLinks = jQuery(this).parent();
        $allLinks
        .parent()
        .find('input:radio')
        .attr('checked', false);
        
     
      $star.nextAll().removeClass('rating');
    
      link.preventDefault();
    });
  }
  

}

var commentRating = {
  create: function(selector) {
    jQuery(selector).each(function() {
        jQuery(this)
		.find('a')
		.each(function(i) {
		commentRating.addHandlers(this);
		});
	});
  },

  
  
  addHandlers: function(item) {
  jQuery(item).addClass('processed');
    jQuery(item).click(function(link) {
	
		jQuery.ajax({
			method: "get",url: "/aj/recieve-firm-comment-karma",data: "comment_id=1&rating=",
			success: function(html){ //so, if data is retrieved, store it in html
			jQuery(item).parent().parent().replaceWith(html);
			}
		}); //close $.ajax(
      link.preventDefault();
    })
  }
  


}

/*

<script>
02.  // When the document loads do everything inside here ...
03.     $(document).ready(function(){
04.     $('.content').load('boo.php'); //by default initally load text from boo.php
05.         $('#menu a').click(function() { //start function when any link is clicked
06.                        $(".content").slideUp("slow");
07.                         var content_show = $(this).attr("title"); //retrieve title of link so we can compare with php file
08.                            $.ajax({
09.                            method: "get",url: "boo.php",data: "page="+content_show,
10.                            beforeSend: function(){$("#loading").show("fast");}, //show loading just when link is clicked
11.                            complete: function(){ $("#loading").hide("fast");}, //stop showing loading when the process is complete
12.                            success: function(html){ //so, if data is retrieved, store it in html
13.                            $(".content").show("slow"); //animation
14.                            $(".content").html(html); //show the html inside .content div
15.                     }
16.                 }); //close $.ajax(
17.         }); //close click(
18.     }); //close $(
19.</script>
*/