var undefined;

var overlay = function(options) {

	var self = this;
	
    var settings = $JQ.extend({
      title: "Overlay",
      id: "overlay",
      width: 600
    }, options);

    
    var $html = $JQ('<div class="overlay"><div id="close-overlay">CLOSE</div><div id="' + settings.id + '-content" class="overlay-content"></div></div>');
    $html.attr("id", settings.id);
    //$html.css({width: settings.width});
	$JQ("body").append($html);
	$JQ("body").append('<div id="overlay-blocker"><div id="overlay-loading"></div></div>');

	var $overlayBlocker = $JQ("#overlay-blocker");
	$overlayBlocker.css({height: $JQ(document).height()});
	//$overlayBlocker.add("#overlay-blocker iframe").css({height: $JQ(document).height()});
	var $overlay = $JQ("#" + settings.id);
	var $overlayContent = $JQ("#" + settings.id + "-content");
	$JQ("#overlay-loading").css({top: (($JQ(window).height() - 52) / 2) + $JQ(window).scrollTop(), left: (($JQ(window).width() - 52) / 2)});

	this.div = $overlayContent;
	this.divBlocker = $overlayBlocker;

    this.show = function() {
	
	  $JQ("#overlay-loading").remove();
	
      var viewportHeight = $JQ(window).height();
      var overlayHeight = $overlay.height();
      var centerY = ((viewportHeight - overlayHeight) / 2) + $JQ(window).scrollTop();

      if(centerY < 17) 
          centerY = 17;

      var viewportWidth = $JQ(window).width();
      var overlayWidth = $overlay.width();
      var centerX = (viewportWidth - overlayWidth) / 2;

      $overlay.css({top: centerY, left: centerX});
      $overlay.fadeIn('slow');
	  
	  $overlay.bind('click', function() {
		 self.hide(); 
	  });
	  
	  $overlayBlocker.bind('click', function() {
		 self.hide();	 
	  });
	  
	  $JQ.ASME.mainContentDiv.find('object').hide();
	  
    }

    this.hide = function() {
      $overlayContent.html("");
      $overlay.remove();
      $overlayBlocker.remove();
      $JQ.ASME.mainContentDiv.find('object').show();
    }

    this.setContent = function(content) {
      $overlayContent.html(content);
    }
	
	this.appendContent = function(content) {
		self.div.append(content);	
	}

}
