//NOTICE: 	Increasing the fade values below will increase probability of an animation bug in the coloring
//			script; where the color will not return to its original state unless the mouse is hovered 
//			over the element again. There is no check for if "isNan()" as this can occur and causes color
//			animation to stop mid-change. Roll mouse over to refresh color.
//			
//This script requires the "jquery color animation" script
//
// @param  	  fadeInTime  	Value in milliseconds	 ||   Value with default value 1000 (milliseconds)
// @param  	  fadeOutTime   Value in milliseconds    ||   Value with default value  600 (milliseconds)
// @param	  fadeToColor	Hex/%%%/RGB color value  ||	  Default hex value of #ffff00
// @author    Travis Mayne <mayne92@gmail.com>

(function($){
    $.fn.colorAnim = function(options) {

		var thisE = this;

		//On first run, thisE/this may be a laundry-list of elements to one thisE/this
        if ( thisE.length > 1){
			//For each item in this/this, pass each element ($(this)) through colorNavAnim with the options as parameter.
			//  In that case, thisE/this.length will be zero and this is bypassed the 2nd time around.
            thisE.each(function() { $(this).colorAnim(options) });
            return thisE;
        }

		//Default settings if nothing passed through options
		var defaults = {
            fadeInTime: 1000,
		    fadeOutTime: 600,
			fadeToColor: '#ffff00'
        };
		
		//Merge options values and defaults
		$.extend(defaults, options);

		//Bind each thisE/this/Element with the mouseenter/mouseleave function
		thisE.bind({

			mouseenter : function () {
			
				if( !thisE.data('color') ) {
					thisE.data('color',thisE.css('color'));
				}

				thisE.stop(true, true).animate({'color': options.fadeToColor}, options.fadeInTime );
					
			},
			mouseleave : function () {

				thisE.stop(true, true).animate({'color' : thisE.data('color')}, options.fadeOutTime, function () {
					thisE.css({'color' : thisE.data('color') });
				});
			}
		});
	};
})(jQuery);
