/*
Class: Mindscape.hub
  A class that provides an isolation and communication for modules in the Mindscape JavaScript application architecture framework.
*/
Mindscape.hub = Mindscape.hub || {

    /*
    Constructor: create
    The constructor function for creating hubs.

    Parameters:
    core - The object that is an instance of Mindscape.core.
    moduleSelector - The string that identifies the module's container DOM element.
    */
    create: function (core, moduleSelector) {
        var container = Mindscape.dom.find(moduleSelector);

        return {
            /*
            Property: container
            The property for storing the container DOM element.
            */
            container: container,

            /*
            Function: find
            The function for finding module DOM elements. Delegates to Mindscape.dom.find which delegates to jQuery().find.

            Parameters:
            selector - The string that identifies the DOM elements.

            See:
            <Mindscape.dom.find>
            */
            find: function (selector) {
                return container.find(selector);
            },

            /*
            Function: bind
            The function for binding event functions to DOM elements. Delegates to Mindscape.dom.bind which delegates to jQuery().bind.

            Parameters:
            element - The DOM element to bind to.
            event - The event to bind to.
            func - The function to bind.

            See:
            <Mindscape.dom.bind>
            <unbind>
            */
            bind: function (element, event, func) {
                Mindscape.dom.bind(element, event, func);
            },

            /*
            Function: unbind
            The function for unbinding event functions from DOM elements. Delegates to Mindscape.dom.unbind which delegates to jQuery().unbind.

            Parameters:
            element - The DOM element to unbind from.
            event - The event to unbind from.
            func - The function to unbind.

            See:
            <Mindscape.dom.unbind>
            <bind>
            */
            unbind: function (element, event, func) {
                Mindscape.dom.unbind(element, event, func);
            },

            /*
            Function: notify
            The function for notifying observers of an event. Delegates to Mindscape.core.triggerEvent.

            Parameters:
            event - The event to trigger a notification for.

            See:
            <Mindscape.core.triggerEvent>
            <listen>
            <ignore>
            */
            notify: function (event) {
                core.triggerEvent(event);
            },

            /*
            Function: listen
            The function for listening to event notifications. Delegates to Mindscape.core.registerEvents.

            Parameters:
            events - The events to listen to.

            See:
            <Mindscape.core.registerEvents>
            <notify>
            <ignore>
            */
            listen: function (events) {
                core.registerEvents(events, moduleSelector);
            },

            /*
            Function: ignore
            The function for ignoring event notifications. Delegates to Mindscape.core.unregisterEvents.

            Parameters:
            events - The events to ignore.

            See:
            <Mindscape.core.unregisterEvents>
            <notify>
            <listen>
            */
            ignore: function (events) {
                core.unregisterEvents(events, moduleSelector);
            },

            /*
            Function: createElement
            The function for creating a new DOM element. Delegates to Mindscape.dom.createElement.

            Parameters:
            tag - The HTML tag to be created as a DOM element.
            settings - The settings to be applied to the new DOM element.

            See:
            <Mindscape.dom.createElement>
            */
            createElement: function (tag, settings) {
                return Mindscape.dom.createElement(tag, settings);
            },

            /*
            Function: ajax
            The function for performing AJAX requests. Delegates to Mindscape.util.ajax which delegates to jQuery.ajax.

            Parameters:
            options - The options to be used when performing the AJAX request.

            See:
            <Mindscape.util.ajax>
            <toJSON>
            */
            ajax: function (options) {
                return Mindscape.util.ajax(options);
            },

            /*
            Function: toJSON
            The function for serializing an object to JSON. Delegates to Mindscape.util.toJSON which delegates to jQuery.toJSON.

            Parameters:
            data - The object to be serialized.

            See:
            <Mindscape.util.toJSON>
            <ajax>
            */
            toJSON: function (data) {
                return Mindscape.util.toJSON(data);
            },

            /*
            Function: each
            The function for looping through items in an object or array.  Delegates Mindscape.util.each which delgates to jQuery.each

            Parameters
            data - The object or array to be itterated through
            method - Code to be extecuted on each itteration of data

            See:
            <Mindscape.util.each>
            <each>
            */
            each: function (data, method) {

                return Mindscape.util.each(data, method);

            },

            /*
            Function: applyCSS
            The function for applying css to a DOM element.  Delegates to Mindscape.dom.applyCSS which delegates to jQuery().css.

            Parameters:
            element - The DOM element to be modified.
            cssProperty - The css property to be modified. (ie: background-color).
            cssValue - The value of the property to be modified. (ie: #ff0000);
            */
            applyCSS: function (element, cssProperty, cssValue) {

                Mindscape.dom.applyCSS(element, cssProperty, cssValue);

            },

            /*
            Function: getChildren
            The function for getting the children of a DOM element. Delegates to Mindscape.dom.getChildren which delegates to jQuery().children().

            Parameters:
            selector - A string containing a selector expression to match elements against.
            */
            getChildren: function (element, selector) {

                return Mindscape.dom.getChildren(element, selector);

            },

            /*
            Function: fadeIn
            The function for fading in a DOM element. Delegates to Mindscape.dom.fadeIn which delegates to jQuery().fadeIn().

            Parameters:
            element - The DOM element to fade in.
            duration - A string or number determining how long the animation will run.
            easing - A string indicating which easing function to use for the transition.
            callback - A function to call once the animation is complete.
            */
            fadeIn: function (element, duration, easing, callback) {

                Mindscape.dom.fadeIn(element, duration, easing, callback);

            },

            /*
            Function: fadeOut
            The function for fading out a DOM element. Delegates to Mindscape.dom.fadeOut which delegates to jQuery().fadeOut().

            Parameters:
            element - The DOM element to fade out.
            duration - A string or number determining how long the animation will run.
            easing - A string indicating which easing function to use for the transition.
            callback - A function to call once the animation is complete.
            */
            fadeOut: function (element, duration, easing, callback) {

                Mindscape.dom.fadeOut(element, duration, easing, callback);

            },

            /*
            Function: animate
            The function for creating an animation for a DOM element. Delegates to Mindscape.dom.animate which delegates to jQuery().animate().

            Parameters:
            element - The DOM element to fade out.
            properties - A map of CSS properties that the animation will move toward.
            duration - A string or number determining how long the animation will run.
            easing - A string indicating which easing function to use for the transition.
            callback - A function to call once the animation is complete.
            */
            animate: function (element, properties, duration, easing, callback) {

                Mindscape.dom.animate(element, properties, duration, easing, callback);

            },

            /*
            Function: not
            Removes elements from the set of matched elements. Delegates to Mindscape.dom.not which delegates to jQuery().not().

            Parameters:
            element - The DOM element to fade out.
            selector - A string containing a selector expression to match elements against.
            This also can be one or more DOM elements to remove from the matched
            set or a function used as a test for each elelment in the set. 'this'
            is the current DOM element.
            */
            not: function (element, selector) {

                return Mindscape.dom.not(element, selector);

            },

            /*
            Function: applyAttributes
            The function for applying attributes to a DOM element. Delegates to Mindscape.dom.applyAttributes which delegates to jQuery().attr.

            Parameters:
            element - The DOM element to apply attributes to.
            attributes - The attributes to appy to the DOM element.

            See:
            <createElement>
            */
            applyAttributes: function (element, attributes) {

                Mindscape.dom.applyAttributes(element, attributes);

            },

            /*
            Function: getAttribute
            The function for applying attributes to a DOM element. Delegates to Mindscape.dom.getAttribute which delegates to jQuery().attr.

            Parameters:
            element - The DOM element to apply attributes to.
            attribute - The attribute to get from the selected elelment.

            See:
            <createElement>
            */
            getAttribute: function (element, attribute) {
                return $m.jQuery(element).attr(attribute);
            },

            /*
            Function: hasClass
            The function for checking if DOM element has a css class.

            Parameters:
            element - The DOM element to be checked.
            className - The css class name to check for.

            See:
            <addClass>
            <removeClass>
            <toggleClass>
            */
            hasClass: function (element, className) {
                return Mindscape.dom.hasClass(element, className);
            },

            /*
            Function: addClass
            The function for adding a css class to a DOM element. Delegates to Mindscape.dom.addClass which delegates to jQuery().addClass.

            Parameters:
            element - The DOM element to be modified.
            className - The css class name to add.

            See:
            <hasClass>
            <removeClass>
            <toggleClass>
            */
            addClass: function (element, className) {

                Mindscape.dom.addClass(element, className);

            },

            /*
            Function: removeClass
            The function for removing a css class from a DOM element. Delegates to Mindscape.dom.removeClass which delegates to jQuery.removeClass.

            Parameters:
            element - The DOM element to be modified.
            className - The css class name to remove.

            See:
            <hasClass>
            <addClass>
            <toggleClass>
            */
            removeClass: function (element, className) {

                Mindscape.dom.removeClass(element, className);

            },

            /*
            Function: toggleClass
            The function for toggling (adding or removing) a css class from a DOM element.

            Parameters:
            element - The DOM element to be modified.
            className - The css class to toggle.

            See:
            <hasClass>
            <addClass>
            <removeClass>
            */
            toggleClass: function (element, className) {

                Mindscape.dom.toggleClass(element, className);

            },

            /*
            Function: next
            Get the immediately following sibling of each element in the set of matched elements. 
            If a selector is provided, it retrieves the next sibling only if it matches that selector. 
    
            Delegates to MIndscape.dom.next which delegates to jQuery().next().

            Parameters:
            element - The DOM element in which to select the next sibling(s) from.
            selector - A string containing a selector expression to match elements against.
            */
            next: function (element, selector) {

                return Mindscape.dom.next(element, selector);

            },

            /*
            Function: getParent
            Get the immediate ancestor of each element in the current set of matched elements, optionally filtered by a selector. 
    
            Delegates to Mindscape.dom.getParent which delegates to jQuery().parent().

            Parameters:
            element - The DOM element in which to select ancestor(s) from.
            selector - A string containing a selector expression to match elements against.
            */
            getParent: function (element, selector) {

                return Mindscape.dom.getParent(element, selector);

            },

            /*
            Function: getParents
            Get the ancestors of each element in the current set of matched elements, optionally filtered by a selector. 
    
            Delegates to Mindscape.dom.getParents which delegates to jQuery().parents().

            Parameters:
            element - The DOM element to fade out.
            selector - A string containing a selector expression to match elements against.
            */
            getParents: function (element, selector) {

                return Mindscape.dom.getParents(element, selector);

            },

            /*
            Function: getOffset
            Get the current coordinates of the first element in the set of matched elements, relative to the document. 
    
            Delegates to Mindscape.dom.getOffset which delegates to jQuery().offset().

            Parameters:
            element - The DOM element to get current coordinates.
            */
            getOffset: function (element) {

                return Mindscape.dom.getOffset(element);

            },

            /*
            Function: getHeight
            Get the current computed height for the first element in the set of matched elements.
    
            Delegates to Mindscape.dom.height which delegates to jQuery().height().

            Parameters:
            element - The DOM element to get current coordinates.
            value - The value to set the DOM elemlent height to
            */
            getHeight: function (element) {

                return Mindscape.dom.getHeight(element);

            },

            /*
            Function: getValue
            Get the current value of the first element in the set of matched elements.
    
            Delegates to Mindscape.dom.getValue which delegates to jQuery().val().

            Parameters:
            element - The DOM element to set/get the value of.
            */
            getValue: function (element) {

                return Mindscape.dom.getValue(element);

            },

            /*
            Function: setValue
            Set the current value of the first element in the set of matched elements.
    
            Delegates to Mindscape.dom.setValue which delegates to jQuery().val().

            Parameters:
            element - The DOM element to set/get the value of.
            value = The value to set/get
            */
            setValue: function (element, value) {

                Mindscape.dom.setValue(element, value);

            },

            /*
            Function: is
            Check the current matched set of elements against a selector, element, 
            or jQuery object and return true if at least one of these elements matches the given arguments.
    
            Delegates to Mindscape.dom.is which delegates to jQuery().is().

            Parameters:
            element - The DOM element to set/get the value of.
            value = The value to set/get
            */
            is: function (element, value) {

                return Mindscape.dom.is(element, value);

            },

            /*
            Function: hide
            Hide the matched elements.
    
            Delegates to Mindscape.dom.hide which delegates to jQuery().hide().

            Parameters:
            element - The DOM element to set/get the value of.
            duration - The amount of time the animation takes.  (milliseconds)
            easing - Specifies the type of easing for the animation.
            callback - Method to run when animation is complete.
            */
            hide: function (element, duration, easing, callback) {

                Mindscape.dom.hide(element, duration, easing, callback);

            },

            /*
            Function: show
            Display the matched elements.
    
            Delegates to Mindscape.dom.show which delegates to jQuery().show().

            Parameters:
            element - The DOM element to set/get the value of.
            duration - The amount of time the animation takes.  (milliseconds)
            easing - Specifies the type of easing for the animation.
            callback - Method to run when animation is complete.
            */
            show: function (element, duration, easing, callback) {

                Mindscape.dom.show(element, duration, easing, callback);

            },

            /*
            Function: delay
            Set a timer to delay execution of subsequent items in the queue.
    
            Delegates to Mindscape.dom.delay which delegates to jQuery().delay().

            Parameters:
            duration - An integer indicating the number of milliseconds to delay execution of the next item in the queue.
            [queueName] - A string containing the name of the queue. Defaults to fx, the standard effects queue.

            */
            delay: function (element, duration, queueName) {

                Mindscape.dom.delay(duration, queueName);

            },

            /*
            Function: getHtml
            Get the HTML contents of the first element in the set of matched elements.
    
            Delegates to Mindscape.dom.getHtml which delgates to jQuery().html().

            Parameters:
            element - The DOM element to set/get the value of.

            */
            getHtml: function (element) {

                return Mindscape.dom.getHtml(element);

            },

            /*
            Function: settHtml
            Sets the HTML contents of the first element in the set of matched elements.
    
            Delegates to jQuery().html(htmlString).

            Parameters:
            element - The DOM element to set/get the value of.
            htmlString

            */
            setHtml: function (element, htmlString) {

                Mindscape.dom.setHtml(element, htmlString);

            },


            //TODO Mindscape element thingy
            select: function (selector, context) {

                return (context) ? new Mindscape.MindscapeElement(selector, context) : new Mindscape.MindscapeElement(this.find(selector));

            }
        };
    }
};
