var FDC_mainContent = "#mainContent";
var FDC_fdiv = {};
var gameMainOverlayObj = new SWFObject();

FDC_fdiv.frontpage = {file:"frontpage/frontpageContent.swf", ix:0, iy:0, iz:100, iw: 980, ih: 644};
FDC_fdiv.product = {file:"product/productContent.swf", ix:0, iy:0, iz:100, iw: 980, ih: 644};
FDC_fdiv.game = {file:"game/gameContent.swf", ix:0, iy:0, iz:100, iw: 980, ih: 644};
FDC_fdiv.academy = {file:"academy/academyContent.swf", ix:0, iy:0, iz:100, iw: 980, ih: 644};
FDC_fdiv.postEvent = {file:"postEvent/postEventContent.swf", ix:0, iy:0, iz:100, iw: 980, ih: 644};

//FDC_fdiv.gameModeTest = {file:"game/gameMode.swf", ix:751, iy:226, iz:50, iw: 229, ih: 82};
FDC_fdiv.gameModeTest = {file:"game/gameMode.swf", ix:751, iy:217, iz:50, iw: 229, ih: 132};
FDC_fdiv.gameInfo = {file:"game/gameInfo.swf", ix:734.0, iy:267, iz:140, iw: 246, ih: 239};
FDC_fdiv.gameMainOverlay = {file:"game/gameMainOverlay.swf", ix:100, iy:100, iz:800, iw: 980, ih: 644};


FDC_fdiv.webcamTest = {file:"webcam/webcamMotion.swf", ix:15, iy:464, iz:100, iw: 250, ih: 150};
FDC_fdiv.loadingOverlay = {file:"loadingOverlay/loadingOverlay.swf", ix:0, iy:0, iz:400, iw: 980, ih: 644};


FDC_fdiv.overlayTest = {file:"overlayTest.swf", ix:89, iy:159, iz:400, iw: 220, ih: 106};




/*

startGame(string mode,float distance,int time)	
//mode: SB for sportband, WC for webcam, KB for keyboard
//in SB mode, distance and time will be passed

pauseGame()	//pause the game, dont clear record
resumeGame()	//resume the game,
endGame()	// stop racing
chooseCity()	//by changing city
readyToPlay() //call flash to show count down message

getTime()	//return nteger in second
getDistance()	//return float in km
getCity()		//return string
isEnd()		//return boolean to check if the game finished

*/
/*
var func = delegate(this, funcA, 1, 2, 3);

function funcA(a,b,c) {
	return a+b+c; 
}

FDC_openFdiv("postEvent", "{x:10, aCallback:function(){return 1+2+3} }")
*/

/*
gameInfo:

FDC_openFdiv("gameInfo", {aCallback:function(){thisMovie('gameInfo').initInfo(totalDistance); } });
thisMovie('gameInfo').initInfo(totalDistance);
thisMovie('gameInfo').updateInfo(time, distance);


*/


function FDC_openFdiv(id, prop) {
	
	var fdiv = FDC_fdiv[id];
	
	if (fdiv) {
//		alert($("#"+id + "Content").length);
		$("#"+id).remove();
		$("#"+id + "Content").remove();
		
		
//		alert($("#"+id + "Content").length);
		var x = fdiv.ix;
		var y = fdiv.iy;
		var z = fdiv.iz;
		var w = fdiv.iw;
		var h = fdiv.ih;
		
		var aCallback = function() {};
		var dCallback = function() {};
		var isTransparent = false;
		
		var p = {};
		if (typeof prop === 'string') {
			p = eval("("+prop+")");
		}
		else {
			p = prop;
		}
		
		if (p != undefined) {
		
			x = (p.x != undefined) ? p.x : x;
			y = (p.y != undefined) ? p.y : y;
			z = (p.z != undefined) ? p.z : z;
			w = (p.w != undefined) ? p.w : w;
			h = (p.h != undefined) ? p.h : h;
			aCallback = (p.aCallback != undefined) ? p.aCallback : aCallback;
			dCallback = (p.dCallback != undefined) ? p.dCallback : dCallback;
			isTransparent = (p.isTransparent != undefined) ? p.isTransparent : false;
			
		}
		fdiv.x = x;
		fdiv.y = y;
		fdiv.aCallback = aCallback;
		fdiv.dCallback = dCallback;
		
		
		

		
		//var so1 = new SWFObject(fdiv.file, id, w, h, flashVersion, "#FFFFFF");
		
		if (id == "gameMainOverlay" || id =="webcamTest" )
		{
			
			if (navigator.appName.indexOf("Microsoft") != -1) {
			
				$(FDC_mainContent).append(jQuery("<div></div>").attr("id", id + "Content"));
				var cssObj = {position: "absolute", left: x, top: y, zIndex: z};
				$("#"+id + "Content").css(cssObj);
				if (id == "gameMainOverlay")
				{
					cssObj = { left: 100,top:100,width:0,height:0,overflow: "hidden"};	
					$("#"+id + "Content").css(cssObj);
				}

				var so1 = new SWFObject(fdiv.file, id, w, h, flashVersion);
				so1.addParam("scale", "noscale");
				so1.addParam("quality", "high");
				so1.addParam("menu","false");
				so1.addParam("wmode","window");
				so1.addParam('allowscriptaccess','always');
				so1.write(id + "Content");
			
			}
			else {
			

				
				$(FDC_mainContent).append(jQuery("<div><div class='mycustomscroll2'><div id='"+id+"_fw' class='fixedwidth'></div></div></div>").attr("id", id + "Content"));
				var cssObj = {position: "absolute", left: x, top: y, zIndex: z};
				$("#"+id + "Content").css(cssObj);
				
				var so1 = new SWFObject(fdiv.file, id, w, h, flashVersion);
				so1.addParam("scale", "noscale");
				so1.addParam("quality", "high");
				so1.addParam("menu","false");
				so1.addParam("wmode","window");
				so1.write(id + "_fw");
		
				
			}	
			
			
			
		}
		else{
			$(FDC_mainContent).append(jQuery("<div></div>").attr("id", id + "Content"));
			var cssObj = {position: "absolute", left: x, top: y, zIndex: z};
			$("#"+id + "Content").css(cssObj);
			
			var so1 = new SWFObject(fdiv.file, id, w, h, flashVersion);
			so1.addParam("scale", "noscale");
			so1.addParam("quality", "high");
			so1.addParam("menu","false");
			so1.addParam("wmode","window");
			so1.write(id + "Content");
		}
		
	}
	
	
}

function FDC_closeFdiv(id) {
	//alert('Close ' + id);
	var fdiv = FDC_fdiv[id];
	
	if (fdiv) {
		
		$("#"+id).remove();
		$("#"+id + "Content").remove();
	}
	
}

function FDC_updateFdiv(id,status) {
	
	//var fdiv = FDC_fdiv["gameMainOverlay"];
	var fdiv = FDC_fdiv[id];
	var cssObj = {};
	var cssObj2 = {};
	var cssObj3 = {overflow:"hidden"};
	if (id == "gameMainOverlay" )
	{
		switch(status)
		{
			/*
			case "regForm":cssObj = { left: 168,top:180.1};cssObj2 = {width:644,height:283.8};break;
			case "webcamIntro":cssObj =  { left: 168.1,top:117.6};cssObj2 = {width:643.9,height:408.8};break;
			case "keyboardIntro":cssObj =  { left: 168,top:180.1};cssObj2 = {width:643.9,height:283.8};break;
			case "nikePlusReg":cssObj = { left: 168,top:180.1};cssObj2 = {width:643.8,height:283.8};break;
			case "changeMode":cssObj = { left: 168,top:180.1};cssObj2 = {width:643.9,height:283.9};break;
			case "loading":cssObj = { left: 168,top:180.1};cssObj2 = {width:643.9,height:283.9};break;
			case "countDown":cssObj = { left: 411.5,top:216};cssObj2 = {width:157.0,height:212.0};break;
			case "quitGame":cssObj = { left: 172.5,top:208.5};cssObj2 = {width:635.0,height:227.0};break;
			case "finishGame":cssObj = { left: 167.5,top:185.6};cssObj2 = {width:645.0,height:272.8};break;
			case "loading":cssObj = { left: 0,top:0};cssObj2 = {width:980,height:644};break;
			*/
			
			case "regForm":cssObj = { left: 168,top:180};cssObj2 = {width:644,height:284};break;
			case "webcamIntro":cssObj =  { left: 168,top:118};cssObj2 = {width:644,height:409};break;
			case "keyboardIntro":cssObj =  { left: 168,top:180};cssObj2 = {width:644,height:284};break;
			case "nikePlusReg":cssObj = { left: 168,top:180};cssObj2 = {width:643.8,height:284};break;
			case "changeMode":cssObj = { left: 168,top:180};cssObj2 = {width:644,height:284};break;
			case "countDown":cssObj = { left: 412,top:216};cssObj2 = {width:157,height:212};break;
			case "quitGame":cssObj = { left: 173,top:209};cssObj2 = {width:635,height:227};break;
			case "finishGame":cssObj = { left: 168,top:186};cssObj2 = {width:645,height:273};break;
			case "loading":cssObj = { left: 0,top:0};cssObj2 = {width:980,height:644};break;
			case "billboard":cssObj = { left: 168,top:42};cssObj2 = {width:644,height:561};break;
			
			
		}
	}
	if (id == "webcamTest")
	{
		switch(status)
		{
			case "startWebcam":cssObj = { left: 15,top:464};cssObj2 = {width:250,height:150};break;
			case "resizeWebcam":cssObj = { left: 15,top:479};cssObj2 = {width:180,height:135};break;
		}
	}

	if (navigator.appName.indexOf("Microsoft") != -1) {
		
		$("#"+id+"Content").css(cssObj).css(cssObj2).css(cssObj3);	
	}
	else {
		
		//$("#gameMainOverlayContent").css({visibility: "hidden"});
		$("#"+id+"Content").css(cssObj);
		if(id == "gameMainOverlay")
		{
			var margin = 18;
			cssObj2.width += margin;
			cssObj2.height += margin;
		}
		$("#"+id+"_fw").css(cssObj2);
		
		
	}
	
	
}



function FDC_showFdiv(id) {
	
	var fdiv = FDC_fdiv[id];
	var cssObj = {left: fdiv.x};
	$("#"+id + "Content").css(cssObj);

	if (id == "gameMainOverlay")
	{
	
		removeOverlay();
		FDC_hideFdiv("gameInfo");
		FDC_hideFdiv("gameModeTest");
		disableMouse();
	}	
}


function FDC_hideFdiv(id) {
	
	//var cssObj = {visibility: "hidden", left: -9999};
	var cssObj = {left: -9999};
	$("#"+id + "Content").css(cssObj);
	
	if (id == "gameMainOverlay")
	{
		enableMouse();
	}
}


function divTest() {
	
	/*alert("divTest");
	
	$(FDC_mainContent).append(jQuery("<div><img src='http://www.google.com.hk/intl/en_com/images/logo_plain.png' /></div>").attr("id", "divContent"));
	var cssObj = {position: "absolute", left: 0, top: 600, zIndex: 400};
	$("#divContent").css(cssObj);
	*/
	$(FDC_mainContent).append(jQuery("<div style=\"position:absolute; top:200px; left:400px;\"><div class='flexcroll mycustomscroll2'><div class='fixedwidth'><object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width=\"980\" height=\"644\" id=\"sampleMx\" align=\"middle\"><param name=\"allowFullScreen\" value=\"true\" /><param name=\"allowScriptAccess\" value=\"sameDomain\" /><param name=\"movie\" value=\"sampleMx.swf\" /><param name=\"quality\" value=\"high\" /><param name=\"bgcolor\" value=\"#333333\" /><embed src=\"sampleMx.swf\" quality=\"high\" bgcolor=\"#333333\" width=\"980\" height=\"644\" name=\"sampleMx\" align=\"middle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" allowFullScreen=\"true\" /></object></div></div></div>").attr("id", "gameMainContent2"));
}

function gameInfoPNG() {
	//var cssObj = {background-image:"images/googleEarth_img.png"};
	//$("#gameInfoContent").css(cssObj);
	//overlayTest(,"googleEarth_img.png");
//	$(FDC_mainContent).append(jQuery("<div><img src='images/googleEarth_img.png' /></div>").attr("id", "gameInfoPNGContent"));
//	var cssObj = {position: "absolute", left: 0, top: 400, zIndex: 240};
//	$("#gameInfoPNGContent").css(cssObj);
	
}
