/*
 * btloader.js
 * ===========
 * primary entry point for our JS systems.
 * Invokes YUI loader first - then loads BT subsystems needed.
 * This files modification time is hashed. The hash code is used for the loading of all BT assets.
 * So touching this file is necessary for an update.
 */

// As we load subsystems, they will attach here.
var btLoginDialog = null;
var btUploadTracker = null;
var btUploadDialog = null;
var btRegisterDialog = null;
var btActivateDialog = null;
var btMessageBox = null;
var btResetPasswordDialog = null;
var btVoteDialog = null;
var btAddCommentDialog = null;
var btControlPanel = null;
var btFamilyFilter = null;

function attachScript(scriptURL)
{
	var scriptEl = document.createElement("script");
	scriptEl.type = "text/javascript";
	scriptEl.src = scriptURL;
	document.body.appendChild(scriptEl);
}

// Kick off the YUI loader.
var loader = new YAHOO.util.YUILoader({
	loadOptional: true,
	combine: true,
	//filter: YAHOO.util.YUILoader.DEBUG, 
	onSuccess: function()
	{
		//Temp hack - scriptaculous uses a silly src check to see what it needs to load.
		// We don't support that with js.php - so load it manually here.
		//if(window.isEntry)

		/*YAHOO.util.Event.onDOMReady(function()
		{
			attachScript("js/scriptaculous.js?load=effects,builder");
		});*/
	}
});

//Add our custom modules to the loader.
var staticJSPath = window.staticURL + "resource.php/js/" + window.jsHash + "/";

//Add our custom modules to the loader.

// Core BT module includes all scripts used across site. Also sets dependancies for YUI stuff.
loader.addModule({
	name: "beatthat_core",
	type: "js",
	fullpath: buildResourceURL("js", "core"),
	requires: ["animation", "connection", "container", "dragdrop", "dom", "event", "button", "uploader"]
});

loader.addModule({
	name: "beatthat_accountactivation",
	type: "js",
	fullpath: buildResourceURL("js", "accountactivation"),
	requires: ["beatthat_core"]
});

loader.addModule({
	name: "beatthat_user",
	type: "js",
	fullpath: buildResourceURL("js", "user"),
	requires: ["beatthat_core"]
});

loader.addModule({
	name: "beatthat_guest",
	type: "js",
	fullpath: buildResourceURL("js", "guest"),
	requires: ["beatthat_core"]
});

loader.addModule({
	name: "beatthat_entry",
	type: "js",
	fullpath: buildResourceURL("js", "entry"),
	requires: ["beatthat_core"]
});

loader.addModule({
	name: "beatthat_entry_slideshow",
	type: "js",
	fullpath: buildResourceURL("js", "entry_slideshow"),
	requires: ["beatthat_entry"]
});

loader.addModule({
	name: "beatthat_entry_video",
	type: "js",
	fullpath: buildResourceURL("js", "entry_video"),
	requires: ["beatthat_entry"]
});

loader.addModule({
	name: "beatthat_cp",
	type: "js",
	fullpath: buildResourceURL("js", "cp"),
	requires: ["beatthat_core", "tabview", "treeview"]
});

loader.addModule({
	name: "beatthat_cpadmin",
	type: "js",
	fullpath: buildResourceURL("js", "cpadmin"),
	requires: ["beatthat_core", "datatable", "datasource"]
});

// Depending on where we are, let's figure what to load.

// Obviously we need our core.
loader.require("beatthat_core");

if(window.isEntry)
{
	if(window.isSlideShow)
		loader.require("beatthat_entry_slideshow");
	else
		loader.require("beatthat_entry_video");
}

if(window.isControlPanel)
{
	loader.require("beatthat_cp");
	
	if(window.isAdmin)
		loader.require("beatthat_cpadmin");
}

if(window.loggedIn)
{
	loader.require("beatthat_user");
	
	if(!window.isActivated)
		loader.require("beatthat_accountactivation");
}
else
	loader.require("beatthat_guest");

// This will actually fire the YUI loader.
loader.insert();