

var CLUETIP_GFX_URL = BOS_SYSTEM_CSS_URL+'/default/jquery.cluetip.gfx/';

var CLUETIP_DEFAULT_SETTINGS = {
  hoverIntent: {
    sensitivity:   1,
    interval:      250,
    timeout:       250
  },
  width:           160,
  splitTitle:      '|',
  showTitle:       false,
  waitImage:       true,
  activation:      'hover',  // set to 'click' to force user to click to show clueTip
  // set to 'focus' to show on focus of a form element and hide on blur
  clickThrough:    true,     // if true, and activation is not 'click', then clicking on link will take user to the link's href,
  // even if href and tipAttribute are equal
  cursor:          'pointer',
  cluetipClass:    'bos',
  //hoverClass:      'highlightHover',
  arrows:          true,
  dropShadow:      false,     // set to false if you don't want the drop-shadow effect on the clueTip
  dropShadowSteps: 0,        // adjusts the size of the drop shadow
  //positionBy:      'auto',
  positionBy:      'bottomTop',
  fx: {
    open:       'fadeIn', // can be 'show' or 'slideDown' or 'fadeIn'
    openSpeed:  '400'
  }
};

/* the next line is an example of how you can override default options globally (currently commented out) ... */
// $.fn.cluetip.defaults.tracking = true;
// $.fn.cluetip.defaults.width = 'auto';

$(document).ready(function() {

  //default theme
  var stSelector = '*[title!=""]';
  _enableDefaultTooltip(stSelector);
  
  stSelector = '[title].tt_sticky';
  _enableStickyTooltip(stSelector);
  
  return false;
});


function _enableDefaultTooltip(stSelector){
  if(stSelector == '') stSelector = '*[title!=""]';
  _fillupTitles(stSelector);
  $(stSelector).cluetip(CLUETIP_DEFAULT_SETTINGS);
}

function _enableStickyTooltip(stSelector){
  if(stSelector == '') stSelector = '[title].tt_sticky';
  var mpStickySettings = CLUETIP_DEFAULT_SETTINGS;
  mpStickySettings.sticky = true;
  mpStickySettings.closePosition = 'title';
  mpStickySettings.arrows = true;
  mpStickySettings.closeText =  '<span class="icon size_16 icon_action_close"><img class="icon_space" src="'+BOS_SPACE_GIF_URL+'" alt="[lang_close]" title="[lang_close]"></span>';
  _fillupTitles(stSelector);
  $(stSelector).cluetip(mpStickySettings);
}


function _fillupTitles(stSelector){
  
  var stIcon = '<span class="icon size_16 icon_info"><img class="icon_space" src="'+BOS_SPACE_GIF_URL+'" alt="'+BOS_TOOLTIP_DEFAULT_TITLE+'" title="'+BOS_TOOLTIP_DEFAULT_TITLE+'"></span>';
  
  $(stSelector).each(function(){
    var stTitle = $(this).attr('title').toString();

    if(typeof stTitle == 'undefined') return false;
    if(stTitle == ' ') return false;
    if(stTitle == '') return false;
    if(stTitle.length == 0) return false;

    if(stTitle.indexOf("|")<0){
      stTitle = BOS_TOOLTIP_DEFAULT_TITLE + '|' + stTitle;
    }

    if(stTitle.indexOf(stIcon)<0){
      stTitle = stIcon + stTitle ;
    }

    $(this).attr('title', stTitle );
  });
  
  return false;
}