/*-----------------------------------------------------------------------------------------------*/
/*                                      SIMPLE jQUERY TOOLTIP                                    */
/*                                      VERSION: 1.1                                             */
/*                                      AUTHOR: jon cazier                                       */
/*                                      EMAIL: jon@3nhanced.com                                  */
/*                                      WEBSITE: 3nhanced.com                                    */
/*-----------------------------------------------------------------------------------------------*/

$(document).ready(function() {
	$('.tooltip').hover(
		function() {
		this.tip = this.title;
		
		var leftPos = findLeft(this);
		var topPos = parseInt($(this).parent().css("top"))+170;
		var height, width = 270;
		if($(this).hasClass("short_balloon")){
			height = 50;
			width = 275;
		}
		else if($(this).hasClass("med_balloon")){
			height = 80;		
		}
		else if($(this).hasClass("long_balloon")){
			height = 105;		
		}
		else if($(this).hasClass("x_long_balloon")){
			height = 185;		
		}
		else if($(this).hasClass("super_balloon")){
			height = 290;		
		}
		
		var parentNode = document.body;
		$(parentNode).append(
			'<div id="toolTipWrapper">'
				+'<div class="toolTipTop">'
					+'<iframe frameborder=0 style="width:'+width+'px;height:'+height+'px;background-color:#0078D4;" src="'+this.tip+'"></iframe>'
				+'</div>'
				+'<div class="toolTipBtm"></div>'
			+'</div>'
		);
		this.title = "";
		this.width = $(this).width();
		
		if(leftPos < ($("#CollapsiblePanel1").width()/2)){
			$('#toolTipWrapper').css({position:'absolute',left:leftPos, top:topPos})
		}
		else{
			$('#toolTipWrapper .toolTipTop').css("background-image", "url(images/balloon/balloon_down_top_left1.png)");
			leftPos-= 290;
			$('#toolTipWrapper').css({position:'absolute',left:leftPos, top:topPos})
		}
		
		$('#toolTipWrapper').fadeIn(300);
	},
	function() {
		$('#toolTipWrapper').fadeOut(100);
		$('#toolTipWrapper').remove();
			this.title = this.tip;
		}
	);
});

function findLeft(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
		}
	}
	return curleft;
}