var uniObj;
var objFlex;

/**
  * This method creates the unity3d div
  */
function createDiv(id, x, y, width, height)
{
	var strModelFilePath = 'content/en_US/'+ '3d_mod_' + id + '.unity3d';
	uniObj = new UnityObject(strModelFilePath, id, width, height);
	
	var newDiv = document.createElement('div');
	newDiv.setAttribute('id',id);
	newDiv.style.width = width;
	newDiv.style.height = height;
	newDiv.style.position = "absolute";
	newDiv.style.left = x;
	newDiv.style.top = y;
	newDiv.innerHTML = uniObj.writeEmbedDOM();
	document.body.appendChild(newDiv);
}

/**
  * This method moves the div to the desired location
  */
function moveDivTo(id, x, y)
{
	var unityDiv = document.getElementById(id);
	unityDiv.style.left = x;
	unityDiv.style.top = y;
}

/**
  * This method resizes the div - required for hiding / showing the unity3d div
  */
 function resizeDiv(id, width, height)
{
	var unityDiv = document.getElementById(id);
	
	if(unityDiv == null)
	{
		return;
	}
	
	unityDiv.style.overflow = 'scroll';
	unityDiv.style.width = width;
	unityDiv.style.height = height;
}

/**
  * This method removes the unity3d div
  */
 function removeDiv(id, zIndex)
{
	var unityDiv = document.getElementById(id);
	document.body.removeChild(unityDiv);
	uniObj = null;
}

/**
  * This method calls an unity3d function
  */
function callFunction(id, target, fName, param)
{
	if(uniObj == null) 
	{
		return;
	}
	
	var hndUnity = ''; 
	if (navigator.appVersion.indexOf("MSIE") != -1 && navigator.appVersion.toLowerCase().indexOf("win") != -1) 
	{
		hndUnity = document.getElementById(id + "_object");
	} 
	else if (navigator.appVersion.toLowerCase().indexOf("safari") != -1) 
	{
		hndUnity = document.getElementById(id + "_object")
	} 
	else 
	{
		hndUnity = document.getElementById(id + "_embed");
	}
	hndUnity.SendMessage(target, fName, param);
}

/**
  * This method is called when the unity is loaded
  */
function onUnityLoad(modelName)
{
	objFlex = getFlexObject('flashObject');
	objFlex.onUnityLoaded(modelName);
}

/**
 * This method is invoked by unity3d when unity3d 
 * responds with its state information for the model
 */
function onGetModelState(strData)
{
	if(objFlex == null)
	{
		objFlex = getFlexObject('flashObject');
	}
	
	objFlex.onGetModelState(strData);
}

/**
 * This method is invoked by unity3d when unity3d 
 * responds with its state information for the model
 * after we set the model
 */
function onSetModelState(strData)
{
	if(objFlex == null)
	{
		objFlex = getFlexObject('flashObject');
	}

	objFlex.onSetModelState(strData);
}

/**
  * This method gets the flex object independent of the browser
  */
function getFlexObject(movieName)
{
	if(movieName == null) return;
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[movieName] : document[movieName];
}

/**
  * This method loads the url in a new browser
  */
function launchUrl(url, fullscreen)
{
	var objWin;
	if(fullscreen)
	{
		objWin = window.open(url, "", "fullscreen=yes, scrollbars=yes");
	}
	else
	{
		objWin = window.open(url, "", "scrollbars=yes");
	}

}

/**
* This function open a pop up window and display the received content
* 
*/

function openPrintWindow(strContent)
{
	print_window= window.open ("","printwindow","status=1,width=350,height=150,resizable=1,,scrollbars=1,location=0"); 
	print_window.document.write(strContent);  

}

/**
* This function open a pop up window and display the wellconnected content
* 
*/
function openWindow()
{
   newWin = window.open("http://www.magicsw.com","newwindow","status=1,width=350,height=150,resizable=1,,scrollbars=1,location=0");

}

/**
* This function open a pop up window and display the wellconnected content
* 
*/
function openWindow(action)
{
	frm = document.getElementById("frmOpener");
	frm.target = "_blank";
	frm.method = "post";
	frm.action = action;
	frm.submit();
}

