$(document).ready(function(){
	
	$(".staff-member").mouseover(function(){
		
		//fade in the little popup
		var identification = this.id.replace("member-", "");
		
		$("#popup-"+identification).show();
		var popwidth = $("#popup-"+identification).width();
		var point = $("#popup-"+identification).find(".bottom");
		
		//now make it follow the mouse
		$(this).mousemove(function(e){
			// make sure to check for the left edge of the screen
			var offset = e.pageX - popwidth + 5;
			
			if (offset <= 1) {
				offset = 1;
				// lets make the point follow the cursor
				// if we're here.
				var halfway = (offset + popwidth)/2+27;
				if (e.pageX < halfway) {
					$(point).css({"background":"url(images/team/quote-bottom-left.gif)", "left":e.pageX});
				} else {
					$(point).css({"background":"url(images/team/quote-bottom.gif)", "left":e.pageX-27});
				}
			}
			
			var x = offset;
			var y = e.pageY - 85;
			$("#popup-"+identification).css({'top' : y, 'left' : x});
			
		});
		
	});
	
	$(".staff-member").mouseout(function(){
		var identification = this.id.replace("member-", "");
		$("#popup-"+identification).hide();
	});
	
	
});
