(function($) {
   $.fn.tooltip = function(settings) {
     config = { 
       'dialog_content_selector' : 'div.tooltip_description',
       'opacity' : 0.95,
       'arrow_left_offset' : 70,
       'arrow_top_offset' : 110,
       'arrow_height' : 20,
       'arrow_width' : 20,
       'animation_duration_ms' : 500,
	   'hide_on_mouseout' : true
     }; 
     if (settings) $.extend(config, settings);
     this.each(function() {
       $(this).hover(function(){
         _show(this);
       },function(){
         if(config.hide_on_mouseout==true)
		 {
		 	_hide(this);
		 }else{
			this.find(config.dialog_content_selector+' span.close').click(function(e){
				e.preventDefault();
				_hide(this);
			}); 
		 }
       });
    });
    function _show(target_elm)
	{
		var dialog_content = $(target_elm).find(config.dialog_content_selector);
		var dialog_box = _create(dialog_content);
		var position;
		var target_elm_position = $(target_elm).offset();
	   
		position = { 
			end : {
				left : target_elm_position.left + $(target_elm).outerWidth(),
				top  : target_elm_position.top + ($(target_elm).outerHeight() / 2) + config.arrow_top_offset - $(dialog_box).outerHeight() + config.arrow_height
			},
			arrow_class : "div.left_arrow"
		}
		$(dialog_box).find("div.left_arrow").css({ top: $(dialog_box).outerHeight() - (config.arrow_top_offset * 2) + "px" });
		$(dialog_box).css({ 
			top : position.end.top + "px", 
			left : position.end.left + "px", 
			opacity : config.opacity
		}).fadeIn();       
		$(dialog_box).find("div.arrow").hide();
		$(dialog_box).find(position.arrow_class).show();
    };
    function _hide(target_elm) {
    	$("body").find("div.jquery-gdakram-tooltip").stop().remove();
    };
	function _create(content_elm) {
       var header = ($(content_elm).attr("title")) ? "<h4>" + $(content_elm).attr("title") + "</h4>" : '';
       return $("<div class='jquery-gdakram-tooltip'>\
         <div class='up_arrow arrow'></div>\
         <div class='left_arrow arrow'></div>\
         <div class='content'>" + header + $(content_elm).html() + "</div>\
         <div style='clear:both'></div>\
         <div class='down_arrow arrow'></div>\
       </div>").appendTo('body');
     };
     return this; 
   };  
})(jQuery);
