$.window = function(options) {
  var defaults = {
    overlayOpacity : 0.25,
    width: 800,
    height: 600,
    border: "1px solid #AEAEAE",
    overflowX: 'hidden',
    overflowY: 'hidden',
    backgroundColor: '#FFFFFF',
    title : '',
    header: false,
    close: false
	};

	options = jQuery.extend(defaults, options);

  if ($("body > .overlay").length == 0) {
    $("body").overlay({
      opacity: options.overlayOpacity,
      bgColor: options.overlayColor
    });
  }

  var html = "";

  html += '<div class="window" style="margin-top: -'+ ((options.height + (options.header?33:0)) / 2 + 1) +'px; margin-left: -'+ (options.width / 2 + 1) +'px; ">';
  html += '<div class="window-container" style="'+ ((options.backgroundColor != "transparent")?'background-color: '+ options.backgroundColor +'; ':'') + ((options.backgroundColor != "transparent")?'border: '+ options.border +'; '+ ((options.header)?'border-top: none; ':''):'') +'width: '+options.width+'px;">';

  if (options.header) {
    html += '<div class="window-header">'+ ((options.close)?'<div class="window-close"><img src="/etc/plugins/jquery/window/images/close.png" alt="close" /></div>':'') + options.title +'</div>';
  }

//  if (!options.modeless) {
//    html += '<div class="header' + ((options.modeless)?' modeless':'') + '"><div class="close" style="margin-left: '+(options.width - (32))+'px;"><img src="/images/jquery/window/close.png"  width="16" height="16" /></div>'+ options.caption +'</div>';
//  }

  //html += '<div class="body">';
  html += '<iframe'+ ((options.backgroundColor == "transparent")?' ALLOWTRANSPARENCY':'') +' scrolling="no" frameborder="0" src="'+ options.src +'" style="overflow: '+ ((options.overflowX == 'visible' || options.overflowY == 'visible')?"visible":"visible") +'; overflow-x: '+ options.overflowX +'; overflow-y: '+ options.overflowY +'; width: '+ options.width +'px; height: '+ options.height +'px;"></iframe>';
  //html += '</div>';
  html += '</div>';
  html += '</div>';

  $("body").prepend(html);

  $(".window-close img").bind("click", function() {
    $.window.hide();
  });
};

$.window.hide = function() {
  var destination = top.document ? top.document : document.body;

//  $("body > .overlay", destination).overlayHide({fade : true, fadeSpeed : 500});
  $("body > .overlay", destination).overlayHide();

  $.window.remove();
}

$.window.checkAnimation = function() {
  var destination = top.document ? top.document : document.body;

  return $(":animated", destination).length;
}

$.window.remove = function() {
  var destination = top.document ? top.document : document.body;

  if ($.window.checkAnimation() == 0) {
    clearTimeout(timeout);

    $("body > .window", destination).remove();
  } else {
    var timeout = setTimeout(function() {
      $.window.remove();
    }, 10);
  }
}

$.window.parent = top.document;