/*

 * DC Tooltip - jQuery tooltip plugin
 * Copyright (c) 2011 Design Chemical
 *
 * Dual licensed under the MIT and GPL licenses:
 * 	http://www.opensource.org/licenses/mit-license.php
 * 	http://www.gnu.org/licenses/gpl.html
 *
 */

(function($){

	//define the new for the plugin ans how to call it
	$.fn.dcTooltip = function(options) {

		//set default options
		var defaults = {
			classWrapper	: 'tooltip',
			hoverDelay		: 0,
			speed       	: 0,
			distance		: 10,
			padLeft			: 0
		};

		//call in the default otions
		var options = $.extend(defaults, options);

		return this.each(function(options){

			var $tooltip = $('.'+defaults.classWrapper,this);
			$('.start',$tooltip).each(function(){
				var text = $(this).text();
				$(this).text('Started: '+text);
			});
			$(this).css('position','relative');
			$tooltip.css('opacity',1);
			
			 $(this).hover(
          function(){
			$tooltip.show().css({
					marginBottom: -margin/2+'px',
					opacity: 1,
					zIndex: 51
                }).animate({
                   marginBottom: 0
                }, defaults.speed);
		  },
          function(){
			$('.'+defaults.classWrapper,this).css({
					zIndex: 50
                }).animate({
                    marginBottom: margin+'px',
                    opacity: 0
			    }, defaults.speed, function() {
					$(this).hide();
				});
		  
		  });

			var margin = defaults.distance
			// Hover link over
			function linkOver(){

				$tooltip.show().css({
					marginBottom: -margin/2+'px',
					opacity: 1
                }).animate({
                   marginBottom: 0
                }, defaults.speed);
			}
			
			// Hover link over
			function linkOut(){
				
				$('.'+defaults.classWrapper,this).animate({
                    marginBottom: margin+'px',
                    opacity: 0
			    }, defaults.speed, function() {
					$(this).hide();
				});

			}
		});
	};
})(jQuery);
