/**
 * 
 */

$(document).ready(function(){
	
	var active = false; // Prevents re-loading of same active link
	
	function closeWindow(){
		$("#usernameContainer2").fadeOut();
		$("#usernameContainer3").fadeOut(500, function(){
            $(this).empty().css("border-style","none").css("border-width","0").css("background-color","");
        });
		return false;
	}
    
    
	
	$(".usernameLink").hover(function(){
		
		$(this).oneTime(500,"usernameLink", function(){
		
			if (active == false){
				
				active = true;

				var position = $(this).offset();
				var leftPosition = position.left + $(this).width() + 5;
				var topPosition = position.top;
				var username = $(this).html();
				
				$("#usernameContainer2").fadeIn(250).css("position","absolute").css("top",topPosition - ($("#usernameContainer2").height() / 2)).css("left",leftPosition);
				$("#usernameContainer3").fadeIn(250).css("border-style","solid").css("border-width","1px").css("background-color","black").css("box-shadow","5px 5px 5px #000").css("-moz-box-shadow","5px 5px 5px #000").html("Loading..");
				
				
				
					$.ajax({
						url:  "/userinfo.php",
						type: "POST",
						data: "do=retrieve&username="+username,
						dataType:  "html",
						success:  function(response){
								
							$("#usernameContainer3").empty().html(response);
							
							var height = $("#usernameTable").height() + 5;
							var width = $("#usernameTable").width() + 5;
							
							topPosition = topPosition - (height / 2);
							$("#usernameContainer2").css("position","absolute").css("top",topPosition).css("left",leftPosition);
							$("#usernameContainer3").width(width).height(height);	
						}
					});
				}
				$(document).scroll(function(){
					active = closeWindow();
				});
		});
		
		}, function(){
			$(this).stopTime("usernameLink");
		});
		
		$("#usernameContainer2").hover(function(){
			
		}, function(){
			active = closeWindow();
		});
});
