/*
 * 	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
 *
 */
var myWidth = 0;

if( typeof( window.innerWidth ) == 'number' ) {
myWidth = window.innerWidth;
myHeight = window.innerHeight;
}else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)){
myWidth = document.documentElement.clientWidth;
myHeight = document.documentElement.clientHeight;
}else if(document.body && (document.body.clientWidth || document.body.clientHeight)){
myWidth = document.body.clientWidth;
myHeight = document.body.clientHeight;
}
 
(function($) {

	$.fn.tntip = function(options){
	  
		var defaults = {	
			xOffset: 0,		
			yOffset: 0,
			tooltipId: "easyTooltip",
			clickRemove: false,
			content: "",content2: "",
			useElement: ""
		}; 
			
		var options = $.extend(defaults, options);  
		var content,content2;
				
		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;
				
				content2 = (options.content2 != "") ? options.content2 : rel;
				
				content2 = (options.useElement != "") ? $("#" + options.useElement).html() : content2;
				
				$(this).attr("title","");					
				
				if (content != "" && content != undefined){		
				
				if (content2 != "" && content2 != undefined){
				
					$("body").append("<div id='"+ options.tooltipId +"'><img src='http://www.sisustuspood.ee/thumb.php?src="+ content +"&x=340&f=0' border='0'>"+ content2 +"</div>");		
					 }else{
					 $("body").append("<div id='"+ options.tooltipId +"'><img src='http://www.sisustuspood.ee/thumb.php?src="+ content +"&x=340&f=0' border='0'></div>");		
					
					 }
					 
					
					var elewidth = $("#" + options.tooltipId).outerWidth();
				
				    var offsetLeftNewFinal = e.pageX + options.xOffset - elewidth - 10;
				
				    var eleheight = $("#" + options.tooltipId).outerHeight() / 2;
					
					var offsetTopNewFinal = e.pageY + options.yOffset - eleheight;
					
					 
				    
					 
				    $("#" + options.tooltipId)
					
					.css("position","absolute")
					
					.css("top",(offsetTopNewFinal) + "px")
					
					.css("left",(offsetLeftNewFinal) + "px")
					
					.css("display","none")
					
					.fadeIn("fast")
					
				    
				}
			},
			function(e){	
			
				$("#" + options.tooltipId).remove();
				
				$(this).attr("title",title);
				
				var elewidth = $("#" + options.tooltipId).outerWidth();
				
				var offsetLeftNewFinal = e.pageX + options.xOffset - elewidth - 10;
				
				 var eleheight = $("#" + options.tooltipId).outerHeight() / 2;
					var offsetTopNewFinal = e.pageY + options.yOffset - eleheight;
				
			    $("#" + options.tooltipId)
				
				.css("top",(offsetTopNewFinal) + "px")
				
				.css("left",(offsetLeftNewFinal) + "px")	
				
				 
				
			    });	
				
			    $(this).mousemove(function(e){
				 
				var elewidth = $("#" + options.tooltipId).outerWidth();
				
				var offsetLeftNewFinal = e.pageX + options.xOffset - elewidth - 10;
				
				var eleheight = $("#" + options.tooltipId).outerHeight() / 2;
				
				var offsetTopNewFinal = e.pageY + options.yOffset - eleheight; 
				
			    $("#" + options.tooltipId)
				
				.css("top",(offsetTopNewFinal) + "px")
				
				.css("left",(offsetLeftNewFinal) + "px")	
				
			});	
			if(options.clickRemove){
			
				$(this).mousedown(function(e){
				
					$("#" + options.tooltipId).remove();
					
					$(this).attr("title",title);
					
				});				
			}
		});
	  
	};

})(jQuery);

