/**
Custom Tooltip plugin
Author: Anand Kulkarni
*/
if(typeof jQuery != 'undefined') {
	jQuery(function($) {
		$.fn.extend({
			ttip: function(options) {
				var settings = $.extend({}, $.fn.ttip.defaults, options);
			
				return this.each(
					function() {
						// Only compatible with jQuery v1.2.6 +
						if($.fn.jquery < '1.2.6') {return;}
						
						
						var $this = $(this);
						var o = $.metadata ? $.extend({}, settings, $this.metadata()) : settings;
						
						/**
						* Tooltip plugin starts here..
						*/
						
						$popup = $this.find(".popup");
						
						var isIE6 = 
							(!$.support.cssFloat && !$.support.opacity && $.browser.msie && $.browser.version <= 6) && 
							((/(MSIE 6\.0)/igm.test(navigator.userAgent)) && 
							!(/(MSIE 7\.0)/igm.test(navigator.userAgent)) && 
							!(/(MSIE 8\.0)/igm.test(navigator.userAgent)));
						
						if(isIE6)
						{
							$this.attr("title",$popup.text());
							return;
						}
						
						$popup.css({
							"opacity": 0,
							"top":-($(this).height())+"px",
							"color":o["color"],
							"padding":"5px",
							"background-color":o["background-color"],
							"-webkit-border-radius": o["border-radius"],
							"-moz-border-radius": o["border-radius"],
							"border-radius": o["border-radius"],
							"white-space":"nowrap"
						});
						
						$popuparrow = $("<em>");
						$popuparrow.css({
							"opacity":0,
							"border-color": o["background-color"] +" transparent transparent transparent",
							"border-style":"solid",
							"border-width":"5px",
							"width":0,
							"height":0,
							"position":"absolute",
							"bottom":"-10px",
							"display":"inline-block",
							"_border-left-color": "pink",
							"_border-bottom-color": "pink",
							"_border-right-color": "pink",
							"_filter": "chroma(color=pink)"
						}).appendTo($popup);
		
						$this.hover(
							function(e)
							{
								e.preventDefault();
								
								$popup = $this.find(".popup");
								$popupwidth = parseInt($popup.outerWidth());
								$popupheight = parseInt($popup.height());
								
								
								$popuparrow = $popup.find("em");
								$popuparrow.css({
									"left":""+(($popupwidth/2))+"px"	  
								});
								if(o.showarrow)
								{
									$popuparrow.stop().animate({
										"opacity":1
									}, o.delay);
								}
								else
								{
									$popuparrow.hide();
								}
								
								$popup
									.css({
										"left":-(($popupwidth/2)-($this.width()/2))+"px",
										"top":"-"+ (1.5 * $popupheight) + "px",
										"display":"block"
									})
									.stop().animate({
										"opacity":1,
										"top":"-"+ (2 * $popupheight) + "px"
									}, o.delay);
							},
							function(e)
							{
								e.preventDefault();
								
								$popup = $this.find(".popup");
								$popupwidth = parseInt($popup.outerWidth());
								$popupheight = parseInt($popup.height());
								
								
								$popuparrow = $popup.find("em");
								$popuparrow.css({
									"left":""+(($popupwidth/2))+"px"	   
								});
								
								if(o.showarrow)
								{
									$popuparrow.stop().animate({
										"opacity":0
									}, o.delay);
								}
								else
								{
									$popuparrow.hide();
								}
								
								$popup
									.css({
										"left":-(($popupwidth/2)-($this.width()/2))+"px",
										"top":"-"+ (2 * $popupheight) + "px",
										"display":"block"
									})
									.stop().animate({
										"opacity":0,
										"top":"-"+ (2.5 * $popupheight) + "px"
									}, o.delay);
							}
						);
					}
				);
			}
		});
		
		/**
		* Tooltip plugin defaults
		*/
		$.fn.ttip.defaults = {
			"delay":"fast",
			"showarrow":true,
			"color":"white",
			"background-color":"black",
			"border-radius":"5px"
		};
	});
}
