/**
 * http://www.kriesi.at/archives/create-simple-tooltips-with-css-and-jquery-part-2-smart-tooltips
 */
function simple_tooltip(target_items, name){
//	if($(this).attr("title") != "" && $(this).attr("title") != "undefined" ){
//		$(target_items).click(function(){
//			alert("fferfer");
//		});
//	}
	$(target_items).each(function(i){
		$("body").append("<div class='"+name+"' id='"+name+i+"'><p>"+$(this).attr('title')+"</p></div>");
		var my_tooltip = $("#"+name+i);
		
		if($(this).attr("title") != "" && $(this).attr("title") != "undefined" ){
			$(this).removeAttr("title").mouseover(function(){
						my_tooltip.css({opacity:0.8, display:"none"}).fadeIn(400);
			}).mousemove(function(kmouse){
					var border_top = $(window).scrollTop(); 
					var border_right = $(window).width();
					var left_pos;
					var top_pos;
					var offset = 20;
					if(border_right - (offset *2) >= my_tooltip.width() + kmouse.pageX){
						left_pos = kmouse.pageX+offset;
					} else{
						left_pos = border_right-my_tooltip.width()-offset;
					}
						
					if(border_top + (offset *2)>= kmouse.pageY - my_tooltip.height()){
						top_pos = border_top +offset;
					} else{
						top_pos = kmouse.pageY-my_tooltip.height()-offset;
					}	
					
					
				my_tooltip.css({left:left_pos, top:top_pos});
			}).mouseout(function(){
					my_tooltip.css({left:"-9999px"});				  
			});
		
		}
	});
}

function simple_tooltip_techStats(target_items, name){
	$(target_items).each(function(i){
		$("body").append("<div class='"+name+"' id='"+name+i+"'><p>"+$(this).attr('title')+"</p></div>");
		var my_tooltip = $("#"+name+i);
		
		if($(this).attr("title") != "" && $(this).attr("title") != "undefined" ){
			$(this).removeAttr("title").mouseover(function(){
						my_tooltip.css({opacity:0.8, display:"none"}).fadeIn(400);
			}).mousemove(function(kmouse){
					var border_top = $(window).scrollTop(); 
					var border_right = $(window).width();
					var left_pos;
					var top_pos;
					var offset = 20;
					if(border_right - (offset *2) >= my_tooltip.width() + kmouse.pageX){
						left_pos = kmouse.pageX+offset;
					} else{
						left_pos = border_right-my_tooltip.width()-offset;
					}
						
					if(border_top + (offset *2)>= kmouse.pageY - my_tooltip.height()){
						top_pos = border_top +offset;
					} else{
						top_pos = kmouse.pageY-my_tooltip.height()-offset;
					}	
					
					
				my_tooltip.css({left:left_pos, top:top_pos});
			}).mouseout(function(){
					my_tooltip.css({left:"-9999px"});				  
			});
		
		}
	});
}

function simple_tooltip_percentages(target_items, name){
	$(target_items).each(function(i){
		$("body").append("<div class='"+name+"' id='"+name+i+"'><p>"+$(this).attr('title')+"</p></div>");
		var my_tooltip = $("#"+name+i);
		
		if($(this).attr("title") != "" && $(this).attr("title") != "undefined" ){
			$(this).removeAttr("title").mouseover(function(){
						my_tooltip.css({opacity:0.8, display:"none"}).fadeIn(400);
			}).mousemove(function(kmouse){
					var border_top = $(window).scrollTop(); 
					var border_right = $(window).width();
					var left_pos;
					var top_pos;
					var offset = 20;
					if(border_right - (offset *2) >= my_tooltip.width() + kmouse.pageX){
						left_pos = kmouse.pageX+offset;
					} else{
						left_pos = border_right-my_tooltip.width()-offset;
					}
						
					if(border_top + (offset *2)>= kmouse.pageY - my_tooltip.height()){
						top_pos = border_top +offset;
					} else{
						top_pos = kmouse.pageY-my_tooltip.height()-offset;
					}	
					
					
				my_tooltip.css({left:left_pos, top:top_pos});
			}).mouseout(function(){
					my_tooltip.css({left:"-9999px"});				  
			});
		
		}
	});
}

function investmentList_pagination(target_items, name){
	$(target_items).each(function(i){
		$("body").append("<div class='"+name+"' id='"+name+i+"'><p>"+$(this).attr('title')+"</p></div>");
		var my_tooltip = $("#"+name+i);
		
		if($(this).attr("title") != "" && $(this).attr("title") != "undefined" ){
			$(this).removeAttr("title").mouseover(function(){
						my_tooltip.css({opacity:0.8, display:"none"}).fadeIn(400);
			}).mousemove(function(kmouse){
//					var border_top = $(window).scrollTop(); 
					var border_right = $(window).width();
					var left_pos;
					var top_pos;
					var offset = 40;
					if(border_right - (offset *2) >= my_tooltip.width() + kmouse.pageX){
						left_pos = kmouse.pageX+offset;
					} else{
						left_pos = border_right-my_tooltip.width()-offset;
					}
						
					/*if(border_top + (offset *2)>= kmouse.pageY - my_tooltip.height()){
						top_pos = border_top +offset;
					} else{
						top_pos = kmouse.pageY-my_tooltip.height()-offset;
					}	*/
					
					top_pos = kmouse.pageY-my_tooltip.height()+offset;
					
					
				my_tooltip.css({left:left_pos, top:top_pos});
			}).mouseout(function(){
					my_tooltip.css({left:"-9999px"});				  
			});
		
		}
	});
}

$(document).ready(function(){
	 simple_tooltip("a.investment_title","tooltip");
	 simple_tooltip_techStats("a.investment_title_techStats","tooltiptechStats");
	 simple_tooltip_percentages("a.investment_tooltip_Percentages","tooltipPercentages");
	 investmentList_pagination("a.investmentList_pagination","tooltipbusinessCaseIds");
	 
});