// treat this as a static object

var LauncherFactory = new Class({
    
    assetsLoaded: [],
    
    getInstance: function(launcherType){
        
        var scriptID = launcherType + 'JS';
        var cssID = launcherType + 'CSS';

        var isLoaded = false;

        var factory = this;	// reference to self

        if (schmedley.isWidgetLoaded(launcherType)
            || this.assetsLoaded.contains(launcherType)) // evaluates wether or not the supporting JS file for this schmidget is loaded
        {
            this.createInstance(launcherType);
        }
        else {
            var jsPath = 'apps/' + launcherType + '/' + launcherType + comp + '.js';
            var cssPath = 'apps/' + launcherType + '/' + launcherType + '.css';

            new Asset.css(cssPath, {'id': cssID});

            new Asset.javascript(jsPath, {'id': scriptID,
                                          'onload': this.onAssetLoad.bindWithEvent(this, {
                                              'launcherType':launcherType
                                          })
                                         });
        }
    },
    
    onAssetLoad: function(e, params) {

        // add to loaded list
        this.assetsLoaded.include(params.launcherType);

        this.createInstance(params.launcherType)
    },

    createInstance: function(launcherType){
        var launcher;

        switch(launcherType) { // switch based on type, instantiating the correct class
        case 'personal': 
            launcher = new Personal(launcherType, schmedley.getActiveTab().dbID);
            break;
        case 'movies': 
            launcher = new Movies(launcherType, schmedley.getActiveTab().dbID);
            break;
        case 'games': 
            launcher = new Games(launcherType, schmedley.getActiveTab().dbID);
            break;
        case 'radio': 
            launcher = new Radio(launcherType, schmedley.getActiveTab().dbID);
            break;
        case 'rss': 
            launcher = new RSS(launcherType, schmedley.getActiveTab().dbID);
            break;
        case 'email': 
            launcher = new Email(launcherType, schmedley.getActiveTab().dbID);
            break;
        default:
            return;
        }
        launcher.postInit();
    }
});