/*
 * -- Tewonder code description start --
 * Name: tewonderGlobalCode
 * Type: Code
 * Version: 0.4.01
 *
 * Edited by: 
 * Updates: 
 *
 * Notes: 
 * Todo: 
 * -- Tewonder code description end --
 */

//alert("tewonderGlobalCode");
var gTewonderClasses = new Object();
var gTewonderGlobalObjects = new Object();
var gTewonderGlobalFunctions = new Object();

function gTewonderLocalScopeFunction() {
	//alert("gTewonderLocalScopeFunction::tewonderGlobalCode");
	
	gTewonderGlobalFunctions.addGlobalFunction = (function(aName, aFunction) {
		gTewonderGlobalFunctions[aName] = aFunction;
	});
	
	gTewonderGlobalFunctions.addGlobalFunction("addGlobalObject", (function(aName, aObject) {
		gTewonderGlobalObjects[aName] = aObject;
	}));
	
	gTewonderGlobalFunctions.addGlobalFunction("globalObjectExists", (function(aName) {
		return (gTewonderGlobalObjects[aName] != undefined);
	}));
	
	gTewonderGlobalFunctions.addGlobalFunction("addClass", (function(aClassPath, aFunction) {
		var pathArray = aClassPath.split(".");
		var currentObject = gTewonderClasses;
		var currentArray = pathArray;
		for(var i = -1; ++i < (currentArray.length-1);) {
			var currentName = currentArray[i];
			if(currentObject[currentName] == undefined) {
				currentObject[currentName] = new Object();
			}
			currentObject = currentObject[currentName];
		}
		currentObject[pathArray[(pathArray.length-1)]] = aFunction;
	}));
	
	gTewonderGlobalFunctions.addGlobalFunction("setClassInheritance", (function(aClass, aBaseClass) {
		//alert("setClassInheritance");
		gTewonderGlobalObjects["classManager"].setClassInheritance(aClass, aBaseClass);
		//aClass.prototype = new aBaseClass();
	}));
	
	gTewonderGlobalFunctions.addGlobalFunction("documentObjectExists", (function(aName) {
		if(document.tewonderDocumentObjects == undefined) {
			return false;
		}
		return (document.tewonderDocumentObjects[aName] != undefined);
	}));
	
	gTewonderGlobalFunctions.addGlobalFunction("addDocumentObject", (function(aName, aObject) {
		//alert("addDocumentObject");
		if(document.tewonderDocumentObjects == undefined) {
			document.tewonderDocumentObjects = new Object();
			gTewonderGlobalFunctions.addDocumentObject("globalObjectsLink", gTewonderGlobalObjects);
		}
		document.tewonderDocumentObjects[aName] = aObject;
	}));
	
	gTewonderGlobalFunctions.addGlobalFunction("getUsedProgramIdName", (function() {
		//Programs
		if(typeof(app) != "undefined") {
			if(app.name == "Adobe Photoshop") {
				return "ps";
			}
			else if(app.name == "Adobe Illustrator") {
				return "ai";
			}
			else if(app.name == "Adobe AfterEffects") {
				return "ae";
			}
		}
		if(typeof(fl) != "undefined") {
			return "fl";
		}
		
		//Browsers
		if(typeof(navigator) != "undefined") {
			var theAppName = navigator.appName.toString().toLowerCase();
			switch(theAppName) {
				case "microsoft internet explorer":
					return "ie";
				case "netscape":
					if(navigator.userAgent.indexOf("Firefox") != -1) {
						return "fx";
					}
					if(navigator.userAgent.indexOf("Safari") != -1) {
						return "sa";
					}
					return "ns";
				case "opera":
					return "op";
				default:
					if(navigator.appCodeName == "Mozilla") {
						return "mo";	
					}
					break;
			}
		}
		
		return "none";
	}));
}

gTewonderLocalScopeFunction();
