/*
 * jQuery Tooltip Expander plugin
 * Version 0.1  (23/02/2009)
 * @requires jQuery v1.1.1+
 *
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */


(function($) {

  $.fn.tooltipExpander = function(options) {

    var opts = $.extend({}, $.fn.tooltipExpander.defaults, options);
    return this.each(function() {
      var $this = $(this);
		var o = $.meta ? $.extend({}, opts, $this.data()) : opts;
		$this.hellip({limit: o.slicePoint});
        
        $this.parents('li:eq(0)').find('a').each(function() {
        	if (!$(this).children().length) {
        		$(this).hellip({limit: 40, title: false});
        	}
        });
        var product = $this.parents('li:eq(0)').find('span.product').text();
        var description = $this.attr('title');
        $this.removeAttr('title');
        var author = $this.parents('li:eq(0)').find('span.author').text();
        
        if (o.parentTag != null) {
          $this = $this.parents(o.parentTag + ':eq(0)');
        };
     	$this.hover(function(e) {
		  $('body').append('<p id="tooltipExpander"></p>');
		  $('#tooltipExpander').html('<p><strong>' + product + '</strong></p><p>' + description + '</p><br /><p>Autor: <strong>' + author + '</strong></p>');
		  $('#tooltipExpander').css('top', (e.pageY - o.offsetX) + 'px').css('left', (e.pageX + o.offsetY) + 'px').fadeIn('fast');						
        }, function() {
		  $('#tooltipExpander').remove();
        }).mousemove(function(e) {
          $('#tooltipExpander').css('top', (e.pageY - o.offsetX) + 'px').css('left', (e.pageX + o.offsetY) + 'px');
	    });
    });
  };

  $.fn.tooltipExpander.defaults = {
    slicePoint: 100,
    widow: 4,
    expandText: '&hellip;',
    offsetX: 10,
    offsetY: 30,
    parentTag: null
  };
})(jQuery);
