/**
* Basic namespace framework for LN 2.0
* Should be included site-wide, available to every page.
**/

/* JavaScript "classes" (i.e. functions or Mootools classes) */
LIVENATION.page = {};
LIVENATION.module = {};

/* create namespaced object for instances of JavaScript clasess,
    e.g. for each instance of a particular module */
LIVENATION.instances = {
    page: {}
};

/*  begin example of instantiating classes
    FOR A PAGE:
        window.addEvent('domready', function(){
            LIVENATION.instances.page = new LIVENATION.page(LIVENATION.registry.page);
        });

    FOR A MODULE:
        window.addEvent('domready', function(){
            if($type(LIVENATION.registry.recommend) === 'array'){
                if ($type(LIVENATION.instances.recommend) !== 'array') {
                    LIVENATION.instances.recommend = [];
                }
                LIVENATION.registry.recommend.each(
                    function(item){
                        LIVENATION.instances.recommend.push(
                            new LIVENATION.module.recommend(item)
                        );
                    }
                );
            }
        });

    end example of instantiating classes */

/* custom global functions
    e.g.
        LIVENATION.global.display_message = function(message) { alert(message); } */
LIVENATION.global = {
    log: function(message){ // deprecated by dbug.log()
        if(window.console){
            console.log(message);
        }
    }
};

/* Live Nation text blocks */
LIVENATION.text = {};

Element.implement({

    // toggles the display of a given element.  If the element is not displayed
    // it will display the element, and vice versa.
    'toggle_displayed' : function(){
        if (this.hasClass('display_none')){
            this.removeClass('display_none');
        } else {
            this.addClass('display_none');
        }
    },

    // will display an element
    'display' : function(){
        this.removeClass('display_none');
    },

    // sill hide a given element
    'undisplay' : function(){
        this.addClass('display_none');
    },

    // set a size limit for an imput field
    'limit_text_area' : function(length){
        var self = this;
        var limit_length = function(event){
            self.set('value', self.get('value').substr(0,length));
        }
        this.addEvents({
            'keyup' : limit_length,
            'change' : limit_length
        });
    }

});

if (LIVENATION.config.debug) {dbug.enable();}
