// jwOverlay plugin v0.0.9.0b for jQuery; free for all; writen by Jiri Wendl www.jiriwendl.cz
(function ($) {
  
  var lastId = 1;

  var jwoverlay_methods = {
    show: function (overlayContentClass) {
      //$(document.body).css("overflow", "hidden");

      if (overlayContentClass == undefined)
        overlayContentClass = "jw-overlay-content";

      var content = this.attr("id") + "-jwoverlaycontent";
      var container = this.attr("id") + "-jwoverlaycontainer";

      $("#" + content + ",#" + container).remove();
      var left = $(this).offset().left;
      var top = $(this).offset().top;
      var width = this.width();
      var height = this.height();

      $(document.body).append("<div class='ui-widget-overlay ui-corner-all' id='" + container + "' style='position: absolute; display: none; left: " + left + "px; top: " + top + "px; ; z-index: 1001;'></div>" + "<div class='" + overlayContentClass + "' id='" + content + "' style='position: absolute; display: none; left: " + left + "px; top: " + top + "px; " + "z-index: 1002;'></div>");
      $('#' + container).width(width);
      $('#' + container).height(height);
      $('#' + content).width(width);
      $('#' + content).height(height);
      $("#" + content + ",#" + container).fadeTo(0, 0).css("display", "block");
      $("#" + content + ",#" + container).fadeTo(100, 0.3, function () {
        $("#" + content).fadeTo(0, 1);
      });
    },
    hide: function () {
      var content = this.attr("id") + "-jwoverlaycontent";
      var container = this.attr("id") + "-jwoverlaycontainer";

      $("#" + content).fadeTo(0, $("#" + container).css("opacity"));
      $("#" + content + ",#" + container).fadeTo(100, 0, function () {
        $("#" + content + ",#" + container).remove();
      });
    }
  };

  $.fn.jwoverlay = function (method) {
    // Method calling logic
    if (jwoverlay_methods[method]) {
      return jwoverlay_methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
    } else if (typeof method === 'object' || !method) {
      return jwoverlay_methods.show.apply(this, arguments);
    } else {
      $.error('Method ' + method + ' does not exist on jQuery.tooltip');
    }
  };
})(jQuery);
