/*****************************************************
 *****************************************************
 * vxGlobecastDeployment.js
 * 
 * The deployment file that collates and implements
 * all the required JS.
 
 *** REQUIRES vxUtils.js ***
 
 *****************************************************
 *****************************************************/

//$(document).ready(initWidgets);
/*************************************************************
 *
 * initWidgets(basePath:String)
 *
 * Initial function that implements all the required files.
 *
 *************************************************************/
function initWidgets(basePath, callback)
{
    try
    {
        $.getScript(basePath + 'js/swfobject.js', function()
        {
            debug('Loaded swfobject.js.');

            $.getScript(basePath + 'js/vxUtils.js', function()
            {
                debug('Loaded vxUtils.js.');
                
                var assetBase = getQueryStringParam("assetBase");
                if(!assetBase)
                    var assetBasePath = basePath;
				else
				{
				var assetBasePath = getAssetBasePath(customerToken, siteCode, assetBase);
				}
                var cacheToken = 		"123DFG789";
                var customerToken = 	"vidunia";
                var siteCode = 			"30da33d3-7f22-42bd-8156-26f3c4a1e2b1";
                var serverBase = 		"qa";
				var clientName = 		"Vidunia";
				var siteName = 		    "Vidunia Demo";
				var device =            "Web"; 
                var techId = 			"VXOne";
				var trackingCode = 		"dcs5g40l5vz5bdmxboq3j811s_9b6b";
				var supplierName = 		"kit-digital";
                var sxmlDefinitionUrl = assetBasePath + "sxml/skin.xml";
                var cssDefinitionUrl = 	"css/Vidunia.css";
                
                var params;

                var embedParams = {};
                embedParams.allowScriptAccess = "always";
                embedParams.allowFullscreen = "true";
                embedParams.wmode = "window";

                $.getScript(assetBasePath + 'js/swfobject.js', function()
                {
                    debug('Loaded swfobject.js.');

                    $.getScript(assetBasePath + 'js/vxEmbed.js', function()
                    {
                        debug('Loaded vxEmbed.js.');
                        
                        $.getScript(assetBasePath + 'js/vxEvents.js', function()
                        //$.getScript(assetBasePath + 'js/vxEventManager.js', function()
                        //$.getScript("http://localhost:3001/demo_files/vxEventManager.js", function()
                        {
                            //debug('Loaded vxEventManager.js.');
                            debug('Loaded vxEvents.js.');
                            
                            //$.getScript(assetBasePath + 'js/vxEvents.js', function()
                            $.getScript(assetBasePath + 'js/vxEventManager.js', function()
                            {
                                //debug('Loaded vxEvents.js.');
                                debug('Loaded vxEventManager.js.');
                                
                                addEventListener(vxEvents.APPLICATION_INITIALIZED, callback);

                                $.getScript(assetBasePath + 'js/vxAlerts.js', function()
                                {
                                    debug('Loaded vxAlerts.js.');

                                    $.getScript(assetBasePath + 'js/vxWidgets.js', function()
                                    //$.getScript('http://localhost:3001/demo_files/vxWidgets.js', function()
                                    {
                                        debug('Loaded vxWidgets.js.');
                                    
                                        params =
	                                    {
	                                        cacheToken: cacheToken,
	                                        customerToken: customerToken,
	                                        siteCode: siteCode,
	                                        //inventoryUid:		inventoryUid,
	                                        languageId: 50, //languageId,
	                                        serverBase: serverBase,
	                                        styleSheetUrl: assetBasePath + cssDefinitionUrl,
	                                        componentId: "OSMFPlayer",
	                                        //componentUrl: assetBasePath + "KIT_OSMF_jsCall.swf",
	                                        componentUrl: assetBasePath + "KIT_OSMF_new.swf",
	                                        techId: techId,
	                                        sxmlDefinitionUrl: sxmlDefinitionUrl,
											device: device,
											siteName: siteName,
											clientName: clientName,
											trackingCode: trackingCode,
											supplierName: supplierName
	                                    };
                                        debug("embedSWF: " + params.componentId + ": " + params.componentUrl);
                                        swfobject.embedSWF(assetBasePath + "ComponentLoader.swf", "OSMFPlayer", "500", "320", "10.0.0", assetBasePath + "expressInstall.swf", params, embedParams);
                                        
                                        //if (callback)
                                        //    callback();
                                        //$("#BannerImage img").fadeIn();
                                    });
                                });
                            });
                        });
                    });
                });
            });
        });
    }
    catch (err) {
        debug("error loading flash setup: "+err);
    }
}

debug = function(text) {
    try{console.log(text);}
    catch(err){}
}
