(function($){
  $.fn.highlight_linked_cells = function(options){
    var options = $.extend({}, $.fn.highlight_linked_cells.defaults, options || {});
    return this.each(function(){
      var table = $(this);
      var cells = table.find('td[class^='+options.prefix+']');
      cells.each(function(){
        var cell = $(this);
        var cell_class = cell.attr('class');
        var links = table.find('.'+cell_class);
        cell.hover(
          function(){ if(links.length > 1) links.addClass(options.class);       },
          function(){ table.find('.'+options.class).removeClass(options.class); }
        );
      });
    });
  };
  $.fn.highlight_linked_cells.defaults = {
    prefix: 'id',
    class: 'highlight'
  };
  
  $(document).ready(function(){
    //$('.widget li')
    //  .click(function(){
    //    var self = $(this);
    //    var t = self.parents('table');
    //    var c = self.attr('class');
    //    if(self.data('active')){
    //      t.find('li').css({opacity: 1}).data('active', false);
    //    }
    //    else {
    //      t.find('li.'+c).css({opacity: 1}).data('active', true);
    //      t.find('li:not(.'+c+')').css({opacity: 0.2}).data('active', false);
    //    }
    //    console.log($(this).data('active'));
    //    return false;
    //  })
    //  .hover(
    //    function(){
    //      $(this).css({cursor: 'pointer'});
    //    },
    //    function(){
    //      $(this).css({cursor: 'default'});
    //    }
    //  )
    //;
    $('#top_users_widget, #top_players_widget').highlight_linked_cells();
    
    // $('.container .help_image').each(function(){
    //   var self = $(this);
    //   var link = self.find('a:eq(0)');
    //   var img = self.find('img.content');
    //   var width = parseInt(img.attr('width'));
    //   link.qtip({
    //     content: {
    //       text: img.outerHtml(),
    //       prerender: true
    //     },
    //     position: {
    //       corner: {
    //          tooltip: 'topRight',
    //          target: 'bottomLeft'
    //       }
    //     },
    //     style: {
    //       tip: true,
    //       textAlign: 'center',
    //       padding: '1px',
    //       name: 'dark'
    //     }
    //   });
    //   link.qtip('api').elements.wrapper.css({width: (width+10)});
    // });
    
    
  });
})(jQuery);