function Configurator() {
	this.products = new ProductList();
	this.selection = new SelectionList();
	this.page3 = new Page3();
	this.page4 = new Page4();
	this.page5 = new Page5();
	this.panel = new Panel();
	this.semaphore = new Semaphore();
	this.currentPage = null;
	this.switchingPage = false;

	Configurator.prototype.load = function() {
		Loader.show("Nahrávám aplikaci...");
		for (var i = 0; i < Config.preloadImages.length; i++) {
			var image = document.createElement("IMG");
			image.src = Config.preloadImages[i];
			image.style.display = "none";
			document.body.appendChild(image);
		}
		window.onload = delegate(this, this.loadProducts);
	};

	Configurator.prototype.loadProducts = function(withConfiguration) {
		Loader.hide();
		if (Config.loadConfiguration) {
			this.products.onLoad = delegate(this, this.loadConfiguration);
		}
		else {
			this.products.onLoad = delegate(this, this.start);
		}
		this.products.load(Config.productsUrl);
	};
	
	Configurator.prototype.loadConfiguration = function() {
		this.selection.onLoad = delegate(this, this.start);
		this.selection.load(Config.configurationUrl);
	};

	Configurator.prototype.start = function() {
		if (Config.intranetMode) {
			document.body.className = "intranet";
		}
		if (Config.intranetMode) {
			c.panel.setUser(c.selection.user);
			c.semaphore.update();
		}
		this.changePage(this.page3);
	};
	
	Configurator.prototype.changePage = function(page) {
		if (this.currentPage != null) {
			this.currentPage.leave();
		}
		Warning.hide();
		Error.hide();
		this.currentPage = page;
        this.request = new AjaxRequest();
		this.request.onSuccess = delegate(this, this.earsuccess);
		this.request.onFailure = delegate(this, this.earfailure);
		this.request.get("ear.jsp?page=" + page.id);
		this.currentPage.enter();
	};

    Configurator.prototype.earsuccess = function() {
	};

    Configurator.prototype.earfailure = function() {
	};


	Configurator.prototype.showPanel = function() {
		this.panel.show();
	};

	Configurator.prototype.hidePanel = function() {
		this.panel.show();
	};

}


