
var DisplayLock = Class.create();

DisplayLock.prototype =
{
	initialize: function(option)
	{
		if (option == undefined) {
			option = new Object();
		}
	
		var zIndex = option.zIndex;
	
		if (zIndex == undefined) {
			zIndex = 99999;
		}
		
		this.filter = document.createElement('div');
		this.filter.style.position = 'absolute';
		this.filter.style.zIndex = zIndex;
		Element.addClassName(this.filter, 'display_lock');

		this.image = new Image();
//		this.image.style.position = 'absolute';
//		this.image.style.zIndex = zIndex + 1;
		this.image.src = option.image;
		this.image.style.display = 'none';

		this.imageBox = document.createElement('div');
		this.imageBox.style.position = 'absolute';
		this.imageBox.style.zIndex = zIndex + 1;
		this.imageBox.style.width = this.image.width + 'px';
		this.imageBox.style.height = this.image.height + 'px';
		this.imageBox.style.backgroundImage = 'url(' + option.image + ')';
		
		this.filter.appendChild(this.image);

		if (option.trigger == undefined) {
			for (var i = 0; i < window.document.forms.length; i++) {
				Event.observe(window.document.forms[i], 'submit', this.lock.bind(this, window.document.forms[i]));
			}
		}
		else {
			Event.observe(option.trigger, 'click', this.lock.bind(this));
		}
	},
	
	lock: function()
	{
		window.document.getElementsByTagName('body')[0].appendChild(this.filter);
		window.document.getElementsByTagName('body')[0].appendChild(this.imageBox);
		
		this._lock();
		
		Event.observe(window, 'resize', this._lock.bind(this));
		Event.observe(window, 'scroll', this._lock.bind(this));
	},
	
	_lock: function()
	{
		var left = (document.documentElement.scrollLeft || document.body.scrollLeft);
		var top = (document.documentElement.scrollTop || document.body.scrollTop);
		
		var width = 0;
		var height = 0;

		if (window.innerWidth) {
			width = window.innerWidth;
		}
		else if (document.documentElement && document.documentElement.clientWidth != 0) {
			width = document.documentElement.clientWidth;
		}
		else if (document.body) {
			width = document.body.clientWidth;
		}
	
		if (window.innerHeight) {
			height = window.innerHeight;
		}
		else if (document.documentElement && document.documentElement.clientHeight != 0) {
			height = document.documentElement.clientHeight;
		}
		else if (document.body) {
			height = document.body.clientHeight;
		}

		this.filter.style.left = left + 'px';
		this.filter.style.top = top + 'px';
		this.filter.style.width = width + 'px';
		this.filter.style.height = height + 'px';
		
		this.imageBox.style.left = (left + (width - this.image.width) / 2) + 'px';
		this.imageBox.style.top = (top + (height - this.image.height) / 2) + 'px';
	}
}