var playerScene = null;
var playerIsReady = false;

function createSilverlight()
{
	playerScene = new PanacheSilverlightPlayerJS.Scene();
	Silverlight.createObjectEx({
		source: 'PanachePlayer.xaml',
		parentElement: document.getElementById('SilverlightPlugInHost'),
		id: 'SilverlightPlugIn',
		properties: {
			width: '720',
			height: '510',
			background:'#000000', 
            isWindowless: 'true',
			version: '1.0'
		},
		events: {
		    onError: doNothing,
			onLoad: silverlightLoaded /*Silverlight.createDelegate(playerScene, playerScene.handleLoad)*/
		},		
		context: null 
	});
}

function doNothing()
{
}

function silverlightLoaded(plugIn, userContext, rootElement)
{
    playerScene.handleLoad(plugIn, userContext, rootElement);
    playerIsReady = true;
}

if (!window.Silverlight) 
	window.Silverlight = {};

Silverlight.createDelegate = function(instance, method) {
	return function() {
        return method.apply(instance, arguments);
    }
}

var panacheOpts = null;

function setPanacheOptions(optIn, clickToOptIn, seekToInteractive, extendedTimeMS)
{
    if (panacheOpts == null)
        panacheOpts = new Panache.Options();
        
    panacheOpts.OptInInteractive = optIn;
    if (optIn)
    {
        panacheOpts.ClickToOptIn = clickToOptIn;
        panacheOpts.SeekToInteractive = seekToInteractive;
        if (seekToInteractive)
        {
            var timeInSecs = parseFloat(extendedTimeMS) / 1000;
            panacheOpts.ExtendedDuration = timeInSecs;
        }
    }
}

function usePackageXML(sXMLFileURL)
{
    if (panacheOpts == null)
        panacheOpts = new Panache.Options();
        
    panacheOpts.XMLSource = sXMLFileURL;
}

function loadPanacheVideo(sURL, partner, templateSet, templateKeys)
{
    if (playerScene != null)
    {
        playerScene.loadMBDD(sURL, templateSet, templateKeys, panacheOpts, partner);
    }
}
