(function($) {

	jQuery.fn.tooltip = function(options){

		 var defaults = {  

		    offsetX: 15,  //X Offset value

		    offsetY: 10,  //Y Offset value
		    fadeIn : 'fast', //Tooltip fadeIn speed, can use, slow, fast, number
		    fadeOut : 'fast',//Tooltip fadeOut speed, can use, slow, fast, number
		    dataAttr : 'data',	//Used when we create seprate div to hold your tooltip data, so plugin search div tage by using id 'data' and current href id on whome the mouse pointer is so if your href id is '_tooltip_1' then the div which hold that tooltips content should have id 'data_tooltip_1', if you change dataAttr from default then you need to build div tag with id 'current dataAttr _tooltip_1' without space

		    bordercolor: '#EEE', // tooltip border color

		    bgcolor: '#F8F8F8', //Tooltip background color

		    fontcolor : '#000', //Tooltip Font color

		    fontsize : '15px', // Tooltip font size

		    folderurl : 'NULL', // Folder url, where the tooltip's content file is placed, needed with forward slash in the last (/), or can be use as http://www.youwebsitename.com/foldername/ also.

		    filetype: 'txt', // tooltip's content files type, can be use html, txt
		    height: 'auto', // Tooltip's width
		    width : 'auto', //Tooltip's Height
		    cursor : 'pointer', // Mouse cursor
			font : 'Trebuchet MS',


		   };  

	var options = $.extend(defaults, options);
	//Runtime div building to hold tooltip data, and make it hidden
	var $tooltip = $('<div id="divToolTip"></div>');

	return this.each(function(){					
    var dialog_id="#divToolTip";
	
			$('body').append($tooltip);
			
			$tooltip.hide();



		var element = this;

		var txt = $(element).attr('txt');


		$(this).hover(function(e){
				
				
						
					
						$("#divToolTip").html(tplTip(txt));

				

				

				//assign css value to div
				$(element).css({'cursor' : options.cursor});
				if($(document).width() / 2 < e.pageX){
					$(dialog_id).css({

						'position' : 'absolute'

						

					});
					//alert(size);
				}else{	

					$(dialog_id).css({

						'position' : 'absolute'

						

					});
//alert(size);
				}
				//enable div block

				$(dialog_id).stop(true, true).fadeIn(options.fadeIn);	

					},function(){

				// when mouse out remove all data from div and make it hidden

				$(dialog_id).stop(true, true).fadeOut(options.fadeOut);	

					}).mousemove(function(e){	

				// to make tooltip moveable with mouse	
				if($(document).width() / 2 < e.pageX){		

				$(dialog_id).css({

					'top' : e.pageY + options.offsetY,

					'left' : e.pageX - $(dialog_id).width(),
					'height' : options.height,
					'width' : options.width

					});
				//$(dialog_id).html(e.pageX - $(dialog_id).width());
				}else{
					$(dialog_id).css({

					'top' : e.pageY + options.offsetY,

					'left' : e.pageX + options.offsetX,
					'height' : options.height,
					'width' : options.width

					});
				}

			});

		});

	};

function tplTip(txt){
		var tpl ='<table  border="0" cellspacing="0">  <tr>    <td height="45" background="/images/left_tooltip.png" width="10"></td>    <td  align="center" background="/images/mid_tooltip.png" style="padding-top:5px; color:#FFF; font-family:\'Trebuchet MS\', Arial, Helvetica, sans-serif; font-size:16px;">'+txt+'</td>    <td width="32" background="/images/right_tooltip.png"></td>  </tr></table>';
		return tpl;
	}

 })(jQuery);
