var isBlur = false;
var ready = false;
var isFirefox = false;
var isUnityActive = false;

if(navigator.userAgent.indexOf("Firefox") != -1){
	isFirefox = true;
}

function UnityActive(pValue){
	//set to true if the user has clicked inside of unity
	isUnityActive = pValue;
	
	if(isUnityActive){
		$(window).focus();
	}
	
}

function ShowUnity(){
	//$("#unity").show('slow');
	
	$("#unity").css("top", "-138px");
	$("#header").css("top", "-138px");
	
}

function sendUserAlert(pMessage){
	$("#alert").show('slow');
	
	var message;
	if(pMessage == 'deny'){
		message = "<img src=\"DATA/delete_button.png\"/><p>You will need to allow flash access to your webcam in order to view this webpage properly</p>";
	} else if(pMessage == 'no_camera'){
		message = "<img src=\"DATA/delete_button.png\"/><p>Our system detects that you do not have a webcam. Please note that you will need a webcam in order to view this page properly.</p>";
	} else if(pMessage == 'using_64bit_safari'){
		message = "<img src=\"DATA/delete_button.png\"/><p>Our system detects that you are using 64 Bit safari. To see the content, switch Safari to 32-bit mode, or use Firefox.</p>";
	}
	
	$(".message").html(message);

}

function setReady(){
	ready = true;
	sayReadyToFlash();
	$(window).focus();
}

$(window).blur(function(){
	stopImageTransfer();
});

$(window).focus(function(){
	startImageTransfer();
});

function getFlashMovie(movieName){
   var isIE = navigator.appName.indexOf("Microsoft") != -1;
   return (isIE) ? window[movieName] : document[movieName];  
}  

function sayReadyToFlash(){
	try{
		getFlashMovie("FLARAlchemyUnityBase").setReady();
	}catch(err){}
}

function startImageTransfer(){
	
	if(ready == true){
		doImage();
		isBlur = false;
	}
	
}

function stopImageTransfer(){

	if(ready == true){
		noImage();	
		isBlur = true;
	}

}

function noImage(){
	try{
		getFlashMovie("FLARAlchemyUnityBase").imageFalse();
	}catch(err){}
}  

function doImage(){
	try{
		getFlashMovie("FLARAlchemyUnityBase").imageTrue();
	}catch(err){}
}

//functions being called from flash

function setImageInfo(imageInfo){
	
	try{
		
		if(getFlashMovie("FLARAlchemyUnityBase") != undefined){
			uniObj.msg('Stage', 'SetImage', imageInfo);
		}
		
	} catch(err){
		
	}

}

/*
function setMatrixInfo(matrixString){
	
	try{
		uniObj.msg('Stage', 'BuildMatrix', matrixString);
	} catch(err){
		//console.log('>> There was an error transfering your matrix');
	}
	
}
*/


