jQuery.extend({
	WindowDefaults: { width:'520px', insert:'5px', window:'10px', opacity:0.7 },
	window: function(id, set) {
		set = jQuery.extend({},jQuery.WindowDefaults, set);
		var content = '<div class="windowbox" id="windowbox"><div class="windowfade" id="windowfade"></div><div style="width:500px" class="window" id="window"><div class="windowcontainer"><span class="windowclose"></span><iframe name="frame" id="frame" allowtransparency="true" scrolling="no" frameborder="0" marginwidth="0" marginheight="0" style="margin-top: 4px; width: 99%; height:380px;"></iframe></div></div></div>';
		var insert = $('#wrapper').append(content).children('#windowbox');
		$('iframe#frame').attr('src', '/display.html?id='+id);
		var box = insert.children('#window');
		var layer = insert.children('#windowfade');
		var ScrollWindow = function() {
			$(window).scroll(function() {
				if ($(window).scrollTop() > $('.content').offset({ scroll: false }).top) {
		   			$('.window').css('top', ($(window).scrollTop()-50) + 'px');
				}
				else {
					$('.window').css('top', '0px');
				}
			});
		};
		var FadeClicked = function() {
			RemoveWindow();
		};
		var PositionWindow = function() {
			var height = $('.content').height();
			var top = $(window).scrollTop();
			insert.css({ position: 'absolute', top: '90px', left: set.insert });
			layer.css({ position: 'absolute', height: height, width: set.width });
			box.css({ position: 'relative', top: (top > 0 ? top - 50 + 'px' : top), left: set.window });
		};
		var StyleWindow = function() {
			layer.css({ zIndex: '999', display: 'none', opacity: set.opacity });
			box.css({ zIndex: '1000', display: 'none' });
		};
		var ResizeFrame = function() {
			var innerDoc = (jQuery('iframe#frame').get(0).contentDocument) ? jQuery('iframe#frame').get(0).contentDocument : jQuery('iframe#frame').get(0).contentWindow.document;
			jQuery('iframe#frame').height(innerDoc.body.scrollHeight + 10);
		};
		var RemoveWindow = function(clicked, msg) {
			box.remove();
			layer.fadeOut('slow',function() {
				layer.unbind('click', FadeClicked);
				layer.remove();
				insert.remove();
			});
		};
		var ResizeWindow = function() {
			jQuery('iframe#frame').load(ResizeFrame);
		};
		PositionWindow();
		StyleWindow();
		ResizeWindow();
		ScrollWindow();
		layer.click(FadeClicked);
		box.find('.windowclose').click(RemoveWindow);
		layer.fadeIn('normal');
		box.fadeIn('normal');
		return insert;
	}
});
