updateProgress();

function LayoutRenderer() {

    this.render = render;
    this.update = update;
    this.getMainContent = getMainContent;
    this.highlightNextButton = highlightNextButton;
    this.resetNextButton = resetNextButton;
    
    var mainContent = null;
    var mainDIV = document.getElementById("main");
    
    function getMainContent() {
    	return mainContent;
    }
    
    function resetNextButton() {
    	var nextButton = mainContent.getContentById("nextbutton");
		var enabled = engine.checkEnabled(nextButton);
		if (enabled) {
			if (nextButton.state == "highlighted") {
				nextButton.state = "default";
				nextButton.update();
			}
		}
		
    
    }
    
    function highlightNextButton() {
		var nextButton = mainContent.getContentById("nextbutton");
		var enabled = engine.checkEnabled(nextButton);
		if (enabled) {
			nextButton.state = "highlighted";
			nextButton.update();
		}
	}
	
    function render() {
        updateProgress();
		
		var xParser = new XParser(skinLayoutXmlDocument);
		
		var widthS = xParser.evaluateAttribute("/layout/main/size", "width");
		var heightS = xParser.evaluateAttribute("/layout/main/size", "height");
		if (widthS == "max") widthS = "-1";
		if (heightS == "max") heightS = "-1";
		
		var width = parseInt(widthS);
		var height = parseInt(heightS);
		
		//alert("### " + height + " x " + width);
		
		
		mainContent = new Container("main", 0, 0, width, height, false, true, false);
		var background = xParser.evaluateNodeValue("/layout/main/icon[@type='background']");
        var contentNodes = xParser.evaluate("/layout/main/content");
        
        utils.attachContents(mainContent, contentNodes, xParser);
        
        var html = mainContent.draw();
	    
	    mainDIV.innerHTML = html;
	    mainDIV.className = "main";
	    
	    window.onresize = layoutrenderer.update;
	    
	    
	    updateProgress();
		
		//tree = new Tree("tree", database.getStructures());
	    //tree.draw();
	    
	    mainlayer = document.getElementById(mainContent.id);
    	//mainlayer.style.background = "url(img/" + background + ")";
    	
    	
    	
    }
    
    function update() {
        //alert("update");
        var bodyTag = document.getElementsByTagName("body")[0];
        if (mainContent.vExpand == true) {
        	var height = parseInt(bodyTag.offsetHeight);
	    	mainContent.height = height;
	    }
	    if (mainContent.hExpand == true) {
	    	var width = parseInt(bodyTag.offsetWidth);
	    	mainContent.width = width
	    }
	    //mainContent.height = height;
	    //mainContent.width = width;
	    
	    //mainDIV.style.height = height;
	    //mainDIV.style.width = width;
	    
	    mainContent.update();
	    
	    //alert("size: " + width + " x " + height);
        
        
    }

}