$(function()  
{  
  var hideDelay = 400;
  var sponsor;  
  var hideTimer = null;  
  
  // One instance that's reused to show info for the current person  
  var container = $('<div id="personPopupContainer">'  
      + '<table width="" border="0" cellspacing="0" cellpadding="0" align="center" class="personPopupPopup">'  
      + '<tr>'  
      + '   <td class="corner topLeft"></td>'  
      + '   <td class="top"></td>'  
      + '   <td class="corner topRight"></td>'  
      + '</tr>'  
      + '<tr>'  
      + '   <td class="left">&nbsp;</td>'  
      + '   <td><div id="personPopupContent"></div></td>'  
      + '   <td class="right">&nbsp;</td>'  
      + '</tr>'  
      + '<tr>'  
      + '   <td class="corner bottomLeft">&nbsp;</td>'  
      + '   <td class="bottom">&nbsp;</td>'  
      + '   <td class="corner bottomRight"></td>'  
      + '</tr>'  
      + '</table>'  
      + '</div>');  
  
  $('body').append(container);  
  
  $('.personPopupTrigger').live('mouseover', function()  
  {  
      // format of 'rel' tag: pageid,personguid  
      var settings = $(this).attr('rel').split(',');  
      var pageID = settings[0];  
      sponsor = settings[1];  
  
      // If no guid in url rel tag, don't popup blank  
      if (sponsor == '')  
          return;  
  
      if (hideTimer)  
          clearTimeout(hideTimer);  
  
      var pos = $(this).offset();  
      var width = $(this).width();  
      container.css({  
          left: (pos.left + width) + 'px',  
          top: pos.top - 5 + 'px'  
      });  
  
      $('#personPopupContent').html('&nbsp;');  
  
      $.ajax({  
          type: 'GET',  
          url: 'personajax.aspx',  
          data: 'page=' + pageID + '&sponsor=' + sponsor,  
          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 ' + sponsor + '.  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(sponsor) > 0)  
              {                    
                  var text = $(data).find('.personPopupResult').html();  
                  $('#personPopupContent').html(text);  
              }  
          }  
      });  
  
      container.css('display', 'block');  
  });  
  
  $('.personPopupTrigger').live('mouseout', function()  
  {  
      if (hideTimer)  
          clearTimeout(hideTimer);  
      hideTimer = setTimeout(function()  
      {  
          container.css('display', 'none');  
      }, hideDelay);  
  });  
  
  // Allow mouse over of details without hiding details  
  $('#personPopupContainer').mouseover(function()  
  {  
      if (hideTimer)  
          clearTimeout(hideTimer);  
  });  
  
  // Hide after mouseout   - Used on publications page
  $('#personPopupContainer').mouseout(function()  
  {  
      if (hideTimer)  
          clearTimeout(hideTimer);  
      hideTimer = setTimeout(function()  
      {  
          container.css('display', 'none');  
      }, hideDelay);
  });

      $("#formatting").click(function(event) {
          event.preventDefault();
          $("#box").slideToggle();
      });

      $("#box a").click(function(event) {
          event.preventDefault();
          $("#box").slideUp();
      });


  });
//used in home fragment
  function tick() {
      $('#ticker li:first').slideUp(function () { $(this).appendTo($('#ticker')).slideDown(); });
  }
  setInterval(function () { tick() }, 5000);

  function tick() {
      $('#ticker li:first').animate({ 'opacity': 0 }, 200, function () { $(this).appendTo($('#ticker')).css('opacity', 1); });
  }
  setInterval(function () { tick() }, 5000);

  function ShowHide(MyControl) {
      if (document.getElementById(MyControl).style.display == "none")
          document.getElementById(MyControl).style.display = "inline";
      else
          document.getElementById(MyControl).style.display = "none";
  }
  function SetChecked() {
      var frm = document.MainForm;
      var len = frm.elements.length;
      var i;
      var val;
      for (i = 0; i < len; i++) {
          if (frm.elements[i].name.indexOf('globalcheckbox') > -1)
              val = frm.elements[i].checked;
      }
      for (i = 0; i < len; i++) {
          if (frm.elements[i].name.indexOf('cbx_') > -1)
              frm.elements[i].checked = val;
      }
  }
//used on the billstatusreportperuser page
    $(document).ready(function () {
        $(function () {
            $(".bill").hover(function () {
                $(this)
                .addClass('pretty-hover')
                .stop(true)
                .next("div").show("fast");
            }, function () {
                $(this)
                .removeClass('pretty-hover')
                .stop(true)
                .next("div").hide("fast");
            });
        });
    });

