/**
 * jQuery :: Popup window
 *
 * @version  1.01
 * @date     2010-04-28
 * @author   Christian Oellers
 * @contact  veryshort@gmx.de
 *
 * Based on a script written by
 * Alen Grakalic (http://cssglobe.com).
 *
 * REQUIREMENTS
 * - jQuery 1.4.2
 *
 * FEATURES
 * - Displays a popup window on element hover
 *   with custom CSS-formatted text.
 *
 * TODO
 * - Convert to native jQuery function
 *   with more public accessible properties.
 */
jQuery.noConflict();
jQuery(document).ready(function($)
{
   var elPopup             = 'popup';      // Element ID of the appended popup DIV.
   var elHoverable         = 'li.partner'; // Hover over this element to show the popup.
   var elHoverableContent = '.text';       // Child element of hoverable with popup-content.
   var offsetX              = 0;           // Horizontal offset from cursor (positive values shift to left).
   var offsetY              = -30;         // Vertical offset from cursor (negative values shift to bottom).
   var centerOnX            = true;        // Ignore horizontal offset and center the popup.
   var fadeSpeed            = 'fast';      // Popup-Fade-in speed.

   /**
    * Hover over this element to display
    * a popup with child elements content.
    *
    * Leaving element will remove the popup.
    */
   $(elHoverable).hover(function(e)
   {
      $('body').append('<div id="' + elPopup + '"' + $(elHoverableContent, this).html() + '</div>');
      $('#' + elPopup).css({'display':'none'}).fadeIn(fadeSpeed);
   },
   function()
   {
      $('#' + elPopup).remove();
   });

   /**
    * Reposition popup on mouse move.
    */
   $(elHoverable).mousemove(function(e)
   {
      offsetX = centerOnX ? offsetX = $('#' + elPopup).width() / 2 : offsetX;

      $('#' + elPopup)
      .css
      ({
         'left' : (e.pageX - offsetX) + 'px',
         'top'  : (e.pageY - offsetY) + 'px'
      });
   });
});

