/**
* Dreamsocket
*  
* Copyright  2005 Dreamsocket.
* All Rights Reserved.  
*
* This software (the "Software") is the property of Dreamsocket and is protected by U.S. and
* international intellectual property laws. No license is granted with respect to the
* software and users may not, among other things, reproduce, prepare derivative works
* of, modify, distribute, sublicense, reverse engineer, disassemble, remove, decompile,
* or make any modifications of the Software without written permission from Dreamsocket.
* Further, Dreamsocket does not authorize any user to remove or alter any trademark, logo,
* copyright or other proprietary notice, legend, symbol, or label in the Software.
* This notice is not intended to, and shall not, limit any rights Dreamsocket has under
* applicable law.
*  
*/

var CodeManager = new Object();


CodeManager.k_includedFiles = {};
CodeManager.jsRootPath= "/video/js/";
CodeManager.cssRootPath = "";

// include does nothing if file has already been included
CodeManager.includeFile = function(p_fileSpec) 
{
	var s = "";
	if (CodeManager.k_includedFiles[p_fileSpec] == null) 
	{
		// add file to list of included
		CodeManager.k_includedFiles[p_fileSpec] = true;
		
		if (p_fileSpec.indexOf(".js") == p_fileSpec.length - 3)
		{	// include javascript
			p_fileSpec = CodeManager.jsRootPath + p_fileSpec;	
			s = '<script type="text/javascript" src="' + p_fileSpec + '"></script>';
		}
		else
		{	// include css
			p_fileSpec = CodeManager.cssRootPath + p_fileSpec;	
			s = ('<link rel="stylesheet" type="text/css" href="' + p_fileSpec + '" />');
		}

		document.writeln(s);
	}
}

CodeManager.registerPackage = function(p_path) 
{
 	var a = p_path.split('.');
  	var i = 0;
  	var len = a.length;
  	var pkg; 
  	var o; 
  	var tmpPkg;
  	
  	while (i < len) 
  	{
    	pkg = a[i];
    	
    	if(i == 0)
    	{
    		o = (eval("typeof(" + pkg + ")") == "undefined") ? eval(pkg + "= {};") : eval(pkg);
    	}
    	else
    	{
      		o = o[pkg] = (o[pkg] == undefined) ? {} : o[pkg];
    	}
    	i++;
  	}

  	return o;  	
}


CodeManager.importClass = function(p_path) 
{
	p_path = p_path.split(".").join("/");
	CodeManager.includeFile(p_path + ".js");
}


CodeManager.registerClass = function(p_path) 
{
	var pkg = CodeManager.registerPackage( p_path.substring(0, p_path.lastIndexOf(".")) );
	var cls = p_path.substring(p_path.lastIndexOf(".") + 1, p_path.length); 
	pkg[cls] = eval(cls);
}



// register class
CodeManager.registerClass("com.dreamsocket.utils.CodeManager");
