﻿/*
 *  Extend the BeautyTips Plugin
 *  So that it will close after hovering
 *  off panel
 */

/*
 *  BT defaults for CPA
 */
(function($){
  var d=$.bt.defaults;
  d.closeWhenOthersOpen = true;
  d.padding = 0;
  d.width = 300;
  d.centerPointX = .9;
  d.spikeLength = 25;
  d.spikeGirth = 40;
  d.trigger = 'none';
  d.ajaxLoading = '<img style="margin:100px 150px 100px 140px" src="/lib/images/loading.gif" />';
  d.fill = '#fff';
  d.cssStyles = { minHeight: '100px' };
  d.strokeWidth = 0;
  d.strokeStyle = '';  
  d.shadow = true;
  d.shadowOffsetX = 2;
  d.shadowOffsetY = 5;
  d.shadowBlur = 10;
  d.shadowColor = "#000";  
  d.noShadowOpts = {
    strokeWidth: 1,
    strokeStyle: '#999'
  };
  d.postShow = function(){
    var elm=this;
    $('.bt-wrapper').hover(
      function(){},
      function(){elm.btOff();}
    );
    return;
  };
})(jQuery);

/*
 *  Extend basic BT
 */
jQuery.fn.btx = function(content,options) {
  // Straighten out arguments
  if (typeof content != 'string') {
    options = content;
    content = '';
  }
  
  // Walk through links and set up
  return this.each(function(){
    var opts=options;
    var lnk=$(this);
  
    // Build ajax link
    if (opts.ajaxPathAttr!=null)
      opts.ajaxPath = lnk.attr(opts.ajaxPathAttr);
    if (opts.ajaxPath!=null)
      opts.ajaxPath += ((opts.ajaxPath.indexOf("?")>0)?'&':'?') + 
        'btxt=' + Math.random();
  
    // Use BT with customized hover action
    lnk.bt(content,opts).hoverIntent({
      over: function(){this.btOn();},
      out: function(){},
      interval: 300,
      timeout: 200
    });
    
    // If click also, wire click
    if(opts.addClickEvent) lnk.click(function(){
      this.btOn();
      return false;
    });
  });
}

