var gusto = window.gusto || {};

gusto.namespace = function() {
    var a=arguments, o=null, i, j, d;
    for (i=0; i<a.length; i=i+1) {
        d=a[i].split(".");
        o=gusto;
        for (j=(d[0] == "gusto") ? 1 : 0; j<d.length; j=j+1) {
            o[d[j]]=o[d[j]] || {};
            o=o[d[j]];
        }
    }
    return o;
};

gusto.asset_path = function(path) {
    // Find containing directory of a common js file by inspecting <script> elements
    var jsdir = jQuery(
        'script[src*=c/js]:first'
    ).attr('src').split('/').slice(0, -1).join('/');
    // Assuming it was served from a/common/js/unified, knock off three parent dirs
    jsdir = jsdir.replace('/unified','');
    var asset_path = jsdir.split('/').slice(0, -2).join('/') + '/';
    // This is a self-replacing function, to memoize the discovered path
    gusto.asset_path = function(path) {
        return asset_path + (path || '');
    };
    return asset_path + (path || '');
};
