jQuery.fn.extend({
  showHide: function(){
    //change toggle to hover if we want "on hover" event  to reveal the categories
  this.hover(
          //make sure that z-index is more than the facebox z-index
          function() {$("ul", this).show().css("z-index","101");},
          function() {$("ul", this).hide().css("z-index","1");}
        )
  }
});

$(function(){
  $(".overlayDivOffsetRight").showHide();
  $(".overlayDiv").showHide();

  $('.fci-delete').click(function(){
    return confirm('Delete requested!\nAre you sure?');
  });

  $('input:checkbox').checkbox({cls:'jquery-safari-checkbox'});

  BT_setOptions({openWait:250});

/*
  $('.fci-tipit').each(function(i) {
    var selectedElement = $(this);
    selectedElement.after('&nbsp;<span class="fci-tooltip" title="' + selectedElement.attr('title') + '">?<span>');
  });

  $('.fci-tooltip').cluetip({
    splitTitle: '|',
    arrows: true,
    cursor:'pointer'
  });
*/

  $(".fci-printButton").click(
      function(){
        $(this).toggle();
        print();
      }
  );

//  var timeoutCall;
//  $('#_fci_recentItems li img').mouseover(
//    function() {
//      clearTimeout(timeoutCall);
//      $.facebox("<img src='" + this.src + "'/>" + "&nbsp;" + this.title);
//      timeoutCall = setTimeout(function() {$.facebox.close();}, 5000);
//    }
//  );

  $('.fci-stripe tr:not(.fci-inactive-record):even').addClass('fci-alt');
  $('.fci-stripe tr')
      .mouseover(function() {$(this).addClass('fci-over');})
      .mouseout(function() {$(this).removeClass('fci-over');});

  $('a[rel*=facebox]').facebox();
  $('.fci-facebox').facebox();
  $(".tablesorter").tablesorter();

/*
  $("#_fci_recentItems a").hover(function() {
		$(this).next("div").animate({opacity: "show", top: "-105"}, "fast");
	}, function() {
		$(this).next("div").animate({opacity: "hide", top: "-85"}, "fast");
	});
*/
});

function hideAndDisplay(hide, display) {
  $(hide).hide();
  $(display).show();
  return false;
}

$(function () {
  var bubbleInfo = '.fci-bubbleInfo';
  var triggerObject = '.fci-bubbleTrigger';
  var popupObject = '.fci-bubblePopup';
  $(bubbleInfo).each(function () {
    // options
    var distance = 10;
    var time = 250;
    var hideDelay = 1;

    var hideDelayTimer = null;

    // tracker
    var trigger = $(triggerObject, this);
    var popup = $(popupObject, this).css('opacity', 0);

    // set the mouseover and mouseout on both element
    $([trigger.get(0), popup.get(0)]).mouseover(function () {
      // stops the hide event if we move from the trigger to the popup element
      if (hideDelayTimer) clearTimeout(hideDelayTimer);

      // don't trigger the animation again if we're being shown, or already visible
      if (popup.is(':animated,:visible')) {
        return;
      } else {
        // reset position of popup box
        popup.css({
          top: -100,
          left: 0,
          display: 'block' // brings the popup back in to view
        })

        // (we're using chaining on the popup) now animate it's opacity and position
        .animate({
          top: '-=' + distance + 'px',
          opacity: 1
        }, time, 'swing');
      }
    }).mouseout(function () {
      // reset the timer if we get fired again - avoids double animations
      if (hideDelayTimer) clearTimeout(hideDelayTimer);

      // store the timer so that it can be cleared in the mouseover if required
      hideDelayTimer = setTimeout(function () {
        hideDelayTimer = null;
        popup.animate({
          top: '-=' + distance + 'px',
          opacity: 0
        }, time, 'swing', function () {
          // hide the popup entirely after the effect (opacity alone doesn't do the job)
          popup.css('display', 'none');
        });
      }, hideDelay);
    });
  });
});