/*
* Tooltip script
* powered by jQuery (http://www.jquery.com)
* inspired by Alen Grakalic http://cssglobe.com
* for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
* modified by me (for option rel -> external ajax-load ....) ;-)
*/
(function($) {
    $.fn.easyTooltip = function(options){
        // default configuration properties
        var defaults = {
            xOffset: 10,
            yOffset: 25,
            tooltipId: "tooltip23",
            clickRemove: false,
            content: "",
            useElement: ""
        };
        var options = $.extend(defaults, options);
        var content;
        this.each(function() {
            var title = $(this).attr("title");
            var rel = $(this).attr("rel");
            $(this).hover(function(e){
                content = (options.content != "") ? options.content : title;
                content = (options.useElement != "") ? $("#" + options.useElement).html() : content;
                $(this).attr("title","");
                $(this).attr("alt","");
                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");
                }
                else if(rel != ""){
                    $("body").append("<div id='"+ options.tooltipId +"'>...</div>");
                    if($(this).attr('class')=='steinansichten'){ //fuer die Steinansicten
                        $("#" + options.tooltipId)
                        .css("top",(e.pageY - options.xOffset) + "px")
                        .css("left",(e.pageX + options.yOffset) + "px")
                        .css("padding","0px 0px")
                        .css("width","120px")
                        .css({
                            'background':'#ffffff',
                            'color':'#999999',
                            'border':'1px solid #000000'
                        })
                        .fadeIn("fast");
                    }
                    else{
                        $("#" + options.tooltipId)
                        .css("top",(e.pageY - options.xOffset) + "px")
                        .css("left",(e.pageX + options.yOffset) + "px")
                        .css("padding","12px 24px")
                        .css({
                            'background':'#ffffff',
                            'color':'#999999',
                            'border':'1px solid #a4a4a4'
                        })
                        .fadeIn("fast");
                    }//end else, wenn NICHT stein
                    var inhalttool='';
                    $.ajax({
                        url: '/konfigurator/tooltip.php',
                        type: 'POST',
                        data:{
                            frage:rel
                        },
                        dataType: 'html',
                        error: function(){
                            //alert('Fehler beim Laden ...');
                            return false;
                        },
                        success: function(data){
                            inhalttool=data;
                        },
                        complete: function(){
                            $('#tooltip23').html(inhalttool);
                        }//end complete function
                    });//end ajax
                /*
*/
                }//end else if fuer externen load
            },
            function(){
                $("#" + options.tooltipId).remove();
                $(this).attr("title",title);
            });
            $(this).mousemove(function(e){
                $("#" + options.tooltipId)
                .css("top",(e.pageY - options.yOffset) + "px")
                .css("left",(e.pageX + options.xOffset) + "px")
            });
            if(options.clickRemove){
                $(this).mousedown(function(e){
                    $("#" + options.tooltipId).remove();
                    $(this).attr("title",title);
                });
            }
        });
    };
})(jQuery);

