/* 
* MyTip 1
* Version 1.0
* Autor : Cabcom13.de (www.Cabcom13.de)
*
* Licensed under GPL <http://en.wikipedia.org/wiki/GNU_General_Public_License>
* Copyright (c) 2010, Cabcom13.de <Cabcom13@aol.com>
* All rights reserved.
*
This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

(function(jQuery){
	jQuery.fn.mytip = function(options) {
                        var settings = {
                                speed: 'slow',
                                tooltipcontainer: '#tooltip',
                                tooltip_title: this.attr('res'),
                                tooltip_content: this.attr('rel'),
                                tooltip_content_val: '',
                                opacity: '.9',
                                use_special_content: false
                        };
                                
			return this.each(function () {

                                if(options) {
                                        jQuery.extend(settings, options);
                                }


		$(this).bind({
			mouseenter: function(e){
                                $(settings.tooltipcontainer).data('timeout', setTimeout( function () {
                                   $(settings.tooltipcontainer).fadeIn(settings.speed, function() {});
                                  }, 200));
			},
			mouseleave: function(){
                                clearTimeout($(settings.tooltipcontainer).data('timeout'));

				$(settings.tooltipcontainer).css({  display: 'none' });
			},
			mousemove: function(e){
				 var mousex = e.pageX + 10;
                                     var mousey = e.pageY + 5;

                                     var test = settings.tooltip_content;
                                     if(options.tooltip_content_val) {
                                         var content = $(this).find(settings.tooltip_content_val).html();
                                     } else {
                                         var content = settings.tooltip_content;
                                     }

                                     var title = settings.tooltip_title;
                                     if(title){
                                         var title_html = '<div class="title">'+title+'</div>';
                                     } else {
                                         var title_html = '';
                                     }


                                    if(settings.use_special_content){
                                          var obj = jQuery.parseJSON($(this).attr('id'));   
                                          var data = '';
                                             $.each(obj, function(i, object) {
                                                    data += '<li class="'+obj[i].status+'">'+ obj[i].name + ' ' + obj[i].status_txt +'<\/li>';                                  
                                            });
                                          
                                          $(settings.tooltipcontainer).html(
                                                  '<ul>'+data+'<\/ul>'               
                                            ).css({ opacity: settings.opacity ,top: mousey, left: mousex });
                                    } else {
                                         $(settings.tooltipcontainer).html(
                                         title_html +
                                         '<div class="content">'+content+'</div>'

                                            ).css({ opacity: settings.opacity ,top: mousey, left: mousex });
                                    }                 
			}
		});

			});


	};
})(jQuery);
