/**
 * InlineBox.js		Date created: 6.04.2007
 * Copyright (c) 2007 Exadel Inc.
 * @author Denis Morozov <dmorozov@exadel.com>
 */
ClientUILib.declarePackage("ClientUI.common.box.SplashBox");

ClientUILib.requireClass("ClientUI.common.box.Box");
ClientUILib.requireClass("ClientUI.common.box.Substrate");

/**
 * Base class that wrap work with inline blocks like span
 */
ClientUI.common.box.SplashBox = Class.create({
	CLASSDEF: {
		name: 'ClientUI.common.box.SplashBox',
		parent: ClientUI.common.box.Box
	}
});

Object.extend(ClientUI.common.box.SplashBox.prototype, {

	initialize: function(text, parentElement, zIndex, supressSplash) {
		ClientUI.common.box.SplashBox.parentClass.constructor().call(this, null, parentElement);
		this.moveTo(-1000, -1000);
		this.zIndex = zIndex || 500;
		this.supressSplash = supressSplash || false;
		this.createControl(text);
		this.hide();
	},
	createControl: function(text) {
		this.element.setStyle({zIndex: this.zIndex});
		this.makeAbsolute();
		
		this.frame = new ClientUI.common.box.Substrate(null, this.getElement());
		this.frame.getElement().setStyle({zIndex: this.zIndex + 1});
		this.frame.getElement().setStyle({backgroundColor: "#FFFFFF"});
		this.frame.getElement().setStyle({border: "medium none"});
		this.frame.getElement().setStyle({opacity: "0"});
		this.frame.moveTo(0, 0);
		this.frame.setWidth(this.getWidth());
		this.frame.setHeight(this.getHeight());
		
		if(!this.supressSplash) {			
			this.div = new ClientUI.common.box.Box(null, this.getElement());
			this.div.getElement().setStyle({zIndex: this.zIndex + 2});
			this.div.getElement().setStyle({backgroundColor: "#000000"});
			this.div.getElement().setStyle({opacity: "0.6"});
			this.div.makeAbsolute();
			this.div.moveTo(0, 0);
			this.div.setWidth(this.getWidth());
			this.div.setHeight(this.getHeight());
			this.div.show();
		}

		this.text = new ClientUI.common.box.Box(text, this.getElement());
		this.text.setParent(this.getElement());
		this.text.getElement().setStyle({zIndex: this.zIndex + 100});
		if(!text)
			this.text.getElement().innerHTML = "<font size='4' color='white'>Loading...</font>";
		this.text.makeAbsolute();
		this.text.show();
		
	},
	setSize: function(width, height) {
		this.setWidth(width);
		this.setHeight(height);
		this.containerWidth = width;
		this.containerHeight = height;
	},
	setImage: function(image) {
		if(!this.img) {
			this.img = new ClientUI.common.box.Box($(document.createElement("img")), this.div.getElement());
			this.img.makeAbsolute();
		}		
		this.img.getElement().src = image;
		this.text.hide();
	},
	updateLayout: function() {
		var width = this.containerWidth||this.getWidth();
		var height = this.containerHeight||this.getHeight();

		this.frame.setWidth(width);
		this.frame.setHeight(height);
		
		if(!this.supressSplash) {
			this.div.setWidth(width);
			this.div.setHeight(height);		
		}
		
		if(this.img) {
			var x = width/2 - this.img.getWidth()/2;
			var y = height/2 - this.img.getHeight()/2;		
			this.img.moveTo(x, y);
		}
		else {
			var x = width/2 - this.text.getWidth()/2;
			var y = height/2 - this.text.getHeight()/2;		
			this.text.moveTo(x, y);
		}
	}
});
