$(function(){

$.highlighter = {
  init: function(){
    $('td.fn-person').hover($.highlighter.markSimilar,$.highlighter.unmark);
    $('td.fn-price').hover($.highlighter.markUpDown,$.highlighter.unmark);
  },
  markUpDown: function(){
    var price = parseInt($(this).text());
    var up = null;
    var down = null;
    $('td.fn-price').each(
      function(){
	var current = parseInt($(this).text());
        if(current>price && (up==null || current<up))
          up = current;
        if(current<price && (down==null || current>down))
          down = current;
      }
    );
    $('tr .fn-popup').hide();
    if(down!=null)
      $('td.fn-price:contains('+down.toString()+')').each(
        function(){
          if ($(this).text()==down.toString()){
            $(this).parents('tr').find('td').addClass('highlightGreen');
            $('.fn-popupDown', $(this).parents('tr')).show().delay(3000).fadeOut();
          }
        }
      );
    if(up!=null) 
      $('td.fn-price:contains('+up.toString()+')').each(
        function(){
          if ($(this).text()==up.toString()){
            $(this).parents('tr').find('td').addClass('highlightRed');
            $('.fn-popupUp', $(this).parents('tr')).show().delay(3000).fadeOut();
          }
        }
      );
  },
  markSimilar: function(){
    $('td.fn-person:contains('+$(this).text()+')').parents('tr').find('td').addClass('highlight');
  },
  unmark: function(){
    $('td').removeClass('highlight highlightGreen highlightRed');
    $('tr .fn-popup').hide();
  }
}
$.thumb = {
  init: function(){
    $('.fn-hasThumbnail').hover( $.thumb.show, $.thumb.hide );
  },
  show: function(){
    $('.fn-details', this).show();
  },
  hide: function(){
    $('.fn-details', this).hide();
  }
}
$.highlighter.init();
$.thumb.init();
	
});
