var RosettaStone = function ()  {
    this.includes = new RSIncludeManager();
    this._functions = new Array();
    this.built = false;
    
    this.init = RosettaStone_init;
    this.register = RosettaStone_register;
    this._loadIncludes = RosettaStone_loadIncludes
    this._build = RosettaStone_build;
    this._run = RosettaStone_run;
}

var RosettaStone_init = function ()  {
    this._loadIncludes();
    this._buildInterval = setInterval( "RosettaStone._build()", 1 );
}
var RosettaStone_loadIncludes = function ()  {
	var urn = "";
	
	if( RosettaStonePath != null )
		urn = RosettaStonePath;
	
    new RSInclude( urn + "RSBrowser.js" );
    new RSInclude( urn + "RSFunctions.js" );
    new RSInclude( urn + "RSConfigrc.js" );
    new RSInclude( urn + "RSConfig.js" );
    new RSInclude( urn + "RSThread.js" );
    new RSInclude( urn + "RSDdt.js" );
    new RSInclude( urn + "RSWindow.js" );
    new RSInclude( urn + "RSLayer.js" );
    new RSInclude( urn + "RSImage.js" );
    
    this.includes.commit();
}
var RosettaStone_build = function ()  {
    if( typeof( RSBrowser ) == "function" && typeof( RSThreadManager ) == "function" && typeof( RSConfigurationManager ) == "function" && typeof( RSDdt ) == "function" && typeof( RSWindowManager ) == "function" && typeof( RSLayerManager ) == "function" && typeof( RSWindow ) == "function" && typeof( RSLayerManager ) == "function" && typeof( RSImageManager ) == "function" )  {
    	clearInterval( this._buildInterval );
        this.browser = new RSBrowser();
        this.threads = new RSThreadManager();
        this.config = new RSConfigurationManager();
        this.ddt = new RSDdt();
        this.windows = new RSWindowManager();
        this.mainWindow = new RSWindow();
        this.elements = new RSLayerManager();
        this.images = new RSImageManager();
        this.built = true;
        this.register( "RosettaStone.ddt.Init()" );
        this._run();
    }
}
var RosettaStone_register = function ( functionPointer )  {
	if( this.built == true )
	{
		eval( functionPointer );
		return;
	}

    if( functionPointer != null )
        this._functions[ this._functions.length ] = functionPointer;
}
var RosettaStone_run = function()  {
    for( var func in this._functions )
        eval( this._functions[ func ] );
}

var RSIncludeManager = function ()  {
    this._sessions = new Array();
    this._latestSessionID = null;
    
    this._addSession = RSIncludeManager_addSession;
    this._register = RSIncludeManager_register;
    this.remove = RSIncludeManager_remove;
    this.commit = RSIncludeManager_commit;
}
var RSIncludeManager_addSession = function ()  {
    lID = Math.abs( new Date().getTime() * new Date().getMilliseconds() );
    while( this._sessions[ lID ] != null ) lID++;
    this._sessions[ lID ] = new RSIncludeSession();
    this._latestSessionID = lID;
}
var RSIncludeManager_register = function( includeObject )  {
    if( this._latestSessionID == null ) this._addSession();

    if( this._sessions[ this._latestSessionID ]._index[ includeObject._id ] == null || 
        this._sessions[ this._latestSessionID ].isIncluded( includeObject._path + includeObject._fileName ) )  {
            this._sessions[ this._latestSessionID ]._index[ includeObject._id ] = includeObject;
            this._sessions[ this._latestSessionID ].length++;
    }
}
var RSIncludeManager_remove = function ( fileName )  {
    if( this._latestSessionID != null && ( lRemove = this._sessions[ this._latestSessionID ].isIncluded( fileName ) ) )  {
        this._sessions[ this._latestSessionID ]._index[ lRemove ] = null;
    }
}
var RSIncludeManager_commit = function ()  {
    for( var include in this._sessions[ this._latestSessionID ]._index )  {
        if( this._sessions[ this._latestSessionID ]._index[ include ] != null )  {
            document.write( "<script language='" + this._sessions[ this._latestSessionID ]._index[ include ]._language + "' src='" + this._sessions[ this._latestSessionID ]._index[ include ]._path + this._sessions[ this._latestSessionID ]._index[ include ]._fileName + "'></script>" );
        }
    }
    this._latestSessionID = null;
}

var RSIncludeSession = function ()  {
    this._index = new Array();
    this.length = 0;
    this.isInclude = RSIncludeSession_isIncluded;
}
var RSIncludeSession_isIncluded = function ( fileName )  {
    for( var include in this._index )  {
        lFileToCheck = ( fileName.indexOf( "/" ) != -1 ) ? this._index[ include ]._path + this._index[ include ]._fileName : this._index[ include ]._fileName;
        if( lFileToCheck == fileName ) return( include );
    }

    return( false );
}

var RSInclude = function( fileName )  {
	this._id = new String();
	this._fileName = new String();
	this._baseName = new String();
	this._path = new String();
	this._extension = new String();
	this._language = new String();
	
	this._init = RSInclude_init;
	this._fileAttributes = RSInclude_fileAttributes;
	this._createID = RSInclude_createID;
	
	this._init( fileName )
}
var RSInclude_init = function ( fileName )  {
    this._fileAttributes( fileName );
    this._createID();
    RosettaStone.includes._register( this );
}
var RSInclude_fileAttributes = function ( fileName )  {
    var lFileName = new String( fileName );
    
    this._location = document.location.href.substring( 0, document.location.href.lastIndexOf( "/" ) + 1 );
    if( this._location.substring( this._location.length - 1, this._location.length ) != "/" ) this._location += "/";
    if( this._location )var lSubPath = "./"
    this._path = ( lFileName.lastIndexOf( "/" ) != -1 ) ? lFileName.substring( 0, lFileName.lastIndexOf( "/" ) + 1 ) : "./";
    

    lFileName = lFileName.substring( lFileName.lastIndexOf( "/" ) + 1, lFileName.length );
    this._baseName = ( lFileName.lastIndexOf( "." ) != -1 ) ? lFileName.substring( 0, lFileName.lastIndexOf( "." ) ) : lFileName;
    this._extension = ( lFileName.lastIndexOf( "." ) != -1 ) ? lFileName.substring( lFileName.lastIndexOf( "." ) + 1, lFileName.length ) : "js";
    this._fileName = lFileName;    

    if( this._extension.search( /^vbs$|^vb$|^bas$/ ) != -1 ) this._language = "VBScript";
    else  this._language = "JavaScript";
}
var RSInclude_createID = new Function( "this._id = this._fileName + Math.abs( ( new Date().getTime() * new Date().getMilliseconds() ) >>> this._fileName.charAt( 0 ) );" );

RosettaStone = new RosettaStone();

RosettaStone.init();