///////////////////////////////////////////////////////////////////////////////
//
//  CreateSilverlight.js   version 0.95
//
//  This file is provided by Microsoft as a helper file for websites that
//  incorporate Silverlight Objects. The default parameters below comply with 
//  Silverlight v1.1 Alpha, which exposes 0.95 as its version number.     
//  This file is provided as is.
// 
// © 2007 Microsoft Corporation. All Rights Reserved.
//
// This file is licensed as part of the Silverlight 1.0 SDK, for details look here: http://go.microsoft.com/fwlink/?LinkID=89145&clcid=0x409
//
///////////////////////////////////////////////////////////////////////////////
// JScript source code
//contains calls to silverlight.js, examples are below

function createSilverlight()
{  
    //example calls, please replace with calls that match your site's requirements    
    //Sys.Silverlight.createObject("xaml/piano.xml", pe, "AgControl1",
                                 //{width:'1024', height:'530', inplaceInstallPrompt:false, background:'white', isWindowless:'false', framerate:'24', version:'0.95.0'},
                                 //{onError:null, onLoad:null},
                                 //null);
                                                                  
    //Sys.Silverlight.createObjectEx({source: 'xaml/piano.xml', parentElement:pe, id:'AgControl1', properties:{width:'1024', height:'530', background:'white', isWindowless:'false', framerate:'24', version:'0.95.0'}, events:{onError:null, onLoad:null}, context:null});    
}

function createSilverlight()
{
	Sys.Silverlight.createObjectEx({
		//source: "TestPage.xaml",
		//source: "TestControl.xaml",
		//source: "TestControlsPage.xaml",
		source: "ItvPage.xaml",
		parentElement: document.getElementById("SilverlightControlHost"),
		id: "SilverlightControl",
		properties: {
			width: document.body.clientWidth,
			height: document.body.clientHeight,
			version: "0.95",  
			background: "white",
			isWindowless: true,
			enableHtmlAccess: true			
		},
		events: {
		    onLoad: OnLoaded
		}
	});
}

function Initialize()
{
    document.getElementById('SilverlightControl').focus()
}

function alertFromCodeEvent(sender, args)
{
    //alert("ScriptAlertFromCodeEvent");
    //alert(sender);
    alert(args.Message);
}

function playFromCodeEvent(sender, args)
{
    window.external.MediaCenter.PlayMedia(2, args.Message);
    window.external.MediaCenter.Experience.GoToFullScreen();
}

function stopFromCodeEvent(sender, args)
{
    window.external.MediaCenter.Experience.PlayRate = 0;
}

//var _sender;
function OnLoaded(sender, args)
{
    //_sender = sender;
    sender.Content.alertObj.AlertEvent = alertFromCodeEvent;
    sender.Content.alertObj.PlayMediaEvent = playFromCodeEvent;
    sender.Content.alertObj.StopMediaEvent = stopFromCodeEvent;
    sender.Content.alertObj.PostInit();
    sender.Content.alertObj.SetSize(document.body.clientWidth, document.body.clientHeight);
    var mce = window.external.MediaCenter;
    if(mce == null)
    {
        sender.Content.alertObj.WithinMce(false);
    }
    else
    {
        sender.Content.alertObj.WithinMce(true);
    }
}

function onRemoteEvent(keyChar)
{
	//boolean handled = _sender.Content.alertObj.RemotePress(keyChar)
	switch (keyChar)
	{
	    case 1: //backspace
		case 8: //escape
		    //TODO need to handle this better
		    //it should exit the app when Back is hit on Categories mode
			return true; //handled
			break;
		default:
			return false; //ignore
	}
}

function IsMCEEnabled()
{
    return true
}

