﻿$(function()   
{   
//Requires
//<script src="../javascript/jquery-1.3.2.js" type="text/javascript"></script>
  var hideDelay = 500;     
  var currentID;   
  var hideTimer = null;   
  
  // One instance that's reused to show info for the current person   
  var container = $('<div id="popupContainer">'  
      + '<div style="width: 275px; border: 2px solid #0092bd; position: relative;" class="popupPopup">'
	  + '<div style="width: 30px; height: 30px; position:absolute; top: -16px; left: 20px;"><img src="/images/popup/toparrow.gif" /></div>'
      + '<div id="popupContent"></div></div>'  
      + '</div>');   
  
  $('#containerperfdetails').append(container);
   
  $('.PopupTrigger').live('mouseover', function()   
  {  
      // 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);   


    //OFFSET  
      var pos = $(this).offset();   
      var width = $(this).width();   
      container.css({   
          left: (pos.left + width) + 'px',   
          top: pos.top + 'px'  
      });   

//CUSTOM: MINICAL OFFSET
      var pos = $('#calendar').offset();   
      var width = $('#calendar').width();  
      var height = $('#calendar').height();  
      var mouseTop = $(this).offset();  
       
      container.css({   
		  //left: (pos.left + width + 20 + 'px'),
		  left: (mouseTop.left - 18) + 'px',
          top: (mouseTop.top + 35) + 'px'          
      });   


    container.css('display', 'block');   

    $("#popupContent").text('');
    $("#PopupResult").hide();
    $("#PopupResult").text('');
    $('#popupContent').html('&nbsp;');   

//Load content
var sUID = Math.random()*Math.random(); 
$('#popupContent').html('<div id=\"cpopLoading\">&nbsp;</div>');
//$('#popupContent').load('popup/popdetail.aspx?id=' + pageID + '&uid=' + sUID, { 'p': pageID});
$('#popupContent').load('/popup/popPerfByDate.aspx?d=' + pageID + '&uid=' + sUID, { 'p': pageID}); //Pass In Date as Page ID


//Alt. Load Content
/*
      $.ajax({   
          type: 'GET',   
          url: 'popdetail.aspx',   
          data: 'id=' + pageID + '&guid=' + currentID,   
          success: function(data)   
          {   
              // Verify that we're pointed to a page that returned the expected results.   
              if (data.indexOf('PopupResult') < 0)   
              {   
                  $('#popupContent').html('<span >Page ' + pageID + ' did not return a valid result' + currentID + '</span>');   
              }   
  
              // Verify requested since we could have multiple ajax   
              // requests out if the server is taking a while.   
              if (data.indexOf(currentID) > 0)   
              {                     
                  var text = $(data) ;//.find('.PopupResult').html();   
                  $('#popupContent').html(data); 
                  $("#cpopLoading").hide();  
                  $("#popupContent").show();  
                  $("#PopupResult").show();   
              }   
          }   
      });   
 */

//    //HIDE LOADER 
    $("#popupContent").show();  
    $("#PopupResult").show();      
//    container.css('display', 'block');   
        
  });   
  
  $('.PopupTrigger').live('mouseout', function()   
  {   
      if (hideTimer)   
          clearTimeout(hideTimer);   
      hideTimer = setTimeout(function()   
      {   
            $("#popupContent").text('');
            $("#PopupResult").hide();
            $("#PopupResult").text('');
            //SHOW LOADER
            $('#popupContent').html('<div id=\"cpopLoading\">&nbsp;</div>');
            container.css('display', 'none');   
      }, hideDelay);   
  });   
  
  // Allow mouse over of details without hiding details   
  $('#popupContainer').mouseover(function()   
  {   
    $("#popupContent").show();  
    $("#PopupResult").show(); 
      if (hideTimer){
        clearTimeout(hideTimer);   
     }
          
  });   
  
  // Hide after mouseout   
  $('#popupContainer').mouseout(function()   
  {   
      if (hideTimer)   
          clearTimeout(hideTimer);   
      hideTimer = setTimeout(function()   
      {   
        $("#popupContent").text('');
        $("#PopupResult").hide();
        $("#PopupResult").text('');
        //SHOW LOADER
        $('#popupContent').html('<div id=\"cpopLoading\">&nbsp;</div>');
          container.css('display', 'none');   
      }, hideDelay);   
  });   
}); 
