// Create the namespaces in the path if they do not exist.
Lib.Utils.NamespaceUtils.createIfNecessary("Lib.Utils");

/**
* author: Nate Minshew (NJMINSH)
* date created: 01/06/2006
* description:
*   This object is used to perform utility operations on objects.
*/
Lib.Utils.ObjectUtils = {};

// Array of context objects used for binding.
Lib.Utils.ObjectUtils.CTX_OBJECTS = new Array();

/**
* author: Nate Minshew (NJMINSH)
* date created: 01/06/2006
* access level: public
* description:
*   This method returns whether the specified parameter is an object.
*
* @param object - Parameter to check.
*/
Lib.Utils.ObjectUtils.isObject = function(object) {
    if (typeof object == 'object') {
        return true;
    }
}

/**
* author: Nate Minshew (NJMINSH)
* date created: 01/06/2006
* access level: public
* description:
*   This method provides the ability to subclass javascript objects.  You just pass it the would be child and the parent
*   and it grants the child inheritance.
*
* @param child - Child object.
* @param parent - Parent object to extend.
*/
Lib.Utils.ObjectUtils.extend = function(child, parent) {
    for (var property in parent) {
        child[property] = parent[property];
    }
    return child;
}

/**
* author: Nate Minshew
* date created: 03/28/2006
* access level: public
* description:
*   This method binds the specified function to the specified context using a weak bind pattern.  Weak binds reduce
*   memory leaks that occur in IE when having circular dependencies on the DOM.  This creates an indirect reference
*   between the function and it's context.
*
* @param fn - Function to bind.
* @param ctx - Context object to find the function to.
* @return Function representing the original function with a weak binding to the context object.
*/
Lib.Utils.ObjectUtils.weakBind = function(fn, ctx) {
    var index = Lib.Utils.ObjectUtils.CTX_OBJECTS.length;
    Lib.Utils.ObjectUtils.CTX_OBJECTS.push(ctx);
    return Lib.Utils.ObjectUtils._bindIndexAndReturnFunction(fn, index);
}

/**
* author: Nate Minshew
* date created: 03/28/2006
* access level: non-public
* description:
*   This method takes the specified function and weakly binds it to the context object represented by the specified
*   index.
*
* @param fn - Function to bind.
* @param index - Representing the index of the context object.
* @return Function representing the original function with a weak binding to the context object.
*/
Lib.Utils.ObjectUtils._bindIndexAndReturnFunction = function(fn, index) {
    return function() {
        var ctx = Lib.Utils.ObjectUtils.CTX_OBJECTS[index];
        fn.apply(ctx, arguments);
    }
}

/**
* author: Nate Minshew
* date created: 04/11/2006
* access level: public
* description:
*   This method returns whether the specified object/property is defined and not null.
*
* @param obj - object/property to check.
* @param boolean - Representing if the object/property is defined.
*/
Lib.Utils.ObjectUtils.isDefined = function(obj) {
    if (typeof obj != 'undefined' && obj != null) {
        return true;
    }
    return false;
}

/**
* author: Nate Minshew
* date created: 03/06/2006
* description:
*   This object contains utility methods for performing tasks on an array.
*/
Lib.Utils.ObjectUtils.ArrayUtils = {};

/**
* author: Nate Minshew (NJMINSH)
* date created: 01/06/2006
* access level: public
* description:
*   This method returns whether the specified object is an array.
*
* @param object - The object to check.
*/
Lib.Utils.ObjectUtils.ArrayUtils.isArray = function(object) {
    if (Lib.Utils.ObjectUtils.isObject(object) && typeof object.length != 'undefined') {
        return true;
    }
    return false;
}

/**
* author: Nate Minshew
* date created: 03/06/2006
* access level: public
* description:
*   This method returns a boolean representing if the specified entry is contained within the specified array.
*
* @param array - Array object.
* @param entry - Value to check array for.
* @return boolean - Representing if the array contains the entry.
*/
Lib.Utils.ObjectUtils.ArrayUtils.contains = function(array, entry) {
    for (var i = 0; Lib.Utils.ObjectUtils.ArrayUtils.isArray(array) && i < array.length; i++) {
        if (array[i] == entry) {
            return true;
        }
    }
    return false;
}