/*Login and server variable*/
//var TRM = "http://bgomps02.vizky.com/"//"file://" + CURRENT_PATH +"scenes/";//TRM URL Location Path//
//var TRM = VizkyGetPathOfHtmlPage() + "USpresident/"
var TRM = "http://BGOMPS02.vizky.com/Demo/USpresident/"
var FileLocation = TRM;
var DirectorIP = "http://10.211.8.89/MPSDirector/MPSWebService.asmx";
/*Login and server variable*/

/* InstantID Variable*/
var extIDMenu = 0;
var extIDLoad = 0;
var extIDMap04 = 0; 
var extIDMap08 = 0;
var extIDSide = 0;
var extIDZoom = 0;
var instIDMenu = 0; //Menu's InstantID//
var instIDLoad = 0; //Loadscene's InstantMenu//
var instIDMap04 = 0; //Map2004 InstantID//
var instIDMap08 = 0; //Map2008 InstantID//
var instIDSide = 0;
var instIDZoom = 0;
var CrrInstMap = 0; //Set CrrInstMap when select on 2004/2008 Map//
var CrrInstSide = 0;
var CrrInstDis = 0; // CurrentInstantID of District Panel playing//
var extIDVp4 = 0;//
var InstIDVp4 = 0;//Used for Load State Panel scene//
//State Instant//
/* InstantID Variable*/

/*Viewport and Station and Channel*/
var Pubstation = 1234;
var stationID = 9876;
var tempCh = 999;
var Max = 10;
var Min = 0;
/*Viewport and Station and Channel*/

/*Overall variable*/
var Option = 0; //No. of Menu when select from menu select//
var Panelplay = 0; //Check Is district panel playing?//
var currentChannelID = 0; //Current District channel playing//
var NewChannel = 0;
var stateclick = 0;
var tmpClick = 0;
/*Overall variable*/

/*SetVariable*/

/*SetVariable*/
//Full Window button scene
var extIDFull = 0;
var instIDFull = 0;
var fullflag = false
//Full Window button scene
function Fullscreen(ControlObject)
{
	ControlObject.SetCommandPipeline(9);
	ControlObject.ClearCommandPipeline();
	ControlObject.ToggleFullscreen();
	if (fullflag)
	{
		ControlObject.ShowDirectorTag(instIDFull,"full","max");
		fullflag = false
	}else
		{
		   ControlObject.ShowDirectorTag(instIDFull,"full","min");
		   fullflag = true
		}
	ControlObject.SetCommandPipeline(0);
}
function PlayLoad (ControlObject)
{
	if(instIDLoad != 0)
	{
		ControlObject.TakeIn(Pubstation, 198, 0, instIDLoad);
	}else
		{
		   extIDLoad = ControlObject.Import(Pubstation, FileLocation + "Load.mps.idx");
		   instIDLoad = ControlObject.Load(Pubstation, extIDLoad);
		   ControlObject.TakeIn(Pubstation, 198, 0, instIDLoad);
		   //Take In Full Screen Scene
		   ControlObject.TakeIn(Pubstation, 69, 0, instIDFull);
		}
	ControlObject.ResetDirector(instIDLoad,"*")
	ControlObject.ResetDirector(instIDFull,"*")
	ControlObject.PlayDirectorToTag(instIDLoad,"Progress","3")
	//ControlObject.ContinueDirector(instIDLoad,"*")
}
function OnVizkyInit(ControlObject)
{
	ControlObject.CreateViewport(7);
	ControlObject.SetConsoleActive(0);
	ControlObject.SetDisplayDownloading(1);
	Pubstation = ControlObject.GenerateStationID(window.location);
	//ControlObject.ShowCursor(1);

	//Pubstation = 98765//Control.Login(DirectorIP);

	ControlObject.SetViewportPercentPositionAndSize(0, 0, 0, 100, 100);
	ControlObject.SetViewportStationAndChannelID(0, Pubstation, 0);	

	ControlObject.SetViewportPercentPositionAndSize(1, 0, 0, 100, 100);
	ControlObject.SetViewportStationAndChannelID(1, Pubstation, 198);

	ControlObject.SetViewportPercentPositionAndSize(2, 0, 0, 100, 100);//MAP Viewport//
	ControlObject.SetViewportPercentPositionAndSize(3, 0, 0, 100, 100);//SIDE Viewport//
	ControlObject.SetViewportPercentPositionAndSize(4, 0, 0, 100, 100);//1st Panel Viewport//
	ControlObject.SetViewportPercentPositionAndSize(5, 0, 0, 100, 100);//Zoom Panel Viewport//
	
	ControlObject.SetViewportPercentPositionAndSize(6, 0, 0, 100, 100);
	ControlObject.SetViewportStationAndChannelID(6, Pubstation, 69);

	ControlObject.CommitAllViewportStationAndChannelChanges();

	// Check file version and current client version;
	var VizkyVersion = ControlObject.GetVersion();
	var VersionArray = VizkyVersion.split(".");
	var currentVersion = ((parseInt(VersionArray[0]) << 28) | (parseInt(VersionArray[1]) << 24) | (parseInt(VersionArray[2]) << 16) | parseInt(VersionArray[3]));
	var requiredVersion = ((1 << 28) | (5 << 24) | (8 << 16) | 0);
	if(currentVersion >= requiredVersion)
	{	
		ControlObject.SetViewportPriorityLevel(0,0);
		ControlObject.SetViewportPriorityLevel(1,1);
		ControlObject.SetViewportPriorityLevel(6,60);
		extIdFull = Control.Import(Pubstation, "http://BGOMPS02.vizky.com/Demo/full/full.mps.idx");
	    instIDFull = Control.Load(Pubstation, extIdFull);
	    ControlObject.SetVariable(Pubstation, 198, "start", 1);//Start the animation of Menu scene and download other scenes too//
	}
	else
		{
			//---------------Vizky Checkversion Text---------class="viz01"----//			
			//alert("Your current Vizky Client version is " + VizkyVersion + ". This page require at least Vizky version 1.3.56.0, Please install new version to preview this page");
			var pleaseInstall2 = '<div class="tv2_millionaer_content millionaer_download" style="font-family: arial; font-size: 12px; padding-right: 200px;"><h2>Please upgrade your Vizky plug-in</h2><p style="font-size: 12px;">Your Vizky version is&nbsp;'+ VizkyVersion +'&nbsp;This page require at least Vizky version 1.5.8.0<br>We now add up more functions in the new version.<br /> Please update your Vizky to experience new enhancement of 3D Graphics.<br /><br /> <a target="_blank" style="color: #ff9000;" href="http://www.vizky.com/download/"><strong>Click to update your Vizky </strong></a><br />The program is developed from Vizrt, the world\'s leader in real-time 3D graphic render for broadcasting which has several major TV channels on the customer lists, including CNN and BBC.<br /></p><p style="font-size: 12px;"><a target="_blank" style="color: #ff9000;" href="http://mps2.vizky.com/node/68">Basic Troubleshooting</a><br /></p><p style="font-size: 12px;">When the program is installed, <strong>Restart the Browser</strong>.</p></div>';
			/*
			var pleaseInstall2 = '<div class="tv2_millionaer_content millionaer_download"style="font-family: arial; font-size: 12px; padding-right: 200px;"><h2 align="left" style="color: #ff9000;">Please upgrade your Vizky plug-in.</h2><p align="left" style="font-size: 12px; color: #ffC030; padding-top: 200px; padding-left: 500px; padding-right: 50px;"> Your Vizky is quite old, we now add up more functions in the new version.<br /> Please update your Vizky to experience new enhancement of 3D Graphics.<br /><br /> <a target="_blank" style="color: #ff9000;" href="http://www.vizky.com/download/"><strong>Click to update your Vizky </strong></a><br />  The program is developed from Vizrt, the world\'s leader in real-time 3D graphic render for broadcasting which has several major TV channels on the customer lists, including CNN and BBC.</p><p align="right" style="font-size: 12px;color: #C08030;padding-right: 50px;"><a target="_blank" style="color: #ff9000;" href="http://mps2.vizky.com/faq">Basic Troubleshooting</a><br /><br />When the program is installed, <strong>Restart the Browser</strong>.</p><p >.</p></div>';
			*/
			//---------------Vizky Checkversion Text-------------//			
			//alert("Your current Vizky Client version is " + VizkyVersion + ". This page require at least Vizky version 1.3.56.0, Please install new version to preview this page");
			document.write(pleaseInstall2);
			//document.getElementById("check").innerHTML = pleaseInstall2;

			//document.write("Your current Vizky Client version is " + VizkyVersion + ". This page require at least Vizky version 1.3.56.0, Please install new version to preview this page")
			//document.write('<H1><a href = "http://da5nvap6twti1.cloudfront.net/installers/windows/VizkySetup1_3_56_1296a.msi">Please install MPS viewer.</a></H1>')
		}
}
function ResetMenu(ControlObject)
{
	ControlObject.ResetDirector(instIDMenu,"*")
}
function TakeInMenu(ControlObject)
{
	PlayLoad (ControlObject)
	
	extIDMenu = ControlObject.Import(Pubstation, FileLocation + "MainMenu.mps.idx");//Menu scenes
	instIDMenu = ControlObject.Load(Pubstation, extIDMenu);

	ControlObject.PlayDirectorToTag(instIDLoad,"Progress","5")
	/* Downnloading other files when click on Option Menu in the first time
	//When loading Menu scene, setting commands below to downloading all MAP in same time//

	//MAP2004//
	extIDMap04 = ControlObject.Import(Pubstation, FileLocation + "US08StaticMapNoZoom.mps.idx");//Map scenes US08StaticMapNoZoom US08StaticMap
	instIDMap04 = ControlObject.Load(Pubstation, extIDMap04);

	//SIDE//
	extIDSide = ControlObject.Import(Pubstation, FileLocation + "XXX2.mps.idx");//Side Panel scenes
	instIDSide = ControlObject.Load(Pubstation, extIDSide);
	
	//Zoom//
	extIDZoom = ControlObject.Import(Pubstation, FileLocation + "ZoomX.mps.idx");//Zoom Panel scenes Zoom
	instIDZoom = ControlObject.Load(Pubstation, extIDZoom);

	//When loading Menu scene, setting commands below to downloading all MAP in same time//
	*/
	ControlObject.WaitBySecond(4.5);//Set for wait time in a second//
	ControlObject.TakeIn(Pubstation, 198, 0, instIDMenu);
	ControlObject.ResetDirector(instIDMenu,'*')
}
function TakeInMap2004(ControlObject)
{
	var GetOpt = Option;
	ControlObject.ResetDirector(instIDMap04,"*")
	ControlObject.TakeIn(Pubstation, 199, 0, instIDMap04);
	switch (GetOpt)
	{
		case(1):
			//Play animation in Option = 1;
			ControlObject.PlayDirectorToTag(instIDMap04,"StaticMapColor","2004")
		break;
		case(2):
			//Play animation in Option = 2;
			ControlObject.PlayDirectorToTag(instIDMap04,"StaticMapColor","poll")
		break;
		case(3):
			//Play animation in Option = 3;
			ControlObject.PlayDirectorToTag(instIDMap04,"StaticMapColor","poll")
		break;
		case(4):
			//Play animation in Option = 4;
			ControlObject.PlayDirectorToTag(instIDMap04,"StaticMapColor","issue")
		break;
	}
	CrrInstMap = instIDMap04;
}
function TakeSide(ControlObject)
{
	var GetOpt = Option
	ControlObject.ResetDirector(instIDSide,"*");
	ControlObject.TakeIn(Pubstation, 200, 0 , instIDSide);
	
	switch (GetOpt)
	{
		case(1):
			ControlObject.ShowDirector(instIDSide,"Main",0)
			ControlObject.PlayDirectorToTag(instIDSide, "Main", "1")
		break;
		case(2):
			ControlObject.ShowDirector(instIDSide,"Main",2.20)
			ControlObject.PlayDirectorToTag(instIDSide, "Main", "2")
		break;
		case(3):
			ControlObject.ShowDirector(instIDSide,"Main",4.28)
			ControlObject.PlayDirectorToTag(instIDSide, "Main", "3")
		break;
		case(4):
			ControlObject.ShowDirector(instIDSide,"Main",6.53)
			ControlObject.PlayDirectorToTag(instIDSide, "Main", "4")
		break;
	}
	CrrInstSide = instIDSide;
}
function TakeZoom(ControlObject)
{
	ControlObject.ResetDirector(instIDZoom,"*")
	ControlObject.TakeIn(Pubstation, 197, 0, instIDZoom);
}
function BackToMenu(ControlObject)
{
	var GetOpt = Option
	if (Panelplay == 1)
	{
		ClosePanel(ControlObject);
	}
	//Side Panel--Play animation hide
	ControlObject.PlayDirectorToTag(CrrInstSide,"Hide","hide")//hide all in side panel

	//Map Panel--Play animation hide
	ControlObject.PlayDirectorToTag(CrrInstMap,"Intro","start")//hide all in Map panel

	ControlObject.WaitBySecond(1);//wait time for play animation out before takeout//
	ControlObject.SetVariable(Pubstation, 198, "backmenu", 1);
}
function OnVizkyLMouseDown(ControlObject,x,y)
{
	var aObject = ControlObject.GetInteractivityObject();
	GetObject = aObject;
	switch (aObject)
	{
		case("menu1")://2004
			Option = 1;
			Control.Log("Option "+Option)
			ControlObject.SetVariable(Pubstation, 198, "menuselect", Option);
		break;
		case("menu2")://Electoral
			Option = 2;
			Control.Log("Option "+Option)
			ControlObject.SetVariable(Pubstation, 198, "menuselect", Option);
		break;
		case("menu3")://Poll
			Option = 3;
			Control.Log("Option "+Option)
			ControlObject.SetVariable(Pubstation, 198, "menuselect", Option);
		break;
		case("menu4")://Issue
			Option = 4;
			Control.Log("Option "+Option)
			ControlObject.SetVariable(Pubstation, 198, "menuselect", Option);
		break;
		case("ResetMenu"):
			ResetMenu(ControlObject);
		break;
		//---MAP PANEL---//
		case("BackMenu"):
			BackToMenu(ControlObject);
		break;
		//---MAP PANEL---//

		//--WEST REGION 11 STATES--//
		case("Washington"):
		case("Oregon"):
		case("California"):
		case("Nevada"):
		case("Idaho"):
		case("Utah"):
		case("Arizona"):
		case("NewMexico"):
		case("Colorado"):
		case("Wyoming"):
		case("Montana"):
		//--WEST REGION 11 STATES--//
		//--MID-WEST REGION 12 STATES--//
		case("Iowa"):
		case("Minnesota"):
		case("Wisconsin"):
		case("Michigan"):
		case("NorthDakota"):
		case("SouthDakota"):
		case("Nebraska"):
		case("Kansas"):
		case("Missouri"):
		case("Illinois"):
		case("Indiana"):
		case("Ohio"):
		//--MID-WEST REGION 12 STATES--//
		//--NORTH-EAST REGION 9 STATES--//
		case("Pensylvania"):
		case("NewYork"):
		case("NewHampshire"):
		case("Vermont"):
		case("Massachusetts"):
		case("Connecticut"):
		case("NewJersey"):
		case("RhodeIsland"):
		case("Maine"):
		//--NORTH-EAST REGION 9 STATES--//
		//--SOUTH REGION 17 STATES--//
		case("Texas"):
		case("Oklahoma"):
		case("Arkansas"):
		case("Louisiana"):
		case("Mississippi"):
		case("Alabama"):
		case("Florida"):
		case("Georgia"):
		case("Tennessee"):
		case("Kentucky"):
		case("SouthCarolina"):
		case("NorthCarolina"):
		case("Virginia"):
		case("WestVirginia"):
		case("Delaware"):
		case("Maryland"):
		case("WashingtonDC"):
		//--SOUTH REGION 17 STATES--//
		//--OTHER REGION 2 STATES--//
		case("Hawaii"):
		case("Alaska"):
			StateClick(ControlObject, GetObject)
		break;
		//--OTHER REGION 2 STATES--//

		//---PANEL BUTTON OBJECT---//
		case("2004"):
			if (Option != 1)
			{
			  //PlayBackOption(ControlObject, 2)
			  ChangeStyle(ControlObject,1)
			}
		break;
		case("Electoral"):
			if (Option != 2)
			{
			  //PlayBackOption(ControlObject, 3)
		      ChangeStyle(ControlObject,2)
			}

		break;
		case("Battle"):
			if (Option != 3)
			{
			  //PlayBackOption(ControlObject, 4)
			  ChangeStyle(ControlObject,3)	
			}
		break;
		case("Issue"):
			if (Option != 4)
			{
			  //PlayBackOption(ControlObject, 5)
			  ChangeStyle(ControlObject,4)
			}

		break;
		case("ClosePanel"):
			ClosePanel(ControlObject);
		break;
		//---PANEL BUTTON OBJECT---//
		
		//Full Screen Window//
		case ("Full"):
			Fullscreen(ControlObject); 
		break;
		//Full Screen Window//
	}
}
function StateClick(ControlObject, GetObject)
{
	var StObj = GetObject;
	stateclick = StObj;
	ControlObject.SetCommandPipeline(1);
	ControlObject.ClearCommandPipeline();
	switch(StObj)
	{
		//--WEST REGION 11 STATES--//
		case("Washington"):// 201 //
			NewChannel = 201;			
			StatePanel(ControlObject)
		break;
		case("Oregon"):// 202 //
			NewChannel = 202;			
			StatePanel(ControlObject)
		break;
		case("California"):// 203 //
			NewChannel = 203;			
			StatePanel(ControlObject)
		break;
		case("Nevada"):// 204 //
			NewChannel = 204;			
			StatePanel(ControlObject)
		break;
		case("Idaho"):// 205 //
			NewChannel = 205;			
			StatePanel(ControlObject)
		break;
		case("Utah"):// 206 //
			NewChannel = 206;			
			StatePanel(ControlObject)
		break;
		case("Arizona"):// 207 //
			NewChannel = 207;			
			StatePanel(ControlObject)
		break;
		case("NewMexico"):// 208 //
			NewChannel = 208;			
			StatePanel(ControlObject)
		break;
		case("Colorado"):// 209 //
			NewChannel = 209;			
			StatePanel(ControlObject)
		break;
		case("Wyoming"):// 210 //
			NewChannel = 210;			
			StatePanel(ControlObject)
		break;
		case("Montana"):// 211 //
			NewChannel = 211;			
			StatePanel(ControlObject)
		break;
		//--WEST REGION 11 STATES--//
		//--MID-WEST REGION 12 STATES--//
		case("Iowa"):// 212 //
			NewChannel = 212;			
			StatePanel(ControlObject)
		break;
		case("Minnesota"):// 213 //
			NewChannel = 213;			
			StatePanel(ControlObject)
		break;
		case("Wisconsin"):// 214 //
			NewChannel = 214;			
			StatePanel(ControlObject)
		break;
		case("Michigan"):// 215 //
			NewChannel = 215;			
			StatePanel(ControlObject)
		break;
		case("NorthDakota"):// 216 //
			NewChannel = 216;			
			StatePanel(ControlObject)
		break;
		case("SouthDakota"):// 217 //
			NewChannel = 217;			
			StatePanel(ControlObject)
		break;
		case("Nebraska"):// 218 //
			NewChannel = 218;			
			StatePanel(ControlObject)
		break;
		case("Kansas"):// 219 //
			NewChannel = 219;			
			StatePanel(ControlObject)
		break;
		case("Missouri"):// 220 //
			NewChannel = 220;			
			StatePanel(ControlObject)
		break;
		case("Illinois"):// 221 //
			NewChannel = 221;			
			StatePanel(ControlObject)
		break;
		case("Indiana"):// 222 //
			NewChannel = 222;			
			StatePanel(ControlObject)
		break;
		case("Ohio"):// 223 //
			NewChannel = 223;			
			StatePanel(ControlObject)
		break;
		//--MID-WEST REGION 12 STATES--//
		//--NORTH-EAST REGION 9 STATES--//
		case("Pensylvania"):// 224 //
			NewChannel = 224;			
			StatePanel(ControlObject)
		break;
		case("NewYork"):// 225 //
			NewChannel = 225;			
			StatePanel(ControlObject)
		break;
		case("NewHampshire"):// 226 //
			NewChannel = 226;			
			StatePanel(ControlObject)
		break;
		case("Vermont"):// 227 //
			NewChannel = 227;			
			StatePanel(ControlObject)
		break;
		case("Massachusetts"):// 228 //
			NewChannel = 228;			
			StatePanel(ControlObject)
		break;
		case("Connecticut"):// 229 //
			NewChannel = 229;			
			StatePanel(ControlObject)
		break;
		case("NewJersey"):// 230 //
			NewChannel = 230;			
			StatePanel(ControlObject)
		break;
		case("RhodeIsland"):// 231 //
			NewChannel = 231;			
			StatePanel(ControlObject)
		break;
		case("Maine"):// 232 //
			NewChannel = 232;			
			StatePanel(ControlObject)
		break;
		//--NORTH-EAST REGION 9 STATES--//
		//--SOUTH REGION 17 STATES--//
		case("Texas"):// 233 //
			NewChannel = 233;			
			StatePanel(ControlObject)
		break;
		case("Oklahoma"):// 234 //
			NewChannel = 234;			
			StatePanel(ControlObject)
		break;
		case("Arkansas"):// 235 //
			NewChannel = 235;			
			StatePanel(ControlObject)
		break;
		case("Louisiana"):// 236 //
			NewChannel = 236;			
			StatePanel(ControlObject)
		break;
		case("Mississippi"):// 237 //
			NewChannel = 237;			
			StatePanel(ControlObject)
		break;
		case("Alabama"):// 238 //
			NewChannel = 238;			
			StatePanel(ControlObject)
		break;
		case("Florida"):// 239 //
			NewChannel = 239;			
			StatePanel(ControlObject)
		break;
		case("Georgia"):// 240 //
			NewChannel = 240;			
			StatePanel(ControlObject)
		break;
		case("Tennessee"):// 241 //
			NewChannel = 241;			
			StatePanel(ControlObject)
		break;
		case("Kentucky"):// 242 //
			NewChannel = 242;			
			StatePanel(ControlObject)
		break;
		case("SouthCarolina"):// 243 //
			NewChannel = 243;			
			StatePanel(ControlObject)
		break;
		case("NorthCarolina"):// 244 //
			NewChannel = 244;			
			StatePanel(ControlObject)
		break;
		case("Virginia"):// 245 //
			NewChannel = 245;			
			StatePanel(ControlObject)
		break;
		case("WestVirginia"):// 246 //
			NewChannel = 246;			
			StatePanel(ControlObject)
		break;
		case("Delaware"):// 247 //
			NewChannel = 247;			
			StatePanel(ControlObject)
		break;
		case("Maryland"):// 248 //
			NewChannel = 248;			
			StatePanel(ControlObject)
		break;
		case("WashingtonDC"):// 249 //
			NewChannel = 249;			
			StatePanel(ControlObject)
		break;
		//--SOUTH REGION 17 STATES--//
		//--OTHER REGION 2 STATES--//
		case("Hawaii"):// 250 //
			NewChannel = 250;			
			StatePanel(ControlObject)
		break;
		case("Alaska"):// 251 //
			NewChannel = 251;			
			StatePanel(ControlObject)
		break;
		//--OTHER REGION 2 STATES--//
	
	}
	ControlObject.Log("stateName : "+stateclick+" Channel : " + NewChannel)
	ControlObject.SetCommandPipeline(0);
}
function PlayBackOption(ControlObject, NewOption)
{
	var NewOpt = NewOption;
	//if (Option != NewOpt)
	//{				
		switch (Option)
		{
			case(1):
				//Play animation 1 back//
			break;
			case(2):
				//Play animation 2 back//
			break;
			case(3):
				//Play animation 3 back//
			break;
			case(4):
				//Play animation 4 back//
			break;
		}
	//}
}
function ChangeStyle(ControlObject, Newopt)
{
	var NewOpt = Newopt
	if (Option != NewOpt)
	{				
		switch (NewOpt)
		{
			case(1):
				if (Option == "2")
				{
					//State Panel animation
					ControlObject.PlayDirectorToTag(CrrInstDis,"Display","1")
					//Side Panel animation
					ControlObject.ShowDirector(CrrInstSide,"Main",0)
					ControlObject.PlayDirectorToTag(CrrInstSide, "Main", "1")
					//Map Scene animation
					ControlObject.PlayDirectorToTag(CrrInstMap, "StaticMapColor" ,"2004")
				}
				else 
				{
					//State Panel animation	
					ControlObject.ShowDirectorTag(CrrInstDis,"Display","2")
					//ControlObject.WaitBySecond(0.4);
					ControlObject.PlayDirectorToTag(CrrInstDis,"Display","1")
					//Side Panel animation
					ControlObject.ShowDirector(CrrInstSide,"Main",0)
					ControlObject.PlayDirectorToTag(CrrInstSide, "Main", "1")
					//Map Scene animation
					ControlObject.ShowDirectorTag(CrrInstMap, "StaticMapColor" ,"poll")
					ControlObject.PlayDirectorToTag(CrrInstMap, "StaticMapColor" ,"2004")
				}
			break;
			case(2):
				if ((Option == "1")||(Option == "3"))
				{
					//State Panel animation
					ControlObject.PlayDirectorToTag(CrrInstDis,"Display","2")
					//Side Panel animation
					ControlObject.ShowDirector(CrrInstSide,"Main",2.20)
					ControlObject.PlayDirectorToTag(CrrInstSide, "Main", "2")
					//Map Scene animation
					ControlObject.PlayDirectorToTag(CrrInstMap, "StaticMapColor" ,"poll")
				}
				else
				{
					//State Panel animation
					ControlObject.ShowDirectorTag(CrrInstDis,"Display","1")
					ControlObject.PlayDirectorToTag(CrrInstDis,"Display","2")
					//Side Panel animation
					ControlObject.ShowDirector(CrrInstSide,"Main",2.20)
					ControlObject.PlayDirectorToTag(CrrInstSide, "Main", "2")
					//Map Scene animation
					ControlObject.PlayDirectorToTag(CrrInstMap, "StaticMapColor" ,"poll")
				}
			break;
			case(3):
				if ((Option == "2")||(Option == "4"))
				{
					//State Panel animation
					ControlObject.PlayDirectorToTag(CrrInstDis,"Display","3")
					//Side Panel animation
					ControlObject.ShowDirector(CrrInstSide,"Main",4.28)
					ControlObject.PlayDirectorToTag(CrrInstSide, "Main", "3")
					//Map Scene animation
					ControlObject.PlayDirectorToTag(CrrInstMap, "StaticMapColor" ,"poll")
				}
				else
				{
					//State Panel animation
					ControlObject.ShowDirectorTag(CrrInstDis,"Display","2")
					ControlObject.PlayDirectorToTag(CrrInstDis,"Display","3")
					//Side Panel animation)
					ControlObject.ShowDirector(CrrInstSide,"Main",4.28)
					ControlObject.PlayDirectorToTag(CrrInstSide, "Main", "3")
					//Map Scene animation
					ControlObject.PlayDirectorToTag(CrrInstMap, "StaticMapColor" ,"poll")
				}
			break;
			case(4):
				if (Option == "3")
				{
					//State Panel animation
					ControlObject.PlayDirectorToTag(CrrInstDis,"Display","4")
					//Side Panel animation
					ControlObject.ShowDirector(CrrInstSide,"Main",6.53)
					ControlObject.PlayDirectorToTag(CrrInstSide, "Main", "4")
					//Map Scene animation
					ControlObject.PlayDirectorToTag(CrrInstMap, "StaticMapColor" ,"issue")
				}
				else
				{				
					//State Panel animation
					ControlObject.ShowDirectorTag(CrrInstDis,"Display","3")
					ControlObject.PlayDirectorToTag(CrrInstDis,"Display","4")					
					//Side Panel animation
					ControlObject.ShowDirector(CrrInstSide,"Main",6.53)
					ControlObject.PlayDirectorToTag(CrrInstSide, "Main", "4")
					//Map Scene animation
					ControlObject.ShowDirectorTag(CrrInstMap, "StaticMapColor" ,"poll")
					ControlObject.PlayDirectorToTag(CrrInstMap, "StaticMapColor" ,"issue")
				}
			break;
		}
	}
	Option = NewOpt;
	ControlObject.Log("New Option : "+ Option)
}
function StatePanel(ControlObject)
{	
	switch(Panelplay)
	{
		case(0): //No District Panel Playing//
				//LoadState(ControlObject);
				ControlObject.SetVariable(Pubstation, 198, "statein", 0);				
		break;
		case(1)://Some District Panel Playing. Need To Replace current panel//
				if ((currentChannelID != NewChannel)||(NewChannel != 0))
				{
				//LoadState(ControlObject);
				ControlObject.TakeIn(Pubstation, currentChannelID, 0, 0)//Take Out current Panel//
				//Try to waiting before TakeIn the new panel state//
				ControlObject.WaitBySecond(1);
				ControlObject.SetVariable(Pubstation, 198, "statein", 1);
				}
				else
					{
					//If Click on same state will not do anything//
					}
		break;
	}
}
function LoadState(ControlObject)
{	
	
	extIDVp4 = ControlObject.Import(Pubstation, FileLocation + stateclick + ".mps.idx");//Pubstation Pubstation .mps.idx
	InstIDVp4 = ControlObject.Load(Pubstation, extIDVp4);
}
function ClosePanel(ControlObject)
{
	ControlObject.PlayDirectorToTag(CrrInstDis,"Hide","hide")// Playanimation Hide
	
	//reset Button stateclick
	ControlObject.ReverseDirector(CrrInstMap, stateclick+"Click", 1);
	ControlObject.ContinueDirector(CrrInstMap, stateclick+"Click");
	//reset Button stateclick

	ControlObject.SetVariable(Pubstation, 198, "close", 1);
}
function StatePlay(ControlObject)
{	
	var GetOpt = Option
	if (tmpClick != NewChannel)
	{
		ControlObject.ResetDirector(instIDZoom,"*")	
		ControlObject.ContinueDirector(instIDZoom, stateclick+"Click")
	}
	else
	{
		ControlObject.ContinueDirector(instIDZoom, stateclick+"Click")
	}			
	//ControlObject.ResetDirector(instIDZoom,"*")		
	//ControlObject.ContinueDirector(instIDZoom, stateclick+"Click")
	switch (GetOpt)
	{
		case(1):
			//Play Panel animation in Option = 1;
			ControlObject.ResetDirector(CrrInstDis,"*")
			ControlObject.ShowDirectorTag(CrrInstDis,"Display","2")
			//ControlObject.WaitBySecond(1);
			ControlObject.PlayDirectorToTag(CrrInstDis,"Panel","end")			
			ControlObject.PlayDirectorToTag(CrrInstDis,"Display","1")
			ControlObject.ShowDirector(CrrInstDis,"Loops",2.1)
			ControlObject.ContinueDirector(CrrInstDis,"Loops")
		break;
		case(2):
			//Play Panel animation in Option = 2;
			ControlObject.ResetDirector(CrrInstDis,"*")
			ControlObject.ShowDirectorTag(CrrInstDis,"Display","1")
			//ControlObject.WaitBySecond(1);
			ControlObject.PlayDirectorToTag(CrrInstDis,"Panel","end")			
			ControlObject.PlayDirectorToTag(CrrInstDis,"Display","2")
			ControlObject.ShowDirector(CrrInstDis,"Loops",2.1)
			ControlObject.ContinueDirector(CrrInstDis,"Loops")
			break;
		case(3):
			//Play Panel animation in Option = 3;
			ControlObject.ResetDirector(CrrInstDis,"*")
			ControlObject.ShowDirectorTag(CrrInstDis,"Display","2")
			ControlObject.PlayDirectorToTag(CrrInstDis,"Panel","end")			
			ControlObject.PlayDirectorToTag(CrrInstDis,"Display","3")
			ControlObject.ShowDirector(CrrInstDis,"Loops",2.1)
			ControlObject.ContinueDirector(CrrInstDis,"Loops")
			break;
		case(4):
			//Play Panel animation in Option = 4;
			ControlObject.ResetDirector(CrrInstDis,"*")
			ControlObject.ShowDirectorTag(CrrInstDis,"Display","3")
			ControlObject.PlayDirectorToTag(CrrInstDis,"Panel","end")			
			ControlObject.PlayDirectorToTag(CrrInstDis,"Display","4")
			ControlObject.ShowDirector(CrrInstDis,"Loops",2.1)
			ControlObject.ContinueDirector(CrrInstDis,"Loops")
		break;
	}
	tmpClick = NewChannel ;
}
function OnVizkyVarChange(ControlObject, varPubstation, varChannelId, szVarName, szVarValue)
{
	//var CkStation = varPubstation;
	var CkStation = Pubstation;
	if(CkStation == Pubstation) //Case Setvariable used for Local station area// 
	{
		ControlObject.Log("Recieve command from Pubstation: "+ CkStation);
		if (szVarName == "statein")
		{
			ControlObject.SetCommandPipeline(1);//
			ControlObject.ClearCommandPipeline();//
			switch (szVarValue)
			{
				case("0") :
					LoadState(ControlObject);
					ControlObject.SetViewportStationAndChannelID(4, Pubstation, NewChannel);
					ControlObject.SetViewportPriorityLevel(4,Max);
					ControlObject.CommitAllViewportStationAndChannelChanges();
					ControlObject.ResetDirector(InstIDVp4,"*");
					ControlObject.TakeIn(Pubstation,NewChannel,0,InstIDVp4)
					CrrInstDis = InstIDVp4;
					//ControlObject.SetVariable(Pubstation, 198, "changechannel", NewChannel);
					currentChannelID = NewChannel;
					Panelplay = 1;
					StatePlay(ControlObject);
				break;
				
				case("1"):
					LoadState(ControlObject);
					ControlObject.SetViewportStationAndChannelID(4, Pubstation, NewChannel);
					//ControlObject.SetViewportPriorityLevel(4,Max);
					ControlObject.CommitAllViewportStationAndChannelChanges();
					ControlObject.ResetDirector(InstIDVp4,"*");
					ControlObject.TakeIn(Pubstation,NewChannel,0,InstIDVp4);
					CrrInstDis = InstIDVp4;
					//ControlObject.SetVariable(Pubstation, 198, "changechannel", NewChannel);
					currentChannelID = NewChannel;
					Panelplay = 1;
					StatePlay(ControlObject);
				break;
			}
		ControlObject.SetCommandPipeline(0);//
		}
		if (szVarName == "start")
		{
			switch(szVarValue)
			{
				case("1"):
					TakeInMenu(ControlObject)
				break;
			}
		}
		if (szVarName == "menuselect")
		{				
			//Set this viewport to recieved SETVAR commands from MPSDirector use Pubstation and Channel 0; Priority = 0//
			ControlObject.SetViewportStationAndChannelID(0, Pubstation, 0);
			//Viewport 1 is Static Viewport used for MainMenu; Priority = 1//
			//Set viewport 2 with Pubstation (Local Publish station) channel 199; Priority = 0 ; Used for MapScene 2004 + 2008// 
			ControlObject.SetViewportStationAndChannelID(2, Pubstation, 199);
			ControlObject.SetViewportPriorityLevel(2,2);

			//Set viewport 3 with Pubstation (Broadcast station) channel 200; Priority = 3 ; Used for "Overall SIDE DATA" scenes//
			ControlObject.SetViewportStationAndChannelID(3, Pubstation, 200);//SIDE
			ControlObject.SetViewportPriorityLevel(3,3);
			
			//Set viewport 4 with Pubstation (Broadcast station) tempCh = 999;Priority = 10 ; Used for 1st State Panel in//
			ControlObject.SetViewportStationAndChannelID(4, Pubstation, tempCh);
			ControlObject.SetViewportPriorityLevel(4,Min);

			//Set viewport 4 with Pubstation (Broadcast station) tempCh = 999;Priority = 10 ; Used for 1st State Panel in//
			ControlObject.SetViewportStationAndChannelID(5, Pubstation, 197);
			ControlObject.SetViewportPriorityLevel(5,5);
		
			ControlObject.CommitAllViewportStationAndChannelChanges();
			//Open Hide director for disable Object in MENU SCENE// 
			ControlObject.PlayDirectorToTag(instIDMenu,"Hide","hide")//another one is tag "hide" will hide when Click "BACKTOMENU"//
			//Open Hide director for disable Object in MENU SCENE//
			ControlObject.SetDisplayDownloading(1);
			
			if (instIDMap04 == "0")
			{
				//MAP2004//
				extIDMap04 = ControlObject.Import(Pubstation, FileLocation + "Map.mps.idx");//Map scenes US08StaticMapNoZoom US08StaticMap
				instIDMap04 = ControlObject.Load(Pubstation, extIDMap04);

				//SIDE//
				extIDSide = ControlObject.Import(Pubstation, FileLocation + "Side.mps.idx");//Side Panel scenes
				instIDSide = ControlObject.Load(Pubstation, extIDSide);
				
				//Zoom//
				extIDZoom = ControlObject.Import(Pubstation, FileLocation + "Zoom.mps.idx");//Zoom Panel scenes Zoom
				instIDZoom = ControlObject.Load(Pubstation, extIDZoom);
			}					
			
			switch(szVarValue)
			{
				case("1"):
				case("2"):
				case("3"):
				case("4"):
					TakeInMap2004(ControlObject)
					TakeSide(ControlObject)
					TakeZoom(ControlObject)
				break;
			}
			//Show the progress bar of downloading Processes
		}
		if (szVarName == "close")
		{
			ControlObject.ReverseDirector(instIDZoom, stateclick+"Click", 1)
			ControlObject.ContinueDirector(instIDZoom, stateclick+"Click")
			if (szVarValue == "1")
			{
				Panelplay = 0;
				ControlObject.SetViewportStationAndChannelID(4, Pubstation, tempCh);
				ControlObject.SetViewportPriorityLevel(4,Min);
				ControlObject.CommitAllViewportStationAndChannelChanges();
				ControlObject.TakeIn(Pubstation, tempCh, 0, 0);
				stateclick = 0;
				CrrInstDis = 0;
				currentChannelID = 0;
				NewChannel = 0;
				tmpClick = 0;
			}
		}
		if (szVarName == "backmenu")
		{
			if (szVarValue == "1")
			{
				ControlObject.SetViewportStationAndChannelID(2, Pubstation, tempCh);
				ControlObject.SetViewportStationAndChannelID(3, Pubstation, tempCh+1);
				ControlObject.SetViewportStationAndChannelID(5, Pubstation, tempCh+2);
				ControlObject.CommitAllViewportStationAndChannelChanges();
				ControlObject.TakeIn(Pubstation, tempCh, 0, 0)//Take Out Map
				ControlObject.TakeIn(Pubstation, tempCh+1, 0, 0)//Take Out Side
				ControlObject.TakeIn(Pubstation, tempCh+2, 0, 0)//Take Out Zoom
				ControlObject.SetViewportPriorityLevel(2,Min);
				ControlObject.SetViewportPriorityLevel(3,Min);
				ControlObject.SetViewportPriorityLevel(5,Min);
				ControlObject.ResetDirector(CrrInstSide,"*")
				ControlObject.ResetDirector(CrrInstMap,"*")
				ControlObject.ResetDirector(instIDZoom,"*")
				CrrInstSide = 0;
				CrrInstMap = 0;
				//ControlObject.PlayDirectorToTag(instIDMenu,"Hide","hide")//another one is tag "show"//
				Option = 0;
				tmpClick = 0;
				NewChannel = 0;
				ControlObject.WaitBySecond(1.5);
				ControlObject.PlayDirectorToTag(instIDMenu,"Hide","show")//another one is tag "show"//
			}
		}
		if (szVarName == "changechannel")
		{
			currentChannelID = szVarValue;
		}
	}
}

