/*
 * jQuery cloud
 * 
 * Copyright (c) 2008 Łukasz Świerżewski
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * @version 1.0.0
 * @author Łukasz Świerżewski
 * @mailto lukasz at zirpe dot com
 */

jQuery.fn.extend({
 cloud: function(options) {
  return this.each(function() {
   new jQuery.Cloud(this, options);
  });
 }
});

jQuery.Cloud = function(o_element, am_options) {
 var options = am_options || {};
 var $o_cloud;

 init();

 $(o_element).bind('mouseover', function(e) {
  if (!$o_cloud) init();
  $o_cloud.css({left: e.pageX + 10 + 'px', top: e.pageY + 10 + 'px'}).show();
 }).bind('mouseout', function(e) {
  $o_cloud.hide();
 }).bind('mousemove', function(e) {
  $o_cloud.css({left: e.pageX + 10 + 'px', top: e.pageY + 10 + 'px'});
 });

 function init() {
  if (!options.head || !options.text) {
   if ($(o_element).attr('abbr')) {
    var as_data = ($(o_element).attr('abbr')).split('||');
    options.head = as_data[0];
    options.text = as_data[1];
   }
  }

  $o_cloud = $('<div class="cloud'+((options.cls) ? ' '+options.cls : '')+'">'+((options.head) ? '<div class="head'+((options.text) ? '' : ' withoutText')+'">'+options.head+'</div>' : '')+((options.text) ? '<div class="text'+((options.head) ? '' : ' withoutHead')+'">'+options.text+'</div></div>' : '')).hide().css({position: 'absolute', zIndex: (parseInt($(o_element).css('zIndex')) || 0)+2}).appendTo($(document.body));
 }

};