var FileName = "q3_report_"
var FileNumber = 26
var FileLocation = "http://www.vizrt.com/template/ver1-3/mps/q3/"
var Width = 1000
var Height = 563
var isFullscreen = getURLVar("framework");
if (isFullscreen == "fullscreen") {
	Width = window.screen.width - 100;
	Height = Width * 9/16;
	
} else {
	Width = 1000
	Height = 563
}


//The file name will start with  FileName+"1"+".mps" ( eg. q3_report_1.mps) to  FileName+FileNumber+".mps" (eg. q3_report_15.mps)


var CurrentPresentation = 1;

var StationID = 10112008
var ChannelID = 0;

var FRONT_LAYER = 2
var MIDDLE_LAYER = 1
var BACK_LAYER = 0

var ExtIdFront = 0;
var InstIdFront = 0;
var ExtIdBack = 0;
var InstIdBack = 0;

var ExtIdMain = 0;
var ExtIdForward = 0;
var InstIdMain = new Array(FileNumber)

var CurrentInstIdMain = 0;

function GetSceneName()
{
	return FileName + (CurrentPresentation) + ".mps.idx"
}

function GetNextSceneName()
{
	return FileName + (CurrentPresentation + 1) + ".mps.idx"
}

function LoadCurrentPresentation(ControlObject)
{
	if(InstIdMain[CurrentPresentation -1] == 0)
	{
		//Load
		ControlObject.Log("*** CURRENT : Load scene = " + GetSceneName());
		ExtIdMain = ControlObject.Import(StationID, FileLocation + GetSceneName())
		InstIdMain[CurrentPresentation -1] = ControlObject.Load(StationID, ExtIdMain)
	}
	
	CurrentInstIdMain = InstIdMain[CurrentPresentation -1];	
	
	ControlObject.ResetDirector(CurrentInstIdMain, "*");
	ControlObject.TakeIn(StationID, ChannelID, MIDDLE_LAYER, CurrentInstIdMain)
	
	if(InstIdMain[CurrentPresentation] == 0 && CurrentPresentation < FileNumber)
	{
		//Load for next one in advance
		ControlObject.Log("*** NEXT : Load scene = " + GetNextSceneName());
		ExtIdForward = ControlObject.Import(StationID, FileLocation + GetNextSceneName())
		InstIdMain[CurrentPresentation] = ControlObject.Load(StationID, ExtIdForward)
	}

	
}
function Home(ControlObject)
{
	CurrentPresentation = 1;
	LoadCurrentPresentation(ControlObject)
}

function Next(ControlObject)
{
	if(CurrentPresentation < FileNumber)
	{
		CurrentPresentation++;
		LoadCurrentPresentation(ControlObject)
	}	
}

function Back(ControlObject)
{
	if(CurrentPresentation > 1)
	{
		CurrentPresentation--;
		LoadCurrentPresentation(ControlObject)
	}
}

function Continue(ControlObject)
{
	ControlObject.ContinueDirector(CurrentInstIdMain, "Default");
}

function OnVizkyInit(ControlObject)
{
	ControlObject.CreateViewport(1);
	ControlObject.SetDisplayDownloading(1);
	ControlObject.SetViewportPositionAndSize(0, 0, 0, Width, Height);
	ControlObject.SetViewportStationAndChannelID(0, StationID, ChannelID);
	ControlObject.CommitAllViewportStationAndChannelChanges();
	
	//Load Background
	ExtIdBack = ControlObject.Import(StationID, FileLocation + "back.mps.idx")
	InstIdBack = ControlObject.Load(StationID, ExtIdBack)
	
	//Load Front
	ExtIdFront = ControlObject.Import(StationID, FileLocation + "front.mps.idx")
	InstIdFront = ControlObject.Load(StationID, ExtIdFront)
	
	//TakeIn Back & Front
	ControlObject.TakeIn(StationID, ChannelID, BACK_LAYER, InstIdBack)
	ControlObject.TakeIn(StationID, ChannelID, FRONT_LAYER, InstIdFront)
	
	//Reset Instance Id for Main Scene
	for(var i = 0; i < FileNumber; i++)
	{
		InstIdMain[i] = 0;
	}
	LoadCurrentPresentation(ControlObject)
	
}

function OnVizkyLMouseDown(ControlObject, X, Y)
{
	var szObject = ControlObject.GetInteractivityObject();
	
	switch(szObject)
	{
		case "Home":
			Home(ControlObject);
		break;
		case "Next":
			Next(ControlObject);
		break;
		case "Back":
			Back(ControlObject);
		break;
		case "Continue":
			Continue(ControlObject);
		break;
	}
}


function getURLVar(urlVarName) {
	//divide the URL in half at the '?'
	var urlHalves = String(document.location).split('?');
	var urlVarValue = '';
	if(urlHalves[1]){
	//load all the name/value pairs into an array
		var urlVars = urlHalves[1].split('&');
		//loop over the list, and find the specified url variable
		for(i=0; i<=(urlVars.length); i++){
			if(urlVars[i]){
			//load the name/value pair into an array
			var urlVarPair = urlVars[i].split('=');
				if (urlVarPair[0] && urlVarPair[0] == urlVarName) {
				//I found a variable that matches, load it's value into the return variable
					urlVarValue = urlVarPair[1];
				}
			}
		}
	}
	return urlVarValue;   
}

