function unity_send(data,unity_object) {
	var unity_name = unity_object ? unity_object : 'UnityObject';
	var obj = (navigator.appName.indexOf("Microsoft") != -1) ? window[unity_name] : window.document[unity_name];
	data = 'msg:' + data;
	obj.SendMessage("core", "MSG", data);
}

function unity_send_internal(data,unity_object) {
	var unity_name = unity_object ? unity_object : 'UnityObject';
	var obj = (navigator.appName.indexOf("Microsoft") != -1) ? window[unity_name] : window.document[unity_name];
	data = 'msg:' + data;
	obj.SendMessage("core", "InternalMSG", data);
}

function unity_receive(data, swf_name) {
	var swf_name = (swf_name) ? swf_name : 'SwfMain'; 
	var obj = (navigator.appName.indexOf("Microsoft") != -1) ? window[swf_name] : window.document[swf_name];

	if (obj && obj.UnityTransfer) {
		obj.UnityTransfer(data);
	}
}
function unity_hide(object_id) {
	var object_id = (object_id) ? (object_id) : 'UnityObject_div';
	var obj = gebi(object_id);
	if (obj) {
	  obj.style.top = '-1000px';
	  obj.style.left = '-1000px';
	}
}
function unity_show(object_id, swf_name) {
	var object_id = (object_id) ? (object_id) : 'UnityObject_div';
	var swf_name = (swf_name) ? swf_name : 'SwfMain'; 
	var obj = gebi(object_id);
	if (obj && obj.style.top == '-1000px') {
		obj.style.top = obj.moveTop ? obj.moveTop + 'px' : '0px';
	  obj.style.left = obj.moveLeft ? obj.moveLeft + 'px' : '0px';
	}
	document.getElementsByName(swf_name)[0].blur();
}
function unity_remove(object_id) {
	var object_id = (object_id) ? (object_id) : 'UnityObject_div';
	var obj = gebi(object_id);
	if (obj) {
		obj.parentNode.removeChild(obj);
	}
	var obj1 = gebi(object_id);
	if (obj1) {
		alert('unity still alive :(');
	}
}

function unity_create(src, width, height, nomove, object_id, unity_object, swf_name) {
	var unity_name = unity_object ? unity_object : 'UnityObject';
	var object_id = (object_id) ? (object_id) : 'UnityObject_div';
	var swf_name = (swf_name) ? swf_name : 'SwfMain'; 
	var obj = gebi(object_id);
	 if (!obj) {
	  obj = document.createElement('DIV');
	  obj.id = object_id;
	  obj.style.position = 'absolute';
	  obj.style.top = '-1000px';
	  obj.style.left = '-1000px';
	  obj.style.width = width + 'px';
	  obj.style.height = height + 'px';
	  document.body.appendChild(obj);
	 } else {

		if (!nomove) {
	    obj.style.top = '-1000px';
	    obj.style.left = '-1000px';
		}
		 
	  obj.style.width = width + 'px';
	  obj.style.height = height + 'px';
	  var unity_obj = (navigator.appName.indexOf("Microsoft") != -1) ? window[unity_name] : window.document[unity_name];		 
	  if (unity_obj) return true;
	 }
	 if (!src) return true;
	 
	 var defArgs = {
	  id: unity_name,
	  name: unity_name,
	  width: '100%',
	  height: '100%',
	  src: src,
	  disableContextMenu: 'true', 
	  backgroundcolor: '000000', 
	  bordercolor: '000000', 
	  textcolor: 'FFFFFF', 
	  cancelwrite: true
	};
	var i;
	 for(i = 6; i<arguments.length; i+=2) {
	  defArgs[arguments[i]] = arguments[i+1];
	 }
	 var args = [];
	 for(i in defArgs) {
	  args[args.length] =  i;
	  args[args.length] =  defArgs[i];
	 }
	 obj.innerHTML = AC_UN_RunContent(args);
	 document.getElementsByName(swf_name)[0].blur();

	return true;
}

function unity_move(left, top, relativeObj,object_id) {
	var object_id = (object_id) ? (object_id) : 'UnityObject_div';
	var obj = document.getElementById(object_id);
	if (!obj) {
	  obj = document.createElement('DIV');
	  obj.id = object_id;
	  obj.style.position = 'absolute';
	  obj.style.top = '-1000px';
	  obj.style.left = '-1000px';
		document.body.appendChild(obj);
	}

	obj.last_top = top;
	obj.last_left = left;

	unity_validate(relativeObj,object_id);
}

function unity_validate(relativeObj,object_id, swf_name) {
	var swf_name = (swf_name) ? swf_name : 'SwfMain'; 
	var object_id = (object_id) ? (object_id) : 'UnityObject_div';
	if (typeof relativeObj == 'undefined') {
		relativeObj = (navigator.appName.indexOf("Microsoft") != -1) ? window[swf_name] : window.document[swf_name];
	}

	swf_coords = getCoords(relativeObj);

	var obj = document.getElementById(object_id);
	var top = obj.last_top;
	var left = obj.last_left;

	obj.moveTop = Number(swf_coords.t) + Number(top);
 	obj.moveLeft = Number(swf_coords.l) + Number(left);
	if (obj.style.top != '-1000px') {
		obj.style.top = obj.moveTop + 'px';
		obj.style.left = obj.moveLeft + 'px';
	}
}

function unity_is_installed() {
	return unity_plugin_version() != 0; 
}

function unity_plugin_version() {
	var pluginVersion = 0;
	if (navigator.appVersion.indexOf("MSIE") != -1 && navigator.appVersion.toLowerCase().indexOf("win") != -1) {
		pluginVersion = GetUnityWebPlayerVersion();
	} else {
		if (navigator.mimeTypes && navigator.mimeTypes["application/vnd.unity"]) {
			if (navigator.mimeTypes["application/vnd.unity"].enabledPlugin && navigator.plugins && navigator.plugins["Unity Player"]) {
				var match = navigator.plugins["Unity Player"].description.match(/Unity Player ([0-9a-z]+\.[0-9a-z]+(\.[0-9a-z]+)?)/);
				pluginVersion = match[1];
			}
		}
	}

	if (pluginVersion != 0) {
		var match = pluginVersion.match(/([0-9a-z]+)\.([0-9a-z]+)(\.([0-9a-z]+))?/);
		pluginVersion = {major: match[1], minor: match[2], build: match[4]};
	}

	return pluginVersion;
}

function unity_callback_loaded() {}

function unity_callback_created() {}

