
Site.Mini = {

	wrap4 : null,
	wrap3 : null,
	wrap2 : null,
	wrap1 : null,
	div : null,
	iframe : null,

	open : function (url) {
	
		Site.Util.showLoading();
	
		if (this.div == null) {
			
			this.wrap4 = document.createElement('div');
			this.wrap4.id = 'mini-window-wrap4';
			this.wrap4.className = 'loading';
			
			this.wrap3 = document.createElement('div');
			this.wrap3.id = 'mini-window-wrap3';
			
			this.wrap2 = document.createElement('div');
			this.wrap2.id = 'mini-window-wrap2';
			
			this.wrap1 = document.createElement('div');
			this.wrap1.id = 'mini-window-wrap1';
			
			this.div = document.createElement('div');
			this.div.id = 'mini-window';
			
			this.iframe = document.createElement('iframe');
			this.iframe.setAttribute('scrolling', 'no');
			this.iframe.setAttribute('frameBorder', '0');
			this.iframe.style.height = '0';
			
			this.div.appendChild(this.iframe);
			this.wrap1.appendChild(this.div);
			this.wrap2.appendChild(this.wrap1);
			this.wrap3.appendChild(this.wrap2);
			this.wrap4.appendChild(this.wrap3);
			document.body.appendChild(this.wrap4);
			
		}else{
		
			this.wrap4.className = 'loading';
			
		}
		
		var Coordinates = ToolMan.coordinates();
		this.wrap4.style.top = Coordinates.scrollOffset().y + 'px';
		this.wrap4.style.height = Coordinates.clientSize().y + 'px';
		this.wrap4.style.display = 'block';
		
		this.iframe.src = Site.Util.addUrlParameters(url, 'mini');
		
	},
	
	_doneLoading : function(width, height, blackout) {
		this.wrap4.className = blackout ? 'blackout mini-window-wrap4-blackout' : 'shadowed';
		this.wrap3.style.width = width + 'px';
		this.iframe.style.height = height + 'px';
		var toolbar = document.getElementById('toolbar');
		Site.Util.hideLoading();
	},
	
	updateHeight : function(height) {
		this.iframe.style.height = height + 'px';
	},
	
	close : function() {
		this.wrap4.style.display = 'none';
		this.iframe.style.height = '0';
	},
	
	redirectParent : function(parentUrl, miniUrl, matchScroll) {
		var href;
		if (parentUrl && parentUrl.charAt(0)=='#') {
			href = Site.Util.removeUrlAnchor(window.location.href) + parentUrl;
		}else{
			href = parentUrl ? parentUrl : window.location.href;
		}
		href = Site.Util.removeUrlParameter(href, 'mu');
		if (matchScroll && !parentUrl) {
			href = Site.Util.removeUrlParameter(href, 'y');
			href = Site.Util.removeUrlAnchor(href);
			var y = ToolMan.coordinates().scrollOffset().y;
			if (y > 0) href = Site.Util.addUrlParameters(href, 'y='+y);
		}
		if (miniUrl) href = Site.Util.addUrlParameters(href, 'mu='+escape(miniUrl));
		window.location.href = href;
	}

}

