$(function()  
{  
	// alert('sdfsd');
  var hideDelay = 200;    
  var currentID;  
  var hideTimer = null;  
  
  // One instance that's reused to show info for the current person  
  var container = $('<div id="infoToolTip">'  
      + '<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" class="personPopupPopup">'  
      + '<tr>'  
      + '   <td class="TTTop"></td>'  
      + '</tr>'  
      + '<tr>'  
      + '   <td class="TTContentHeader" id="TTContentHeader">&nbsp;</td>'  
      + '</tr>'  
      + '<tr>'  
      + '   <td class="TTContentContent" id="TTContentContent"></td>'  
      + '</tr>'  
      + '<tr>'  
      + '   <td class="TTBottom"></td>'  
      + '</tr>'  
      + '</table>'  
      + '</div>');  
/*  var container = $('<div id="infoToolTip">'
  	+ '<div class="TTTop">&nbsp;</div>'
  	+ '<div class="TTContent" id="TTContent">'
  	+ '<div class="TTContentHeader" id="TTContentHeader">&nbsp;</div>'
  	+ '<div class="TTContentContent" id="TTContentContent">&nbsp;</div>'
  	+ '</div>'
  	+ '<div class="TTBottom">&nbsp;</div>'
  	+ '</div>');
  	//alert('sas');*/
  $('body').append(container);  
 
  $('.infoContent').live('mouseenter', function()  
  {  
	//alert('xzxz');
  	// format of 'rel' tag: pageid,personguid  
      var settings = $(this).attr('rel').split(',');  
      var pageID = settings[0];  
      currentID = settings[1];  
  
      // 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();  
      var left=0;
     
	  var windowW =  document.body.clientWidth;
	  
	  //alert(windowW+'-'+pos.left+'-'+width+'-'+(pos.left+width));
	  
      if(pos.left+216 > windowW )
      {
       	left=pos.left-216;
	  }
	  else
	    left=pos.left + width;
    
      container.css({  
          left: left + 'px',  
          top: pos.top - 5 + 'px'  
      });  
  
    //  $('#TTContent').html('&nbsp;');  
  
     /* $.ajax({  
          type: 'GET',  
          url: '',  
          data: 'page=' + pageID + '&guid=' + currentID,  
          success: function(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();  
                  $('#personPopupContent').html(text);  
              }  
          }  
      });  */
     
     var text=$(this).attr('rel');
     $('#TTContentContent').html(text+' '); 
      
      var text=$(this).attr('lang');
      $('#TTContentHeader').html(text+' '); 
      //$(this).attr('title','');
  //alert(text);
      container.css('display', 'block');  
  });  
  
  $('.infoContent').live('mouseleave', function()  
  {  
      if (hideTimer)  
          clearTimeout(hideTimer);  
      hideTimer = setTimeout(function()  
      {  
          container.css('display', 'none');  
      }, hideDelay);  
  });  
  
  // Allow mouse over of details without hiding details  
  $('#infoToolTip').mouseover(function()  
  {  
      if (hideTimer)  
          clearTimeout(hideTimer);  
  });  
  
  // Hide after mouseout  
  $('#infoToolTip').mouseout(function()  
  {  
      if (hideTimer)  
          clearTimeout(hideTimer);  
      hideTimer = setTimeout(function()  
      {  
          container.css('display', 'none');  
      }, hideDelay);  
  });  
});  
