var imgLang;
var swfPref="";
var seenIntro;

var MM_contentVersion = 6;
var MM_FlashCanPlay;

var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
if ( plugin ) {
		var words = navigator.plugins["Shockwave Flash"].description.split(" ");
	    for (var i = 0; i < words.length; ++i)
	    {
		if (isNaN(parseInt(words[i])))
		continue;
		var MM_PluginVersion = words[i]; 
	    }
	MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
}
else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 
   && (navigator.appVersion.indexOf("Win") != -1)) {
	document.write('<scr' + 'ipt language=VBScript\> \n'); //FS hide this from IE4.5 Mac by splitting the tag
	document.write('on error resume next \n');
	document.write('MM_FlashCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & MM_contentVersion)))\n');
	document.write('</scr' + 'ipt\> \n');
}

function playSpin()
{
	if(MM_FlashCanPlay)
	{
		var theFlashStr="";
		theFlashStr+='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="750" height="600" id="flashSpinMovie" >';
		theFlashStr+='<param name="movie" value="swf/'+swfPref+'fadein.swf" />';
		theFlashStr+='<param name="quality" value="high" />';
		theFlashStr+='<param name="bgcolor" value="#ffffff"/>';
		theFlashStr+='<param name="wmode" value="transparent"/>';
		theFlashStr+='<embed src="swf/'+swfPref+'fadein.swf" quality="high" bgcolor="#ffffff" wmode="transparent" width="750" height="600" name="flashSpinMovie" align="" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>';
		theFlashStr+='</object>';
		
		document.getElementById("flashSpin").style.width="750px";
		document.getElementById("flashSpin").style.height="600px";
		document.getElementById("flashSpin").style.visibility="visible";
		document.getElementById("flashSpin").innerHTML=theFlashStr;
	} else {
		loadNew();
	}
}

function loadNew()
{
	//alert("loadNew() called");
	document.location="phone_home.aspx?doIntro=true";
}

function unHide()
{
	//alert("in unhide");
	document.getElementById("cameraHomeMain").style.visibility="visible";
}

function showPage()
{
	//alert("in showpage");
	document.getElementById("flashSpin").style.visibility="hidden";
	document.getElementById("flashSpin").style.width="1px";
	document.getElementById("flashSpin").style.height="1px";
}

function spinIntro(cBlue)
{
	var pref=((cBlue==1)?"blue_":"");
	if(MM_FlashCanPlay)
	{
		var theFlashStr="";
		theFlashStr+='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="750" height="600" id="spinMovie" >';
		theFlashStr+='<param name="movie" value="swf/'+swfPref+pref+'backtofront.swf" />';
		theFlashStr+='<param name="quality" value="high" />';
		theFlashStr+='<param name="bgcolor" value="#ffffff">';
		theFlashStr+='<param name="wmode" value="transparent">';
		theFlashStr+='<param name="swLiveConnect" value="true">';
		theFlashStr+='<embed src="swf/'+swfPref+pref+'backtofront.swf" quality="high" bgcolor="#ffffff" wmode="transparent" swLiveConnect="true" width="750" height="600" name="spinMovie" align="" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>';
		theFlashStr+='</object>';
		
		//alert(theFlashStr);
		
		document.getElementById("flashSpin").style.width="750px";
		document.getElementById("flashSpin").style.height="600px";
		document.getElementById("flashSpin").style.visibility="visible";
		document.getElementById("flashSpin").innerHTML=theFlashStr;
	} else {
		unHide();
	}
}

function showCameraIntro()
{
	//alert("in SHOWCAMERAINTRO()");
	
	var pref="";
	args=document.location.toString().split("?")[1].split("#")[0];
	args=args.split("&");
	for(x=0; x<args.length; x++)
	{
		if(args[0]=="doIntro=trueblue")
		{
			pref="blue_";
		}
	}
	
	//alert(pref);
	
	if(MM_FlashCanPlay)
	{
		//alert("writing the flash");
		var theFlashStr="";
		theFlashStr+='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="750" height="600" id="spinMovie" >';
		theFlashStr+='<param name="movie" value="swf/'+swfPref+pref+'backtofront_cookie.swf" />';
		theFlashStr+='<param name="quality" value="high" />';
		theFlashStr+='<param name="bgcolor" value="#ffffff">';
		theFlashStr+='<param name="wmode" value="transparent">';
		theFlashStr+='<param name="swLiveConnect" value="true">';
		theFlashStr+='<embed src="swf/'+swfPref+pref+'backtofront_cookie.swf" quality="high" bgcolor="#ffffff" wmode="transparent" swLiveConnect="true" width="750" height="600" name="spinMovie" align="" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>';
		theFlashStr+='</object>';
		
		document.getElementById("flashSpin").style.width="750px";
		document.getElementById("flashSpin").style.height="600px";
		document.getElementById("flashSpin").style.visibility="visible";
		document.getElementById("flashSpin").innerHTML=theFlashStr;
	} else {
		unHide();
	}
}

function cookieIntro()
{
	//alert("in COOKIEINTRO");
	createCookie("seenIntro","true",365*30);
	suffix="_EMEA";
	
	if(swfPref=="apac/")
	{
		suffix="_APAC";
	} else if(swfPref=="ch/")
	{
		suffix="_CHINESE";
	}
	introFile="FINAL_intro"+suffix+".swf";
	
		var theFlashStr="";
		theFlashStr+='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="520" height="370" id="spinMovie" >';
		theFlashStr+='<param name="movie" value="swf/'+introFile+'" />';
		theFlashStr+='<param name="quality" value="high" />';
		theFlashStr+='<param name="bgcolor" value="#ffffff">';
		theFlashStr+='<param name="wmode" value="transparent">';
		theFlashStr+='<param name="swLiveConnect" value="true">';
		theFlashStr+='<embed src="swf/'+introFile+'" quality="high" bgcolor="#ffffff" wmode="transparent" swLiveConnect="true" width="520" height="370" name="spinMovie" align="" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>';
		theFlashStr+='</object>';
		
		//alert(theFlashStr);
		
		document.getElementById("flashSpin").style.width="520px";
		document.getElementById("flashSpin").style.height="370px";
		document.getElementById("flashSpin").style.left="116px";
		document.getElementById("flashSpin").style.top="110px";
		document.getElementById("flashSpin").style.visibility="visible";
		document.getElementById("flashSpin").innerHTML=theFlashStr;
}

function endIntro()
{
	showPage();
	unHide();
	document.getElementById("flashSpin").style.width="750px";
	document.getElementById("flashSpin").style.height="600px";
	document.getElementById("flashSpin").style.left="0px";
	document.getElementById("flashSpin").style.top="0px";
}


function wipeCookie()
{
	createCookie("seenIntro","false",365*30);
	//alert("your 'seenIntro' cookie has now been set to 'false'");
}



function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}





function setup()
{
	cook=document.cookie.split(";");
	imgLang="global";
	seenIntro=false;
	
	//alert(cook);
	for(x=0;x<cook.length;x++)
	{
		a=cook[x];
		if(a.indexOf("lang") != -1)
		{
			imgLang=a.split("=")[1];
		}
		if(a.indexOf("seenIntro=true") != -1)
		{
			seenIntro=true;
		}
	}
		
	//var apac="au,in,id,jp,my,nz,pk,ph,sg,tw,th,vn,ap".split(",");
	var apac="th,au,id,in,my,nz,pk,ph,sg,tw,vn,ap".split(",");
	for(x=0;x<apac.length;x++)
	{
		if(imgLang==apac[x])
		{
			swfPref="apac/";
		}
	}
	
	//var ch="cn,hk,hk-en".split(",");
	var ch="cn,hk,hk-en".split(",");
	for(x=0;x<ch.length;x++)
	{
		if(imgLang==ch[x])
		{
			swfPref="ch/";
		}
	}
	


	if(seenIntro==false)
	{
		showCameraIntro();
		return;
	}



	//alert("COOKIE SAYS:\nseenIntro="+seenIntro+"\nimgLang="+imgLang);

	if(document.location.toString().split("?").length<=1)
	{
		unHide();
		return;
	}
	
	args=document.location.toString().split("?")[1].split("#")[0];
	args=args.split("&");
	for(x=0; x<args.length; x++)
	{
		if(args[0]=="doIntro=true")
		{
			spinIntro(0);
		} else if(args[0]=="doIntro=trueblue")
		{
			spinIntro(1);
		} else {
			unHide();
		}
	}
}










onload = setup;