$(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="popupContainer">' 
		+ '<div class="close" id="popupClose"></div>'
		+ '<div id="popupTop"></div>'  
		+ '<div id="popupContent"></div>'  
		+ '</div>');  
  
  $('body').append(container);  
  
  $('#evt').live('click', function()  
  {  
      var settings = $(this).attr('detailid').split(',');  
      var pageID = settings[0];  
	  var locID = settings[1];  
      var popClass = settings[2]; 
	  var tz = settings[3];
	  var hex = settings[4];
	  
	  //var pageID = $(this).attr('detailid');  
  
  
      if (hideTimer)  
          clearTimeout(hideTimer);  
	  
	  $('#popupContent').css('border-left-color','#' + hex);
  
      var pos = $(this).offset();  
      var width = $(this).width();  
      container.css({  
          left: (pos.left) + 'px',  
          top: pos.top + 15 + 'px'  
      });  
	  
  
      $('#popupContent').html('&nbsp;');  
  
      $.ajax({  
          type: 'GET',  
          url: 'http://www.publicsectorevent.com/data/caldetail.cfm',  
          data: 'eid=' + pageID + '&tz=' + tz + '&locid=' + locID,  
          success: function(data)  
          {  
			  $('#popupContent').html(data);  
          }  
      });  
      container.css('display', 'block');  
		var docHeight = $(document).height();
		var winHeight = $(window).height();
		var scrollHeight = pos.top + 400;
		if (scrollHeight > docHeight){
		  if (hideTimer) {
			  clearTimeout(hideTimer);  
		  }
		  hideTimer = setTimeout(function()  
			{  	
			  $(window).scrollTo(scrollHeight);
			}, 250); 
		} else {
			$(window).scrollTo(pos.top);
		}
});  
  
  $('#evtATA').live('click', function()  
  {  
      var settings = $(this).attr('detailid').split(',');  
      var pageID = settings[0];  
	  var locID = settings[1];  
      var popClass = settings[2]; 
	  var tz = settings[3];

	//var pageID = $(this).attr('detailid');  
  
  
      if (hideTimer)  
          clearTimeout(hideTimer);  
	  
	  $('#popupContent').css('background-color','#' + hex);

  
      var pos = $(this).offset();  
      var width = $(this).width();  
      container.css({  
          left: (pos.left -10) + 'px',  
          top: pos.top + 60 + 'px'  
      });  
  
      $('#popupContent').html('&nbsp;');  
  
      $.ajax({  
          type: 'GET',  
          url: 'http://www.publicsectorevent.com/data/caldetail.cfm',  
          data: 'eid=' + pageID + '&tz=' + tz + '&locid=' + locID,  
          success: function(data)  
          {  
			  $('#popupContent').html(data);  
          }  
      });  
  
      container.css('display', 'block');  
		var docHeight = $(document).height();
		var winHeight = $(window).height();
		var scrollHeight = pos.top + 400;
		if (scrollHeight > docHeight){
		  if (hideTimer) {
			  clearTimeout(hideTimer);  
		  }
		  hideTimer = setTimeout(function()  
			{  	
			  $(window).scrollTo(scrollHeight);
			}, 250); 
		} else {
			$(window).scrollTo(pos.top);
		}
  });
  
  $('#evtTitle').live('click', function()  
  {  
      var settings = $(this).attr('detailid').split(',');  
      var pageID = settings[0];  
	  var locID = settings[1];  
      var popClass = settings[2]; 
	  var tz = settings[3];

	//var pageID = $(this).attr('detailid');  
  
  
      if (hideTimer)  
          clearTimeout(hideTimer);  
	  
	  $('#popupContent').css('background-color','#' + hex);


  
      var pos = $(this).offset();  
      var width = $(this).width();  
      container.css({  
          left: (pos.left - 78) + 'px',  
          top: pos.top + 58 + 'px'  
      });  
  
      $('#popupContent').html('&nbsp;');  
  
      $.ajax({  
          type: 'GET',  
          url: 'http://www.publicsectorevent.com/data/caldetail.cfm',  
          data: 'eid=' + pageID + '&tz=' + tz + '&locid=' + locID,  
          success: function(data)  
          {  
			  $('#popupContent').html(data);  
          }  
      });  
  
      container.css('display', 'block');  
		var docHeight = $(document).height();
		var winHeight = $(window).height();
		var scrollHeight = pos.top + 400;
		if (scrollHeight > docHeight){
		  if (hideTimer) {
			  clearTimeout(hideTimer);  
		  }
		  hideTimer = setTimeout(function()  
			{  	
			  $(window).scrollTo(scrollHeight);
			}, 250); 
		} else {
			$(window).scrollTo(pos.top);
		}
  });
  $('#popupClose').live('click', function()  
	{
         container.css('display', 'none');  
	});
  /*
  $('#evt').live('mouseout', function()  
  {  
      if (hideTimer)  
          clearTimeout(hideTimer);  
      hideTimer = setTimeout(function()  
      {  
          container.css('display', 'none');  
      }, hideDelay);  
  });  
  // Allow mouse over of details without hiding details  
  $('#popupContainer').mouseover(function()  
  {  
      if (hideTimer)  
          clearTimeout(hideTimer);  
  });  
  
  // Hide after mouseout  
  $('#popupContainer').mouseout(function()  
  {  
      if (hideTimer)  
          clearTimeout(hideTimer);  
      hideTimer = setTimeout(function()  
      {  
          container.css('display', 'none');  
      }, hideDelay);  
  });
    */

}); 