(function($) {
    
  /**
   * fhHover
   * Copyright (c) 2010 Freshheads
   *
   
   *
   * Authors: Gijs van Zon MA
   * Return: Object (this)
   * Params:
   *   hoverClassName: String ('fhHover-active')
   */
   
  $.fn.fhHover = function(o)
  {
    return this.each(function()
    {
      new $fhh(this, o);
    });
  };
  
  // Default configuration properties.
  var defaults =
  {
    activeClassname: 'fhHover-active',
    mouseoverCallback: null,
    mouseoutCallback: null,
    initCallback: null
  };
  
  $.fhHover = function(e, o)
  {
  
    this.options = $.extend({}, defaults, o || {});
    this.element = $(e);
    
    var self = this;
    
    /* Get sub-links and disable the block click when they are hovered */
    this.element.find('a, input, label').bind('click', function(e){
      e.stopPropagation();
    });
    
    /* Set mouseover class to element */
    this.element
      .bind({
        mouseover: function(e)
        {
          $(this)
            .addClass(self.options.activeClassname)
            .css({
              'cursor': 'pointer'
            });
    
          if(self.options.mouseoverCallback != null)
          {
            self.options.mouseoverCallback(this);
          };
        },
        mouseout: function(e)
        {
          $(this).removeClass(self.options.activeClassname);
    
          if(self.options.mouseoutCallback != null)
          {
            self.options.mouseoutCallback(this);
          };
        },
        click: function(e)
        {
          e.preventDefault();
              
          /* Check if target is given */
          var link = $(this).find('a[rel*=fhhLocation]');
          if(link.length == 1)
          {
            /* Check whether or not to open te url in a new window */
            if(link.attr('target') == '_blank')
            {
              window.open(link.attr('href'));
            }
            else
            {
              window.location = link.attr('href');
            };
          }
          else
          {
            throw('There are no or multiple fhhLocation url\'s found within the clicked element');
          };
        }
      });
    
    // If a initCallback function is given the element is return on init
    if(this.options.initCallback != null)
    {
      this.options.initCallback(this);
    }
  };

  // Create shortcut for internal use
  var $fhh = $.fhHover;

  $fhh.fn = $fhh.prototype =
  {
    version: '2.0',
    author: 'Gijs van Zon MA',
    requirements: 'jQuery 1.4'
  };
  
})(jQuery);
