/*
 * jQuery Animated Underline Plugin v1.0
 * http://cavaliere.org/sandbox/jquery_animated_underline_plugin
 *
 * Copyright (c) 2009 Mike Cavaliere
 * Licensed under the GNU Public License (GPL).
 */

/*jslint browser: true*/
/*global $, jQuery */

$.fn.underline = function(params)
{
  return this.each(function()
  {
    var $this = $(this),
    
        defaults = {
            color: '#000000',
            width: 1,
            duration: 500
        },
        
        options   = $.extend({}, defaults, params),
        running   = false,
        underline = $('<span class="jquery-underline"></span>');

        $this
          .addClass('jquery-underline-container')
         
          .append( underline );

        underline.addClass('jquery-underline')
                 .css({
                        'border-bottom': options.width + 'px solid '+options.color,
                        opacity: 0,
                        width:  $this.width() + 'px'
                     });

       // Peekaboo fix for ie6
       if ($.browser.ie6)
       {
         underline.css({
          height: '1%'
         });
       }

    var callback = function( ) { running = false; };

    $(this).hover(function()
    {    	
      if (underline.queue().length < 2)
      {
        underline.animate({ opacity: 1.0 }, {duration: options.duration});
      }
    }, 
    function()
    {
        underline.animate({ opacity: 0 }, {duration: options.duration} );
    });
  });
};
