/**
 * brand.progress
 * Class: Swap content with progress indicator while something loads
 * @memberOf brand
 */ 
brand.progress = Class.create(
{
    progressNode: null, // node to show on progress start
    containerNode: null, // node to hide on progress start 

    /**
     * brand.progress.initialize
     * Method for creating an instance of brand.progress
     * @returns An instance of brand.progress
     * @param {DOM Node} args.containerNode  Node object of content to hide during progress (Required: either args.containerNode or args.containerId)
     * @param {String} args.containerId  Id of content node to hide during progress
     * @param {DOM Node} args.progressNode  Node object containing progress indicator to show during progress (Required: either args.progressNode or args.progressId)
     * @param {String} args.progressId  Id of node containing progress indicator to show during progress
     * @param {Boolean} *Optional* args.matchDimensions Set to true if progress indicator content should automatically set its dimensions to match the content being hidden
     * @example
        var progress = new brand.progress({
            containerNode: swatchSet.domNode,
            progressNode: searchNodes.container.select('.progress')[0]
        }); 
     * @methodOf of brand.progress
     */    
    initialize: function(/* Object */args) {
        brand.updateProperties.apply(this, [args]);
        this.containerNode = (args.containerNode ? args.containerNode : $(args.containerId));
        this.progressNode = (args.progressNode ? args.progressNode : $(args.progressId));
        if (args.matchDimensions) {
            this._setDimensions();
        }
    },
    
    start: function() {
        if (!this.progressNode || !this.containerNode) { return; }
        this.containerNode.style.display = "none";
        this.progressNode.style.display = "block";
    },
    
    clear: function() {
        if (!this.progressNode || !this.containerNode) { return; }
        this.containerNode.style.display = "block";
        this.progressNode.style.display = "none";
    },

    // for errors and user messages
    showMessage: function(args) {
        if (!this.progressNode) { return; }
        this.progressNode.style.display = "none";
        var messageNode = args.messageNode;
        if (messageNode && args.message) {
            messageNode.update(args.message);
            messageNode.show();
        }
        if (!args.hideContainer && this.containerNode) {
            this.containerNode.style.display = "block";
        }
    },
    
    _setDimensions: function() { 
        this.progressNode.style.width = this.containerNode.getWidth() + "px";
        this.progressNode.style.height = this.containerNode.getHeight() + "px";    
    }
});

/**
 * brand.progressOverlay
 * Class: Display progress indicator as an overlay
 * @memberOf brand
 */
brand.progressOverlay = Class.create (brand.progress, 
{

    // summary:
    //      Progress overlay
    
    offset: {w: 0, h: 0},

    /**
     * brand.progressOverlay.initialize
     * Method for creating an instance of brand.progressOverlay
     * @returns An instance of brand.progressOverlay
     * @param {String} args.containerId  Id of content node to hide during progress
     * @param {String} args.progressId  Id of node containing progress indicator to show during progress
     * @param {Object} args.offset  width & height offset for dimensions of overlay
     * @example
        var progress = new generic.progressOverlay({
            containerId: "address-container",
            progressId: "progress-address-container",
            offset: {w: 10, h: 10}
        }); 
     * @methodOf of brand.progress
     */    
    initialize: function(/* Object */args) {
        this.containerNode = $(args.containerId);
        this.progressNode = $(args.progressId);
        if (args.offset) {
            this.offset = args.offset;
        }
        
        // set dimensions 
        this.progressNode.style.width = (this.containerNode.getWidth() + this.offset.w) + "px";
        this.progressNode.style.height = (this.containerNode.getHeight() + this.offset.h) + "px";
    },
    
    start: function() {
        if (!this.progressNode) { return; }
        this.progressNode.style.display = "block";
    },
    
    clear: function() {
        if (!this.progressNode) { return; }
        this.progressNode.style.display = "none";
    }
});
