// Create the tooltips only on document load
jQuery(document).ready(function() {
    ccTooltipInitialize(jQuery(document));
});

function ccTooltipInitialize(element)
{
  jQuery(element).find('.bubble-section-heading').each(function() {
    elementId = this.id;
    if (
      !_.isUndefined(descriptionToolTipArray[elementId]) &&
      !_.isUndefined(titleToolTipArray[elementId]) &&
      !_.isUndefined(descriptionToolTipArray) &&
      !_.isUndefined(titleToolTipArray)
    ) {

      jQuery(this).qtip({
        content: {
          text: descriptionToolTipArray[elementId],
          title: {
            text: titleToolTipArray[elementId]
          }
        },
        position: {
          corner: {
            target: 'bottomLeft',
            tooltip: 'topLeft'
          },
          adjust: {
            screen: true
          }
        },
        show: {
          when: 'mouseover',
          solo: true
        },
        hide: 'mouseleave',
        style: 'blue'
      });
    }
  });

  /////////////////////////////////////////////////////////////////////////////
  /////////////////////////////////////////////////////////////////////////////

  jQuery(element).find('.bubble_help').each(function() {
    elementId = this.id;
    if (
      !_.isUndefined(descriptionToolTipArray[elementId]) &&
      !_.isUndefined(titleToolTipArray[elementId]) && 
      !_.isUndefined(descriptionToolTipArray) &&
      !_.isUndefined(titleToolTipArray)
    ) {

      jQuery(this).qtip({
        content: {
          text: descriptionToolTipArray[elementId],
          title: {
            text: titleToolTipArray[elementId]
          }
        },
        position: {
          corner: {
            target: 'bottomLeft',
            tooltip: 'topLeft'
          },
          adjust: {
            screen: true
          }
        },
        show: {
          when: 'mouseover',
          solo: true
        },
        hide: 'mouseleave',
        style: 'blue'
      });
    }
  });

  /////////////////////////////////////////////////////////////////////////////
  /////////////////////////////////////////////////////////////////////////////

  jQuery(element).find('.bubble_user').each(function() {
    jQuery(this).qtip({
      content: {
        text: jQuery(this).find('.bubble-content').html(),
        title: {
          text: jQuery(this).find('.bubble-title').html()
        }
      },
      position: {
        corner: {
          target: 'bottomLeft',
          tooltip: 'topLeft'
        },
        adjust: {
          screen: true
        }
      },
      show: { 
        when: 'mouseover',
        solo: true
      },
      hide: 'unfocus',
      style: 'cream'
    });
  });

  /////////////////////////////////////////////////////////////////////////////
  /////////////////////////////////////////////////////////////////////////////

  jQuery(element).find('.bubble_message').each(function() {
    jQuery(this).qtip({ 
      content: { 
        text: jQuery(this).find('.bubble-content').html(),
        title: { 
          text: jQuery(this).find('.bubble-title').html() 
        }
      },
      position: { 
        corner: { 
          target: 'bottomLeft', // Position the tooltip above the link
          tooltip: 'topLeft'
        },
        adjust: { 
          screen: true // Keep the tooltip on-screen at all times
        }
      },
      show: { 
        when: 'mouseover',
        solo: true // Only show one tooltip at a time
      },
      hide: 'mouseleave',
      style: 'blue'
    });
  });

}

// vim: set et ts=2 sw=2 sts=2:

