/*
 * 	Easy Tooltip 1.0 - jQuery plugin
 *	written by Alen Grakalic
 *	http://cssglobe.com/post/4380/easy-tooltip--jquery-plugin
 *
 *	Copyright (c) 2009 Alen Grakalic (http://cssglobe.com)
 *	Dual licensed under the MIT (MIT-LICENSE.txt)
 *	and GPL (GPL-LICENSE.txt) licenses.
 *
 *	Built for jQuery library
 *	http://jquery.com
 *
 */

(function($) {

    $.fn.easyTooltip = function(options) {

        // default configuration properties
        var defaults = {
            xOffset: "41%",
            yOffset: 100,
            tooltipId: "easyTooltip",
            clickRemove: false,
            content: "",
            useElement: ""
        };

        var options = $.extend(defaults, options);
        var content;

        this.each(function() {
            var title = $(this).attr("title");
            $(this).hover(function(e) {

                $("#" + options.tooltipId).remove();
                $(".resultBox").css("background", "#ffffff")
                $(this).attr("title", title);
				$("#" + options.tooltipId).remove();
				$(".resultBox").css('border','none')
				$(this).attr("title", title);
				$("#" + options.tooltipId).remove();
				$(".resultBox").css('padding','none')
				$(this).attr("title", title);

                content = (options.content != "") ? options.content : title;
                content = (options.useElement != "") ? $("#" + options.useElement).html() : content;
                $(this).attr("title", "");
                if (content != "" && content != undefined) {
                    $("body").append("<div id='" + options.tooltipId + "'>" + content + "</div>");

                    /*
                    $("#" + options.tooltipId)
                    .css("position","absolute")
                    .css("top",(e.pageY - options.yOffset) + "px")
                    .css("left",(e.pageX + options.xOffset) + "px")
                    .css("display","none")
                    .fadeIn("fast")
                    ;
                                                
                    */
					
                    $("#" + options.tooltipId)
                    .css("position","absolute")
                    .css("top",(e.pageY - options.yOffset) + "px")
                    .css("left", options.xOffset)
                    .css("display","none")
                    .fadeIn("fast")
                    ;
                                                
                    
                   /* $("#" + options.tooltipId)
						.css("position", "absolute")
						.css("top", "30%")
						.css("left", "41%")
						.css("display", "none")
						.fadeIn("fast");*/

                    $(this).mousemove(function(e) {
                        $("#" + options.tooltipId)
					.css("top", (e.pageY - options.yOffset) + "px")
                        //alert('d' + e.pageY)
                        //alert($(window).height())
                        //.css("left", (e.pageX + options.xOffset) + "px")
                    });
                    if (options.clickRemove) {
                        $(this).mousedown(function(e) {
                            $("#" + options.tooltipId).remove();
                            $(this).attr("title", title);
                        });
                    }

                    $(this).parent().parent().css("background", "#cfe2fe")
					 $(this).parent().parent().css('border','1px solid #b1c4e0');
					 $(this).parent().parent().css('padding','2px 0px 2px 5px');
                }
            },
			function() {

			});


        });

    };

})(jQuery);

