$(document).ready(function(){
	$(function()
	{
	  var hideDelay = 500;
	  var currentID;
	  var hideTimer = null;

	  // One instance that's reused to show info for the current person
	  var container = $('<div id="mpContainer"><div class="top"></div>'
		  + '   <div id="personPopupContent"></div><div class="bot"></div>'
		  + '</div>');

	  $('body').append(container);

	  $('.mpTrigger').live('mouseover', function()
	  {
		  $('#personPopupContent').html('');
		  // format of 'rel' tag: pageid,personguid
		  var settings = $(this).attr('rel');
		  //var pageID = settings[0];
		  currentID = settings;

		  // If no guid in url rel tag, don't popup blank
		  if (currentID == '')
			  return;

		  if (hideTimer)
			  clearTimeout(hideTimer);

		  var pos = $(this).offset();
		  var width = $(this).width();
		  container.css({
			  left: (pos.left) + 'px',
			  top: pos.top - 5 - container.height() + 'px'
		  });

		  $('#personPopupContent').html('&nbsp;');

		  $.ajax({
			  type: 'POST',
			  url: '/?ajax=1',
			  data: 'wrajaxfunction=show_miniprofile&wrajaxsmarty=../custom/component/miniprofile&wrajaxargs[0]=' + currentID,
			  dataType: 'text',
			  cache: 'false',
			  success: function(data)
			  {
				  //console.log(data);
				  /*console.log(data.documentElement.innerHTML);
				  console.log(data.innerHTML);*/
				  //console.log(data.getElementById('content'));
				  //alert(data.getElementById('contentPer'));
				  //alert(data);
				  // Verify that we're pointed to a page that returned the expected results.
				  /*if (data.indexOf('personPopupResult') < 0)
				  {
					  $('#personPopupContent').html('<span >Page ' + pageID + ' did not return a valid result for person ' + currentID + 
	'.Please have your administrator check the error log.</span>');
				  }*/

				  // Verify requested person is this person since we could have multiple ajax
				  // requests out if the server is taking a while.
				  /*if (data.indexOf(currentID) > 0)
				  {*/
					  /*var text = $(data).find('.personPopupResult').html();
					  $('#mpContainer').html(text);

					  var editdummy = document.getElementById('editdummy');
					  editdummy.innerHTML = data;*/
				  //alert(data.toString());
					  //var text = $(data).html();
					  $('#personPopupContent').html(data);
					  
				  //}
			  }
		  });

		  container.css('display', 'block');
	  });

	  $('.mpTrigger').live('mouseout', function()
	  {
		  if (hideTimer)
			  clearTimeout(hideTimer);
		  hideTimer = setTimeout(function()
		  {
			  container.css('display', 'none');
		  }, hideDelay);
	  });

	  // Allow mouse over of details without hiding details
	  $('#mpContainer').mouseover(function()
	  {
		  if (hideTimer)
			  clearTimeout(hideTimer);
	  });

	  // Hide after mouseout
	  $('#mpContainer').mouseout(function()
	  {
		  if (hideTimer)
			  clearTimeout(hideTimer);
		  hideTimer = setTimeout(function()
		  {
			  container.css('display', 'none');
		  }, hideDelay);
	  });
	});
});
