var loader = '';

function Loader() {
	this.target = '';
	this.isWalled = false;
	this.ids = {
		'wall'		: 'uploader_wall',
		'content'	: 'uploader_content'
	};
	this.blWall = null;
	this.blContent = null;
	this.blClose = null;
	var self = this;
	this.load = function(target) {
		this.setBlocks();
		this.setWall();
		this.setContent('<div style="margin:20px;">Личный кабинет находится в разработке</div>');
		this.show();
	}
	this.show = function() {
		if (!this.blWall||!this.blContent) return false;
		this.blWall.style.display = 'block';
		this.blContent.style.display = 'block';
		self.resizeContent();
	}
	this.setBlocks = function() {
		if (document.getElementById(this.ids['wall'])) {
			this.blWall = document.getElementById(this.ids['wall']);
		} else {
			this.blWall = document.createElement('iframe');
			this.blWall.src = '/empty.html';
			this.blWall.id = this.ids['wall'];
			this.blWall.className = 'loader_wall';
			document.body.appendChild(this.blWall);
		}
		if (document.getElementById(this.ids['content'])) {
			this.blContent = document.getElementById(this.ids['content']);
		} else {
			this.blContent = document.createElement('div');
			this.blContent.id = this.ids['content'];
			this.blContent.className = 'loader_content';
			this.blContent = document.body.appendChild(this.blContent);
			// close button
			this.blClose = document.createElement('div');
			this.blClose.className = 'loader_close';
			this.blClose.onclick = this.close;
			this.blContent.appendChild(this.blClose);
		}
	}
	this.getSizes = function() {
		var w, h;
		if( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
			w = document.body.clientWidth;
			//w = window.innerWidth;
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			w = document.documentElement.clientWidth;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			w = document.body.clientWidth;
		}
		h = Math.max(
					 Math.max(document.body.scrollHeight, document.documentElement.scrollHeight),
					 Math.max(document.body.offsetHeight, document.documentElement.offsetHeight),
					 Math.max(document.body.clientHeight, document.documentElement.clientHeight)
					 );
		return {'w':w,'h':h};
	}
	this.getClientSizes = function() {
		var w = document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
		var h = document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
		return {'w':w,'h':h};
	}
	this.resizeWall = function() {
		if (self.blWall) {
			var s = self.getSizes();
			self.blWall.style.width = s['w']+'px';
			self.blWall.style.height = s['h']+'px';
		}
	}
	this.setWall = function() {
		if (!this.blWall) return false;
		this.resizeWall();
		this.blWall.style.display = 'block';
	}
	this.resizeContent = function() {
		if (!self.blContent) return false;
		var s = self.getClientSizes();
		var scroll = (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
		self.blContent.style.left = Math.round(s['w']/2-(self.blContent.offsetWidth/2))+'px';
		if (s['h']>self.blContent.offsetHeight) {
			self.blContent.style.top = (scroll+Math.round(s['h']/2-(self.blContent.offsetHeight/2)))+'px';
		} else {
			self.blContent.style.top = (scroll+50)+'px';
		}
		self.resizeWall();
	}
	this.setContent = function(content) {
		if (!self.blContent) return false;
		self.blContent.style.width = '300px';
		var bl = document.createElement('div');
		bl.innerHTML = content;
		self.blContent.appendChild(bl);
	}
	this.destroyWall = function() {
		if (this.blWall) {
			this.blWall.parentNode.removeChild(this.blWall);
		}
	}
	this.destroyContent = function() {
		if (this.blContent) {
			this.blContent.parentNode.removeChild(this.blContent);
		}
	}
	this.close = function() {
		self.destroyContent();
		self.destroyWall();
	}
	this.setEvents = function() {
		window.onresize = self.resizeWall;
	}
	this.init = function() {
		this.setEvents();
	}
	this.init();
}

loader = new Loader();
