/*-----------------------------------------------------------------------------------------------*/
/*                                      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;
		if ($(this).attr('tiptitle') != null)
			this.toptip = $(this).attr('tiptitle');
		else
			this.toptip = $(this).text();
			if ($(this).attr('id') == 'risk') {
				this.tip = 'You can work out your risk profile on Sorted\'s <a href="/calculators/risk-recommender/">Risk recommender</a>.';
				$(this).append(
					'<div class="toolTipWrapper" id="kiwi-first-page-popup">'
						+'<div class="toolTipTop"><p class="toptip">'
						+this.toptip
						+'</p></div>'
						+'<div class="toolTipMid"><p class="tipcontent">'
							+this.tip
						+'</p></div>'
						+'<div class="toolTipBtm"></div>'
					+'</div>'
				);
			} else {
				$(this).append(
					'<div class="toolTipWrapper">'
						+'<div class="toolTipTop"><p class="toptip">'
						+this.toptip
						+'</p></div>'
						+'<div class="toolTipMid"><p class="tipcontent">'
							+this.tip
						+'</p></div>'
						+'<div class="toolTipBtm"></div>'
					+'</div>'
				);
			}
			if ($(this).attr('id') == 'risk') {
				$('toolTipWrapper').addClass="test";
			}
			
		var heightTest = $(".toolTipMid").height();
		$(this).find('.toolTipWrapper').css({display:'none'});
		
		this.title = "";
		this.width = $(this).width();
		
		//alert(heightTest);
		
		$(this).find('.toolTipWrapper').css({top:-54-heightTest})
		$(this).find('.toolTipWrapper').css({left:this.width-240})
		$('.toolTipWrapper').fadeIn(300);
	},
	function() {
		$('.toolTipWrapper').fadeOut("slow");
		$(this).children().remove();
			this.title = this.tip;
		}
	);
	
	//if it is on kiwisave calc page2
	$('.toolTip-kiwi').mouseover(function() {
	    $('.tooltip-container').remove();
			this.tip = this.title;
			if ($(this).attr('tiptitle') != null)
				this.toptip = $(this).attr('tiptitle');
			else
				this.toptip = $(this).text();
			
			//alert(this.tip);
			if ($(this).attr('id') == 'risk' || $(this).attr('id') == 'fund-name' || $(this).attr('id') == 'header-passive-active' || $(this).attr('id') == 'header-fees-paid-dollar' || $(this).attr('id') == 'header-fees-paid-percent' ) {
					$('#calculator_container').append(
					'<div class="tooltip-container" style="height: auto; overflow: hidden; ">'
						+'<div class="top-region"><strong>'
						+this.toptip
						+'</strong></div>'
						+'<div class="mid-region"><p>'
							+this.tip
						+'</p></div>'
						+'<div class="bottom-region"></div>'
					+'</div>'
					);
			} else {
				$(this).append(
					'<div class="tooltip-container" style="height: auto; overflow: hidden; ">'
						+'<div class="top-region"><strong>'
						+this.toptip
						+'</strong></div>'
						+'<div class="mid-region"><p>'
							+this.tip
						+'</p></div>'
						+'<div class="bottom-region"></div>'
					+'</div>'
					);
			}
				
			var heightTest = $(".mid-region").height();
			$(this).find('.tooltip-container').css({display:'none'});
			this.width = $(this).width();
			if ($(this).attr('id') == 'risk') {
				$('.tooltip-container').css({top: -34-heightTest});
				$('.tooltip-container').css({left:-210});
			} else if ($(this).attr('id') == 'fund-name') {
				$('.tooltip-container').css({top: -34-heightTest});
				$('.tooltip-container').css({left:160});
			} else if ($(this).attr('id') == 'header-passive-active') {
				$('.tooltip-container').css({top: -134-heightTest});
				$('.tooltip-container').css({left:360});
				$('.top-region').html('<strong>Passive / Active Fund</strong>');
				$('.mid-region').html ('Active funds have managers who will actively seek the greatest return. Passive funds generally rely on the market to dictate performance.');
			} else if ($(this).attr('id') == 'header-fees-paid-dollar') {
				$('.tooltip-container').css({top: -114-heightTest});
				$('.tooltip-container').css({left:280});
				$('.top-region').html('<strong>Fees until age 65 $</strong>');
				$('.mid-region').html ('The total amount of fees expected to be paid in <a href="#notes">today\'s dollars</a> by 65.  For those aged 60-64 the fee $ represents a 5 year term.');
			}  else if ($(this).attr('id') == 'header-fees-paid-percent') {
				$('.tooltip-container').css({top: -114-heightTest});
				$('.tooltip-container').css({left:320});
				$('.top-region').html('<strong>Fees until age 65 %</strong>');
				$('.mid-region').html ('The total amount of fees expected to be paid in <a href="#notes">today\'s dollars</a> expressed as a proportion of the expected <a href="#kiwisaver-balance">KiwiSaver balance</a> by 65. For those aged 60-64 the fee % represents a 5 year term.');
			} else {
				$('.tooltip-container').css({top:-54-heightTest});
				$('.tooltip-container').css({left:this.width-240});
			}
			$('.tooltip-container').fadeIn(300);
			$(this).addClass('actived');    																			
	});
	
	
	$('.toolTip-kiwi').mouseout(function() {
	    window.setTimeout(function() {
   		    
					$('.tooltip-container').fadeOut("slow").remove();
			}, 2000);																					 
	});

/*$('.toolTip-kiwi').hover(
		function() {
		$('.tooltip-container').remove();
		this.tip = this.title;
		if ($(this).attr('tiptitle') != null)
			this.toptip = $(this).attr('tiptitle');
		else
			this.toptip = $(this).text();
		
		//alert(this.tip);
		if ($(this).attr('id') == 'risk' || $(this).attr('id') == 'fund-name' || $(this).attr('id') == 'header-passive-active' || $(this).attr('id') == 'header-fees-paid-dollar' || $(this).attr('id') == 'header-fees-paid-percent' ) {
				$('#calculator_container').append(
				'<div class="tooltip-container" style="height: auto; overflow: hidden; ">'
					+'<div class="top-region"><strong>'
					+this.toptip
					+'</strong></div>'
					+'<div class="mid-region"><p>'
						+this.tip
					+'</p></div>'
					+'<div class="bottom-region"></div>'
				+'</div>'
				);
		} else {
			$(this).append(
				'<div class="tooltip-container" style="height: auto; overflow: hidden; ">'
					+'<div class="top-region"><strong>'
					+this.toptip
					+'</strong></div>'
					+'<div class="mid-region"><p>'
						+this.tip
					+'</p></div>'
					+'<div class="bottom-region"></div>'
				+'</div>'
				);
		}
			
		var heightTest = $(".mid-region").height();
		$(this).find('.tooltip-container').css({display:'none'});
		this.width = $(this).width();
		if ($(this).attr('id') == 'risk') {
			$('.tooltip-container').css({top: -34-heightTest});
			$('.tooltip-container').css({left:-210});
		} else if ($(this).attr('id') == 'fund-name') {
			$('.tooltip-container').css({top: -34-heightTest});
			$('.tooltip-container').css({left:160});
		} else if ($(this).attr('id') == 'header-passive-active') {
			$('.tooltip-container').css({top: -134-heightTest});
			$('.tooltip-container').css({left:360});	
		} else if ($(this).attr('id') == 'header-fees-paid-dollar') {
			$('.tooltip-container').css({top: -114-heightTest});
			$('.tooltip-container').css({left:280});
			$('.top-region').html('<strong>Fees until age 65 $</strong>');
			$('.mid-region').html ('The total amount of fees expected to be paid in <a href="#notes">today\'s dollars</a> by 65.  For those aged 60-64 the fee $ represents a 5 year term.');
		}  else if ($(this).attr('id') == 'header-fees-paid-percent') {
			$('.tooltip-container').css({top: -114-heightTest});
			$('.tooltip-container').css({left:320});
			$('.top-region').html('<strong>Fees until age 65 %</strong>');
			$('.mid-region').html ('The total amount of fees expected to be paid in <a href="#notes">today\'s dollars</a> expressed as a proportion of the expected <a href="#kiwisaver-balance">KiwiSaver balance</a> by 65. For those aged 60-64 the fee % represents a 5 year term.');
		} else {
			$('.tooltip-container').css({top:-54-heightTest});
			$('.tooltip-container').css({left:this.width-240});
		}
		$('.tooltip-container').fadeIn(300);
		$(this).addClass('actived');
	},
	
	function() {
			
			window.setTimeout(function() {
   		    
					$('.tooltip-container').fadeOut("slow").remove();
			}, 2000);			
		}
	);
	*/
	
	
	
});
