// Global and universal object for all Joboso operations
// Requires yuiloader-dom-event.js to be loaded
// (c) 2009 Shine the Light Ltd.
// Portions Copyright (c) 2008, Yahoo! Inc.
// All rights reserved.

// Create root object if it doesn't exist
if (typeof STL == "undefined" || !STL) {
    var STL = {};
}

STL.name = "Joboso Global object";
STL.version = "1.0";
STL.YUIVersion = "2.8.0";

// Function to aid in making new namespaces
STL.namespace = function() {
    var a=arguments, o=null, i, j, d;
    for (i=0; i<a.length; i=i+1) {
        d=a[i].split(".");
        o=STL;

        // STL is implied, so it is ignored if it is included
        for (j=(d[0] == "STL") ? 1 : 0; j<d.length; j=j+1) {
            o[d[j]]=o[d[j]] || {};
            o=o[d[j]];
        }
    }

    return o;
}

// Pull global vars into our object
if (typeof STLBasePath == "undefined") {
	STL.basePath = "http://www.joboso.com/assets/js/";
} else { 
	STL.basePath = STLBasePath;
	STLBasePath = undefined;
};
if (typeof YUIBuildPath == "undefined") {
	STL.YUIBuildPath = "http://yui.yahooapis.com/2.8.0r4/build/";
} else {
	STL.YUIBuildPath = YUIBuildPath;
	YUIBuildPath = undefined;
};
if (!(typeof STLModules == "undefined")) {
	STL.required = STLModules;
	STLModules = undefined;
};


// Check if the YAHOO object is available, if it is then re-use some elements
if (typeof YAHOO == "object") {
	STL.L = YAHOO.util.YUILoader;
	STL.D = YAHOO.util.Dom;
	STL.E = YAHOO.util.Event;
}

// Define the modules available
STL.module = {
	control: {
		friendlyName: "Control",
		fileName: "control.js"
	},

	public: {
		friendlyName: "Public",
		fileName: "public.js"
	},

	homepage: {
		friendlyName: "Homepage",
		fileName: "homepage.js"
	},
	
	affiliate: {
		friendlyName: "Affiliate",
		fileName: "affiliate.js"
	},
	
	user: {
		friendlyName: "User",
		fileName: "user.js"
	},

	postcode: {
		friendlyName: "Postcode",
		fileName: "postcode.js"
	}

}

STL.loadModules = function() {
	var moduleLoader = new STL.L();
	
	for (i = 0; i < STL.required.length; i++) {
		curr = STL.required[i];
		moduleLoader.addModule({
			name: STL.required[i],
			type: "js",
			fullpath: STL.basePath + STL.module[STL.required[i]].fileName
		});
		moduleLoader.require(STL.required[i]);
	};
	
	moduleLoader.insert();
};

//STL.displayChromeFramePrompt = function() {
//	alert("Not Installed");	
//};

STL.init = function() {

	// Add the yui skin class to the body
	STL.E.onDOMReady(function(){STL.D.addClass(document.body, 'yui-skin-sam')});

    // Load the modules requested
    if (!typeof STL.required == "undefined" || STL.required) {
		STL.loadModules();
    }
	
	//Detect Chrome Frame
	//CFInstall.check({ preventPrompt: true, onmissing: STL.displayChromeFramePrompt });
	
};

//STL.E.onDOMReady(STL.init);

STL.init();

YAHOO.register("global", STL, {version: STL.version});
