/**
 * @requires {Cobalt.Core}
 * @requires {Cobalt.Core.SandboxFactory}
 *
 * @param {Cobalt.Core.DomService} domService
 * @param {Cobalt.Core.AjaxService} ajaxService
 * @constructor
 */
var Cobalt = (typeof(Cobalt) === "undefined") ? {} : Cobalt;
Cobalt.Core = (typeof(Cobalt.Core) === "undefined") ? {} : Cobalt.Core;

Cobalt.Core.Application = function(domService, ajaxService, flashService, reportingService, plugins, global)
{
    this._moduleCount = 0;
    this._moduleCollection = {};
    this._domService = domService;
    this._ajaxService = ajaxService;
    this._flashService = flashService;
	this._reportingService = reportingService;
    this._plugins = plugins;
    this._global = global;
};

/**
 * @return {Integer} number of modules registered
 */
Cobalt.Core.Application.prototype.getModuleCount = function()
{
     return this._moduleCount;
};
/**
 * registers a module with the application without starting it
 *
 * example:
 * Core.register("specialsModule", function(sandbox) {
 *      //implementation
 * });
 *
 * @param {String} moduleID
 * @param {Function} moduleClosure  a closure function with a single param, taking in Sandbox
 *
 */
Cobalt.Core.Application.prototype.register = function(moduleID, moduleClosure)
{
    if (typeof moduleClosure !== "function")
    {
        throw new Error("module implementation must be in a closure function");
    }
    if(typeof this._moduleCollection[moduleID] == 'undefined') {
        this._moduleCollection[moduleID] = { "moduleClosure": moduleClosure, "instance": null};
        ++this._moduleCount;
    }
};
/**
 * start the module and init process; module must implement init()
 *
 * example:
 * var mockModuleData = function()
 * {
 *     return {
 *        init : function() { //impl},
 *        destroy : function() {//impl }
 *    };
 * };
 * _cobaltCoreTest.application = new Cobalt.Core.Application(_cobaltCoreTest.mockSandbox);
 * _cobaltCoreTest.application.register(_cobaltCoreTest.moduleID1, mockModuleData);
 * _cobaltCoreTest.application.start(_cobaltCoreTest.moduleID1);
 *
 * @param {String} moduleID
 *
 */
Cobalt.Core.Application.prototype.start = function(moduleID)
{
    var moduleData = this._moduleCollection[moduleID];
    if (moduleData.instance!==null)
    {
        return false;
    }
    moduleData.instance = moduleData.moduleClosure(this.getSandbox());
    if (typeof moduleData.instance.init !== "function")
    {
        throw new Error("module implementation needs to implement init()");
    }

    moduleData.instance.init();
};
/**
 * @return {Cobalt.Core.Sandbox}
 */
Cobalt.Core.Application.prototype.getSandbox = function()
{
    return Cobalt.Core.SandboxFactory.createInstance(this);
};
/**
 * stop the module and clean up; module must implement destroy()
 * 
 *  example:
 *  var mockModuleData = function()
 *  {
 *     return {
 *        init : function() { //impl},
 *        destroy : function() {//impl }
 *    };
 *  };
 *  _cobaltCoreTest.application = new Cobalt.Core.Application(_cobaltCoreTest.mockSandbox);
 *  _cobaltCoreTest.application.register(_cobaltCoreTest.moduleID1, mockModuleData);
 *  _cobaltCoreTest.application.start(_cobaltCoreTest.moduleID1);
 *
 * @param {String} moduleID
 *
 */
Cobalt.Core.Application.prototype.stop = function(moduleID)
{
    var moduleData = this._moduleCollection[moduleID];
    if (moduleData.instance)
    {
        if (typeof moduleData.instance.destroy !== "function")
        {
            throw new Error("module implementation needs to implement destroy()");
        }
        moduleData.instance.destroy();
        moduleData.instance = null;
    }
};
/**
 * start all modules
 */
Cobalt.Core.Application.prototype.startAll = function()
{
     for (var moduleID in this._moduleCollection)
     {
         if (this._moduleCollection.hasOwnProperty(moduleID) && this._moduleCollection[moduleID].hasOwnProperty("instance") && this._moduleCollection[moduleID].instance===null)
         {
             this.start(moduleID);
         }
     }
};
/**
 * stop all modules
 */
Cobalt.Core.Application.prototype.stopAll = function()
{
     for (var moduleID in this._moduleCollection)
     {
         if (this._moduleCollection.hasOwnProperty(moduleID))
         {
             this.stop(moduleID);
         }
     }
};
/**
 * Return the "namespace" that holds the data for module
 * @param {String} name of the module
 */
Cobalt.Core.Application.prototype.getDataScope = function(moduleName)
{
     return (Cobalt.ModulesData && Cobalt.ModulesData[moduleName])? Cobalt.ModulesData[moduleName] : window;
};
/**
 * Attach a handler for the given anchor on the event
 * example:
 *    sandbox.listen(anchor, "click", onNewCategorySeleced, this);
 *
 * @param {Object} anchor nullable, if null, then listening for broadcast events
 * @param {String} eventName
 * @param {Function} handler
 * @param {Object} eventData
 */
Cobalt.Core.Application.prototype.listen = function(anchor, eventName, handler, eventData)
{
    this._verifyDependencyMethod(this._domService, "listen");
    this._domService.listen(anchor, eventName, handler, eventData);
};

Cobalt.Core.Application.prototype.removeListeners = function(anchor, eventName)
{
    this._verifyDependencyMethod(this._domService, "removeListeners");
    this._domService.removeListeners(anchor, eventName);
};

/**
 * Triggers an event on the anchor object
 * example:
 *    app.raise(anyAnchor, eventName, anyData);
 *
 * @param {Object} anchor nullable, if null, then broadcast an event
 * @param {String} eventName
 * @param {Object} eventData
 */
Cobalt.Core.Application.prototype.raise = function(anchor, eventName, eventData)
{
    this._verifyDependencyMethod(this._domService, "raise");
    this._domService.raise(anchor, eventName, eventData);
};


/**
 * Fire ajax requests
 * example:
 *     var app = createApplication();
 *     var options = {
 *        requestData : {},
 *        success : function(response) { },
 *        failure : function(response) { }  
 *     };
 *     app.request(options);
 *
 * @param {Object} options
 */
Cobalt.Core.Application.prototype.request = function(options)
{
    this._verifyDependencyMethod(this._ajaxService, "request");
    this._ajaxService.request(options);
};
/**
 * Works with xml and Html element. Returns attributeName if attributeValue not set
 * @param {DomElement} element
 * @param {String} attributeName
 * @param {String} attributeValue
 */
Cobalt.Core.Application.prototype.attr = function(element, attributeName, attributeValue)
{
    this._verifyDependencyMethod(this._domService, "attr");
    return  this._domService.attr(element, attributeName, attributeValue);
};
/**
 *
 * @param {DomElement} element
 * @param {String} replacementHtmlString
 */
Cobalt.Core.Application.prototype.html = function(element, replacementHtmlString)
{
    this._verifyDependencyMethod(this._domService, "html");
    this._domService.html(element, replacementHtmlString);
};
/**
 *
 * @param {DomElement} element
 * @param {String} replacementWith String
 */
Cobalt.Core.Application.prototype.replaceWith = function(element, replacementWithString)
{
    this._verifyDependencyMethod(this._domService, "replaceWith");
    this._domService.replaceWith(element, replacementWithString);
};


/**
 *
 * @param {DomElement} element
 * @return {String}
 */
Cobalt.Core.Application.prototype.text = function(element, param)
{
    this._verifyDependencyMethod(this._domService, "text");
    return this._domService.text(element, param);
};
/**
 * @param {DomElement} element element collection
 * @param {Function} funcPtr the function to be evaulated per iteration
 */
Cobalt.Core.Application.prototype.each = function(element, funcPtr)
{
    this._verifyDependencyMethod(this._domService, "each");
    this._domService.each(element,  funcPtr);
};
Cobalt.Core.Application.prototype.load = function(element, funcPtr)
{
    this._verifyDependencyMethod(this._domService, "load");
    this._domService.load(element,  funcPtr);
};
Cobalt.Core.Application.prototype.error = function(element, funcPtr)
{
    this._verifyDependencyMethod(this._domService, "error");
    this._domService.error(element,  funcPtr);
};
/**
 *
 * @param {String} id
 * @return {DomElement}
 */
Cobalt.Core.Application.prototype.getElementById = function(id)
{
    this._verifyDependencyMethod(this._domService, "getElementById");
    return this._domService.getElementById(id);
};
/**
 *
 * @param {DomElement} element
 * @param {String} event
 * @param {Function} handler
 */
Cobalt.Core.Application.prototype.listenLive = function(element, event, handler, context)
{
    this._verifyDependencyMethod(this._domService, "listenLive");
    return this._domService.listenLive(element, event, handler, context);
};
/**
 * 
 * @param {String} attributeName
 * @param {String} attributeValue if this is null or undefined, all elements having attributeName will be returned
 * @return {Array<DomElements>} array of DomElements
 */
Cobalt.Core.Application.prototype.getElementsByAttribute = function(attributeName, attributeValue)
{
    this._verifyDependencyMethod(this._domService, "getElementsByAttribute");
    return this._domService.getElementsByAttribute(attributeName, attributeValue);
};
/**
 *
 * @param {String} Raw XML data
 * @return Serialised XML data
 */
Cobalt.Core.Application.prototype.getXmlElementTextValue = function(xmlElement)
{
    this._verifyDependencyMethod(this._domService, "getXmlElementTextValue");
    return this._domService.getXmlElementTextValue(xmlElement);
};
/**
 *
 * @param {DomElement} element
 * @param {String} parameter
 * @return boolean
 */
Cobalt.Core.Application.prototype.is = function(element, param)
{
    this._verifyDependencyMethod(this._domService, "is");
    return this._domService.is(element, param);
};
/**
 *
 * @param {DomElement} element
 * @param {String} or {Number} parameter
 */
Cobalt.Core.Application.prototype.show = function(element, param)
{
    this._verifyDependencyMethod(this._domService, "show");
    return this._domService.show(element, param);
};
/**
 *
 * @param {DomElement} element
 * @param {String} or {Number} parameter
 */
Cobalt.Core.Application.prototype.hide = function(element, param)
{
    this._verifyDependencyMethod(this._domService, "hide");	
    return this._domService.hide(element, param);
};
Cobalt.Core.Application.prototype.animate = function(element, properties, duration, effect, callback)
{
    this._verifyDependencyMethod(this._domService, "animate");
    return this._domService.animate(element, properties, duration, effect, callback);
};
Cobalt.Core.Application.prototype.slideUp = function(element, callback, options)
{
    this._verifyDependencyMethod(this._domService, "slideUp");
    return this._domService.slideUp(element, callback, options);
};
Cobalt.Core.Application.prototype.slideDown = function(element, callback, options)
{
    this._verifyDependencyMethod(this._domService, "slideDown");
    return this._domService.slideDown(element, callback, options);
};
Cobalt.Core.Application.prototype.slideToggle = function(element, callback, options)
{
    this._verifyDependencyMethod(this._domService, "slideToggle");
    return this._domService.slideToggle(element, callback, options);
};

Cobalt.Core.Application.prototype.fadeIn = function(element, duration, callback)
{
    this._verifyDependencyMethod(this._domService, "fadeIn");
    return this._domService.fadeIn(element, duration, callback);
};
Cobalt.Core.Application.prototype.fadeOut = function(element, duration, callback)
{
    this._verifyDependencyMethod(this._domService, "fadeOut");
    return this._domService.fadeOut(element, duration, callback);
};
/**
 *
 * @param {DomElement} element
 * @param {String} parameter
 */
Cobalt.Core.Application.prototype.find = function(element, param)
{
    this._verifyDependencyMethod(this._domService, "find");	
    return this._domService.find(element, param);	
};
Cobalt.Core.Application.prototype.children = function(element, param)
{
    this._verifyDependencyMethod(this._domService, "children");	
    return this._domService.children(element, param);
};
Cobalt.Core.Application.prototype.parents = function(element, param)
{
    this._verifyDependencyMethod(this._domService, "parents");	
    return this._domService.parents(element, param);
};
Cobalt.Core.Application.prototype.closest = function(element, param)
{
    this._verifyDependencyMethod(this._domService, "closest");
    return this._domService.closest(element, param);
};
Cobalt.Core.Application.prototype.prependTo = function(element, param)
{
    this._verifyDependencyMethod(this._domService, "prependTo");
    return this._domService.prependTo(element, param);
};
Cobalt.Core.Application.prototype.length = function(element)
{
    this._verifyDependencyMethod(this._domService, "length");
    return this._domService.length(element);
};
Cobalt.Core.Application.prototype.size = function(element)
{
    this._verifyDependencyMethod(this._domService, "size");
    return this._domService.size(element);
};
Cobalt.Core.Application.prototype.get = function(element, param)
{
    this._verifyDependencyMethod(this._domService, "get");
    return this._domService.get(element, param);
};
Cobalt.Core.Application.prototype.height = function(element, param)
{
    this._verifyDependencyMethod(this._domService, "height");
    return this._domService.height(element, param);
};
Cobalt.Core.Application.prototype.width = function(element, param)
{
    this._verifyDependencyMethod(this._domService, "width");
    return this._domService.width(element, param);
};
Cobalt.Core.Application.prototype.outerHeight = function(element, param)
{
    this._verifyDependencyMethod(this._domService, "outerHeight");
    return this._domService.outerHeight(element, param);
};
Cobalt.Core.Application.prototype.outerWidth = function(element, param)
{
    this._verifyDependencyMethod(this._domService, "outerWidth");
    return this._domService.outerWidth(element, param);
};
Cobalt.Core.Application.prototype.scroll = function(element, param)
{
    this._verifyDependencyMethod(this._domService, "scroll");
    return this._domService.scroll(element, param);
};
Cobalt.Core.Application.prototype.scrollEnd = function(element, param) {
    this._verifyDependencyMethod(this._domService, "scrollEnd");
    return this._domService.scrollEnd(element, param);
};
Cobalt.Core.Application.prototype.scrollTop = function(element, param)
{
    this._verifyDependencyMethod(this._domService, "scrollTop");
    return this._domService.scrollTop(element, param);
};
Cobalt.Core.Application.prototype.scrollLeft = function(element, param)
{
    this._verifyDependencyMethod(this._domService, "scrollLeft");
    return this._domService.scrollLeft(element, param);
};
Cobalt.Core.Application.prototype.scrollTo = function(x, y)
{
    this._verifyDependencyMethod(this._domService, "scrollTo");
    return this._domService.scrollTo(x, y);
};
Cobalt.Core.Application.prototype.openLocation = function(uri)
{
    this._verifyDependencyMethod(this._domService, "openLocation");
    return this._domService.openLocation(uri);
};
Cobalt.Core.Application.prototype.next = function(element, param)
{
    this._verifyDependencyMethod(this._domService, "next");
    return this._domService.next(element, param);
};
Cobalt.Core.Application.prototype.prev = function(element, param)
{
    this._verifyDependencyMethod(this._domService, "prev");
    return this._domService.prev(element, param);
};
Cobalt.Core.Application.prototype.removeClass = function(element, param)
{
    this._verifyDependencyMethod(this._domService, "removeClass");
    return this._domService.removeClass(element, param);
};
Cobalt.Core.Application.prototype.removeAttr = function(element, param)
{
    this._verifyDependencyMethod(this._domService, "removeAttr");
    return this._domService.removeAttr(element, param);
};
Cobalt.Core.Application.prototype.not = function(element, param)
{
    this._verifyDependencyMethod(this._domService, "not");
    return this._domService.not(element, param);
};
Cobalt.Core.Application.prototype.addClass = function(element, param)
{
    this._verifyDependencyMethod(this._domService, "addClass");
    return this._domService.addClass(element, param);
};
Cobalt.Core.Application.prototype.hasClass = function(element, param)
{
    this._verifyDependencyMethod(this._domService, "hasClass");
    return this._domService.hasClass(element, param);
};
Cobalt.Core.Application.prototype.index = function(element, param)
{
    this._verifyDependencyMethod(this._domService, "index");
    return this._domService.index(element, param);
};
Cobalt.Core.Application.prototype.getDomElements = function(element)
{
    this._verifyDependencyMethod(this._domService, "getDomElements");
    return this._domService.getDomElements(element);
};
Cobalt.Core.Application.prototype.createDomElement = function(element)
{
    this._verifyDependencyMethod(this._domService, "createDomElement");
    return this._domService.createDomElement(element);
};
Cobalt.Core.Application.prototype.append = function(element, param)
{
    this._verifyDependencyMethod(this._domService, "append");
    return this._domService.append(element, param);
};
Cobalt.Core.Application.prototype.wrapAll = function(element, param)
{
    this._verifyDependencyMethod(this._domService, "wrapAll");
    return this._domService.wrapAll(element, param);
};
Cobalt.Core.Application.prototype.parseJSON = function(json) {
	this._verifyDependencyMethod(this._domService, "parseJSON");
	return this._domService.parseJSON(json);
};
Cobalt.Core.Application.prototype.parent = function(element, param)
{
    this._verifyDependencyMethod(this._domService, "parent");
    return this._domService.parent(element, param);
};
Cobalt.Core.Application.prototype.parents = function(element, param)
{
    this._verifyDependencyMethod(this._domService, "parents");
    return this._domService.parents(element, param);
};
Cobalt.Core.Application.prototype.position = function(element)
{
    this._verifyDependencyMethod(this._domService, "position");
    return this._domService.position(element);
};
Cobalt.Core.Application.prototype.offset = function(element)
{
    this._verifyDependencyMethod(this._domService, "offset");
    return this._domService.offset(element);
};
Cobalt.Core.Application.prototype.addStyle = function(element, param)
{
    this._verifyDependencyMethod(this._domService, "addStyle");
    return this._domService.addStyle(element, param);
};
Cobalt.Core.Application.prototype.css = function(element, prop, val)
{
    this._verifyDependencyMethod(this._domService, "css");
    return this._domService.css(element, prop, val);
};
Cobalt.Core.Application.prototype.remove = function(element, param)
{
    this._verifyDependencyMethod(this._domService, "remove");
    return this._domService.remove(element, param);
};
Cobalt.Core.Application.prototype.empty = function(element, param)
{
    this._verifyDependencyMethod(this._domService, "empty");
    return this._domService.empty(element, param);
};
Cobalt.Core.Application.prototype.detach = function(element, param)
{
    this._verifyDependencyMethod(this._domService, "detach");
    return this._domService.detach(element, param);
};
Cobalt.Core.Application.prototype.before = function(element, param)
{
    this._verifyDependencyMethod(this._domService, "before");
    return this._domService.before(element, param);
};
Cobalt.Core.Application.prototype.innerHTML = function(element, param)
{
    this._verifyDependencyMethod(this._domService, "innerHTML");
    return this._domService.innerHTML(element, param);
};
Cobalt.Core.Application.prototype.val = function(element, param)
{
    this._verifyDependencyMethod(this._domService, "val");
    return this._domService.val(element, param);
};

Cobalt.Core.Application.prototype.embedFlash = function(options)
{
    this._verifyDependencyMethod(this._flashService, "embedFlash");
    return this._flashService.embedFlash(options);
};

Cobalt.Core.Application.prototype.firePixelTag = function(data)
{
    this._verifyDependencyMethod(this._reportingService, "firePixelTag");
    return this._reportingService.firePixelTag(data);
};

Cobalt.Core.Application.prototype.trackExternalLinkout = function(linkData, pixelTagData)
{
    this._verifyDependencyMethod(this._reportingService, "trackExternalLinkout");
    return this._reportingService.trackExternalLinkout(linkData, pixelTagData);
};

Cobalt.Core.Application.prototype.tabs = function(element, param, options)
{
    this._verifyDependencyMethod(this._domService, "tabs");
    return this._domService.tabs(element, param, options);
};

Cobalt.Core.Application.prototype.datepicker = function(element, param, options, val)
{
    this._verifyDependencyMethod(this._domService, "datepicker");
    return this._domService.datepicker(element, param, options, val);
};

Cobalt.Core.Application.prototype.dialog = function(element, param, options)
{
    this._verifyDependencyMethod(this._domService, "dialog");
    return this._domService.dialog(element, param, options);
};

Cobalt.Core.Application.prototype.tablesorter = function(element, options)
{
    this._verifyDependencyMethod(this._domService, "tablesorter");
    return this._domService.tablesorter(element, options);
};

Cobalt.Core.Application.prototype.carousel = function(element, func)
{
    this._verifyDependencyMethod(this._domService, "carousel");
    return this._domService.carousel(element, func);
};


Cobalt.Core.Application.prototype.bind = function(element, eventType, func)
{
    this._verifyDependencyMethod(this._domService, "bind");
    return this._domService.bind(element, eventType, func);
};

Cobalt.Core.Application.prototype.click = function(element, func)
{
    this._verifyDependencyMethod(this._domService, "click");
    return this._domService.click(element, func);
};

Cobalt.Core.Application.prototype.focus = function(element, func)
{
    this._verifyDependencyMethod(this._domService, "focus");
    return this._domService.focus(element, func);
};

Cobalt.Core.Application.prototype.blur = function(element, func)
{
    this._verifyDependencyMethod(this._domService, "blur");
    return this._domService.blur(element, func);
};

Cobalt.Core.Application.prototype.serialize = function(element)
{
    this._verifyDependencyMethod(this._domService, "serialize");
    return this._domService.serialize(element);
};

Cobalt.Core.Application.prototype.cbltslider = function(domSelector, options)
{
    this._verifyDependencyMethod(this._plugins, "cbltslider");
    return this._plugins.cbltslider(domSelector, options);
};

Cobalt.Core.Application.prototype.clone = function(element)
{
    this._verifyDependencyMethod(this._domService, "clone");
    return this._domService.clone(element);
};

Cobalt.Core.Application.prototype.extend = function(obj1, obj2)
{
    this._verifyDependencyMethod(this._domService, "extend");
    return this._domService.extend(obj1, obj2);
};

Cobalt.Core.Application.prototype.extendNew = function(obj1, obj2, obj3)
{
    this._verifyDependencyMethod(this._domService, "extendNew");
    return this._domService.extendNew(obj1, obj2, obj3);
};

Cobalt.Core.Application.prototype.globalMethod = function(name, callback)
{
    this._verifyDependencyMethod(this._domService, "globalMethod");
    return this._domService.globalMethod(name, callback);
};

Cobalt.Core.Application.prototype.appendTo = function(element, target)
{
    this._verifyDependencyMethod(this._domService, "appendTo");
    return this._domService.appendTo(element, target);
};

Cobalt.Core.Application.prototype.data = function(element, dataElem, key, value)
{
    this._verifyDependencyMethod(this._domService, "data");
    return this._domService.data(dataElem, key, value);
};
Cobalt.Core.Application.prototype.submit = function(element, callback)
{
    this._verifyDependencyMethod(this._domService, "submit");
    return this._domService.submit(element, callback);
};
Cobalt.Core.Application.prototype.browser = function()
{
	this._verifyDependencyMethod(this._domService, "browser");
    return this._domService.browser();
};
Cobalt.Core.Application.prototype.autocomplete = function(domSelector, options)
{
    this._verifyDependencyMethod(this._plugins, "autocomplete");
    return this._plugins.autocomplete(domSelector, options);
};
Cobalt.Core.Application.prototype.iPhoneStyleToggle = function(domSelector, options)
{
    this._verifyDependencyMethod(this._plugins, "iPhoneStyleToggle");
    return this._plugins.iPhoneStyleToggle(domSelector, options);
};
Cobalt.Core.Application.prototype.addDomCache = function(element) 
{
    this._verifyDependencyMethod(this._domService, "addDomCache");
    this._domService.addDomCache(element);
};
Cobalt.Core.Application.prototype.getJSON = function(url, data, callback)
{
    this._verifyDependencyMethod(this._domService, "getJSON");
    this._domService.getJSON(url, data, callback);
}
Cobalt.Core.Application.prototype.placeholder = function(domSelector, options)
{
    this._verifyDependencyMethod(this._plugins, "placeholder");
    return this._plugins.placeholder(domSelector, options);
};
Cobalt.Core.Application.prototype.support = function()
{
    this._verifyDependencyMethod(this._domService, "support");
    return this._domService.support();
};
Cobalt.Core.Application.prototype.toggle = function(element, param)
{
    this._verifyDependencyMethod(this._domService, "toggle");
    return this._domService.toggle(element,param);
};
Cobalt.Core.Application.prototype.die = function(element, param)
{
	this._verifyDependencyMethod(this._domService, "die");
    return this._domService.die(element,param);
};

Cobalt.Core.Application.prototype.throttle = function(method, scope) {
    clearTimeout(method._tId);
    method._tId = setTimeout(function() {
        method.call(scope);
    }, 100);
};

Cobalt.Core.Application.prototype.getFrameWindowByName = function(frameName) {
    if (!this._global || this._global.frames.length < 1) {
        return null;
    }

    return this._global.frames[frameName];
};

Cobalt.Core.Application.prototype.setInterval = function(func, time) {
    if (!this._global) {
        throw new Error("setInterval => global not set");
    }

    return this._global.setInterval(func, time);
};

Cobalt.Core.Application.prototype.getGlobalVariable = function(name) {
    if (!this._global) {
        throw new Error("getGlobalVariable => global not set");
    }

    return this._global[name];
};

Cobalt.Core.Application.prototype.delay = function(element, param) {
	this._verifyDependencyMethod(this._domService, "delay");
    return this._domService.delay(element,param);
};

Cobalt.Core.Application.prototype.trim = function(param) {
	this._verifyDependencyMethod(this._domService, "trim");
    return this._domService.trim(param);
};

Cobalt.Core.Application.prototype.sortelements = function(domSelector, comparator, options)
{
    this._verifyDependencyMethod(this._plugins, "sortelements");
    return this._plugins.sortelements(domSelector, comparator, options);
};

Cobalt.Core.Application.prototype.safetynetfn = function(domSelector, options)
{
    this._verifyDependencyMethod(this._plugins, "safetynetfn");
    return this._plugins.safetynetfn(domSelector, options);
};

Cobalt.Core.Application.prototype.getSafetynetObj = function()
{
	if (!this._plugins.safetynetObj) {
        throw new Error("getSafetynetObj => safetynetfn not called");
    }
    return this._plugins.safetynetObj;
};

Cobalt.Core.Application.prototype.setGlobalVariable = function(name, value) {
    if (!this._global) {
        throw new Error("getGlobalVariable => global not set");
    }

    this._global[name] = value;
};

Cobalt.Core.Application.prototype.jScrollPane = function(domSelector, options)
{
    this._verifyDependencyMethod(this._plugins, "jScrollPane");
    return this._plugins.jScrollPane(domSelector, options);
};

Cobalt.Core.Application.prototype.copyToClipboard = function(domSelector, options)
{
    this._verifyDependencyMethod(this._plugins, "copyToClipboard");
    return this._plugins.copyToClipboard(domSelector, options);
};

Cobalt.Core.Application.prototype.zAccordion = function(domSelector, options)
{
    this._verifyDependencyMethod(this._plugins, "zAccordion");
    return this._plugins.zAccordion(domSelector, options);
};

Cobalt.Core.Application.prototype.getDomQueryInstance = function() {
    this._verifyDependencyMethod(this._domService, "getDomQueryInstance");
    return this._domService.getDomQueryInstance();
};
Cobalt.Core.Application.prototype.insertAfter = function(domSelector, options) {
    this._verifyDependencyMethod(this._domService, "insertAfter");
    return this._domService.insertAfter(domSelector, options);
};


Cobalt.Core.Application.prototype._verifyDependencyMethod = function(obj, propertyName)
{
    if (typeof obj[propertyName] !== "function")
    {
        throw new Error("Application => dependency method '" +  propertyName + "' does not exist.");
    }
};
