/*********************************************
rock.js 
Creates Rock runtime - rock.
Also contains convenient methods.
Depends on: rock-utils.js, prototype.js.
**********************************************/
var _rockGlobalScope = this;

if (!rock) {
    var rock = new Rock();  
}

function Rock(){
    this.version = "1.0.0";
	
    /**
     * Create a namespace with the given path.
     */
    this.namespace = function(_path) {
        // get the top level object
        var paths = _path.split('.');
        var _obj = _rockGlobalScope[paths[0]];
        for (var ii = 1; ii < paths.length; ii++) {
            if (typeof _obj[paths[ii]] != 'undefined' ) {
                _obj = _obj[paths[ii]];                                       
            } else {
                _obj[paths[ii]] = {};
                _obj = _obj[paths[ii]];
            }
        }
        
        return _obj;
    }	        

    this.insertErrorMsg = function(errorHtml, container){
	//jmaki.log("insertErrorMsg: " + errorHtml);
	this.showErrorMsg(errorHtml, container, false);  // inserted (not appended)
    }		
    
    /**
     * Show error message in a container element.
     */
    this.showErrorMsg = function(errorHtml, container){
	this.showErrorMsg(errorHtml, container, false); // inserted
    }	

    this.showErrorMsg = function(errorHtml, container, appended){
	jmaki.log("rock.js/showErrorMsg: " + errorHtml);
	rock.util.DomUtil.showLabel(errorHtml, container, "error", appended);
    }	

    /**
     * Hide error message in a container element.
     */
    this.hideErrorMsg = function(container){
	rock.util.DomUtil.hideLabel(container, "error");
    }	
    /**
     * Show loading/waiting message in a container element. 
     * The loading element is the 1st child of the container element. 
     * It's is a div element with classname "loading". It has
     * a nested span element that contains the message text.
     * If not exit, the loading elememt is created and inserted 
     * before the container's 1st child.
     */	    
    this.showLoadingMsg = function(msgHtml, container){
	rock.util.DomUtil.showLabel(msgHtml, container, "loading", false);
    }   	   

    this.hideLoadingMsg = function(container){
	rock.util.DomUtil.hideLabel(container, "loading");
    }   	   


    /**
     * Dynamically show a loading/waiting spinning icon in a container element. 
     * The loading element is the last child of the container elmeent. 
     * It is an img element with classname "loading_icon".
     */	    
    this.showLoadingIcon = function(container){
	rock.util.DomUtil.showIcon(container, 
				   true, //true - appended as last 
				   "loading_icon", 
				   "images/wait.gif");  
    }   	   

    this.hideLoadingIcon = function(container){
	rock.util.DomUtil.hideIcon(container, "loading_icon");
    }   	   
	 
}

