/*-------------------------------------------------------------------------------
	A Better jQuery Tooltip
	Version 1.0
	By Jon Cazier
	jon@3nhanced.com
	01.22.08
-------------------------------------------------------------------------------*/

$.fn.betterTooltip = function(options){
	
	/* Setup the options for the tooltip that can be 
	   accessed from outside the plugin              */
	var defaults = {
		/* speed: 200,
		delay: 1000 */
	};
	
	var options = $.extend(defaults, options);
	
	/* Create a function that builds the tooltip 
	   markup. Then, prepend the tooltip to the body */
	getTip = function() {
		var tTip = 
			"<div class='tip'>" +
				"<div class='tipMid'>"	+
				"</div>" +
				"<div class='tipBtm'></div>" +
			"</div>";
		return tTip;
	}
	//$("body").prepend(getTip());
	$("#forex_tooltip").prepend(getTip());
	var default_title = $('.tTip:first').attr('title');
	
	var offset_default = $(this).offset();
	var tLeft_default = offset_default.left;
	var tTop_default = offset_default.top;
		var xTip_default = (tLeft_default + 527 + 30)+"px";
			var yTip_default = (255)+"px";
		
	$('.tip .tipMid').html(default_title);
	$('.tip').css({'top' : yTip_default, 'left' : xTip_default})
	$('.tip').show();
	
	/* Give each item with the class associated with 
	   the plugin the ability to call the tooltip    */
	$(this).each(function(){
		
		var $this = $(this);
		var tip = $('.tip');
		var tipInner = $('.tip .tipMid');
		
		var tTitle = (this.title);
		this.title = "";
		
		var offset = $(this).offset();
		var tLeft = offset.left;
		var tTop = offset.top;
		var tWidth = $this.width();
		var tHeight = $this.height();
	
		/* Mouse over and out functions*/
		
	/* 	$this.hover(
			function() {
				tipInner.html(tTitle);
				setTip(tTop, tLeft);
				setTimer();	
			}, 
			
			function() {
				stopTimer();
				//tip.hide();	
			}
		);		 */   
		
		
		
		$this.mouseover(function(){
			//tip.hide();
			
			tipInner.html(tTitle);
			//setTip(tTop, tLeft);
			tip.show();
			//setTimer();	
			
			/*
				$('.row-desc > a > img').click(function(){
					var redirect_link = $(this).parent().attr('redirection');
		
					if(redirect_link != ""){
						window.open(redirect_link);
						return false;
					}
				}); */
		});
		
		
		
		$('.tipMid').click(function(){
			tip.toggle();
		});
		
		
		/* $this.click(function(){
			if($this.hasClass('active') == false){
				$this.addClass('active');
			}else{
				$this.removeClass('active');
			}
		});		 */
		/* Delay the fade-in animation of the tooltip */
		setTimer = function() {
			$this.showTipTimer = setInterval("showTip()", defaults.delay);
		}
		
		stopTimer = function() {
			clearInterval($this.showTipTimer);
		}
		
		/* Position the tooltip relative to the class 
		   associated with the tooltip                */
		setTip = function(top, left){
			/* var topOffset = tip.height();
			var xTip = (left-30)+"px";
			var yTip = (top-topOffset-60)+"px";
			tip.css({'top' : yTip, 'left' : xTip}); */
			 
			var xTip = (left + 527 + 30)+"px";
			var yTip = (255)+"px";
			//tip.css({'top' : yTip, 'left' : xTip});
		}
		
		/* This function stops the timer and creates the
		   fade-in animation                          */
		showTip = function(){
			stopTimer();
			//tip.animate({"top": "+=20px", "opacity": "toggle"}, defaults.speed);
		}
	});
	/*
	$('.row-desc > a > img').click(function(){
		var redirect_link = $(this).parent().attr('redirection');
		if(redirect_link != ""){
			window.open(redirect_link);
			return false;
		}
	});
	/*$('.img-thumb > a > img').click(function(){
		var redirect_link = $(this).parent().attr('redirection');
		if(redirect_link != ""){
			window.open(redirect_link);
			return false;
		}
	});
	/* $('.aligner').click(function(){
		var redirect_link = $('.img-thumb > a > img').parent().attr('redirection');
		if(redirect_link != ""){
			window.open(redirect_link);
			return false;
		}
	}); */
};

