var onScreenWindow = function(options) {
	
	this.options = {
		maxWidth      : 600,
		maxHeight     : 300,
		zIndex        : 1000,
		zIndexOverlay : 999
	};
	
	if (typeof options !== 'undefined') {
		jQuery.merge(this.options,options);
	}
	
	this.window = jQuery('<div>')
		.attr('class','ScreenWindow')
		.css('position','absolute')
		.css('z-index',this.options.zIndex)
		.hide()
	;
	
	this.windowBody = jQuery('<div>')
		.attr('class','ScreenWindowBody')
	;
	
	this.window.html(this.windowBody);
	
	this.contentBox = jQuery('<div>')
		.attr('class','ScreenWindowContent')
	;
	
	this.windowBody.html(this.contentBox);
	
	this.overlay = jQuery('<div>')
		.attr('id','PageOverlay')
		.css('z-index',this.options.zIndexOverlay)
		.css('position','absolute')
		.css('top','0px')
		.css('left','0px')
		.fadeTo(0,0.85)
	;
	
	jQuery(document.body).append(this.overlay);
	jQuery(document.body).append(this.window);
	
	/**
	 * set the content of the window
	 */
	this.setContent = function(content) {
		this.contentBox.html(content);
	};
	
	/**
	 * show the window
	 */
	this.show = function() {
		jQuery.when(this.window.show()).then(this.position());
	};
	
	/**
	 * show the window
	 */
	this.hide = function() {
		this.window.hide();
	};
	
	/**
	 * center and size the Window
	 */
	this.position = function() {

		// window
		var screenWidth  = jQuery(document.body).width();
		var screenHeight = jQuery(document.body).height();
		
		var windowWidth  = Math.min(this.window.width() ,this.options.maxWidth);
		this.window.css('width',parseInt(windowWidth)  + "px");
		
		var windowHeight = Math.min(this.window.height(),this.options.maxHeight);
		this.window.css('height',parseInt(windowHeight)  + "px");
		this.window
			.css('left', parseInt((screenWidth-windowWidth)/2)+jQuery(document).scrollLeft()   + "px")
			.css('top',  parseInt((screenHeight-windowHeight)/2)+jQuery(document).scrollTop() + "px")
		;
		
		//overlay
		this.overlay
			.css('width',parseInt(Math.max(jQuery(document.body).width(),jQuery(document).width()))+"px")
			.css('height',parseInt(Math.max(jQuery(document.body).height(),jQuery(document).height()))+"px")
		;
	};
	
	if (typeof options !== 'undefined') {
		if (typeof options.id != 'undefined') {
			this.window.attr('id',options.id);
		}
		if (typeof options.content != 'undefined') {
			this.setContent(options.content);
		}
	};
	
	jQuery(window).resize(jQuery.proxy(this.position,this));
	jQuery(window).scroll(jQuery.proxy(this.position,this));
}
