/*jshint asi: false, bitwise: true, boss: false, curly: true, debug: false, devel: false, eqeqeq: true, evil: false, forin: true, immed: true, laxbreak: false, newcap: true, noarg: true, noempty: true, nonew: true, nomen: true, onevar: true, plusplus: true, regexp: false, undef: true, sub: false, strict: true, white: false*/
/*global jQuery, console, baseUrl, window, document */
(function ($) {
	"use strict";
	var tooltip;
	
	tooltip	=	function ($target, options) {
		var $el, methods, settings, content;
		
		settings	=	{
			"className":		"pluginTooltip"
		};
		
		methods		=	{
			"init":			function ( ) {
				if (options) {
					$.extend(true, settings, options);
				}
				
				methods.createTooltip();
				
				$target.bind("mouseover", methods.show);
				$target.bind("mouseout", methods.hide);
				
				return methods;
			},
			"show":			function (e) {
				$el.show();
				methods.setPosition(e);
				$("body").bind("mousemove", methods.follow);
				
				return methods;
			},
			"hide":			function (e) {
				$el.hide();
				methods.setPosition(e);
				$("body").unbind("mousemove", methods.follow);
				
				return methods;
			},
			"follow":		function (e) {
				methods.setPosition(e);
				
				return methods;
			},
			"createTooltip":	function ( ) {
				content	=	$target.attr("data-tooltip-content");
				
				if ($el) {
					$el.remove();
				}
				
				$el	=	$("<div/>").html(content).addClass(settings.className);
				
				if (content) {
					$el.appendTo("body");
				}
				
				return methods;
			},
			"setPosition":		function (e) {
				var x, y;
				
				x	=	e.clientX;
				y	=	e.clientY + parseInt($(window).scrollTop(), 10);
				
				x	+=	10;
				y	+=	10;
				$el.css({
					"top":		y + "px",
					"left":		x + "px"
				});
				
				return methods;
			}
		};
		
		return methods.init();
	};
	
	$.fn.tooltip	=	function (options) {
		this.each(function ( ) {
			var $this	=	$(this);
			$this.data({"tooltip": tooltip($this, options)});
		});
	};
}(jQuery));

