﻿	var Yappa3D = null;

	function InitApplet(appletId, eventfunc)
	{
		Yappa3D = document.getElementById(appletId);
		var aName = navigator.appName.toUpperCase();
		if(aName.indexOf('MICROSOFT')>=0) // Internet Explorer
		{//might be a dotnet applet, init it
			if(document.getElementById(appletId)!=null && (document.getElementById(appletId).DocumentBase==null))
				document.getElementById(appletId).DocumentBase = document.URL;
		}
		setTimeout("EventPolling('"+appletId+"', '"+eventfunc+"');", 10);
	}

	function EventPolling(appletId, eventfunc)
	{
		try{
			var applet = document.getElementById(appletId);
			var type = applet.fetchNextEvent(0);
		}catch(e){
			setTimeout("EventPolling('"+appletId+"', '"+eventfunc+"');", 500);
			return;
		}
		if(type!=0)
		{
			var p1 = applet.fetchNextEvent(1);
			var p2 = applet.fetchNextEvent(2);
			var p3 = applet.fetchNextEvent(3);
			if(type<0)
			{
				if(type==-1)
					window.status = p1;
				if(type==-2)
					window.open(p1, p2);
			}
			else if(eventfunc!="")
				eval(eventfunc+"(type, p1, p2, p3);");
			applet.fetchNextEvent(-1);
		}
		setTimeout("EventPolling('"+appletId+"', '"+eventfunc+"');", 10);
	}

	var rewrwerew = 0;

/*
	function getApplet()
	{
		return document.getElementById("Applet1");
	}
*/
	function getAppletCheck(){
		try{
		//	var a = getApplet().isTextureLoadInProgress();
			var a = Yappa3D.isTextureLoadInProgress();
		}catch(e){
			return false;
		}
		return true;
	}

	function Y_getFrameName(){
		return window.frames[0];
	}

	function toValueArray(array)
	{
		if(array==null)
			return null;
		var va = Yappa3D.newValueArray();
		for(var i in array)
		{
			var item = array[i];
			//safari is a pile of bugs who can't pass primitive types to a function with parameter of type object 
			if(typeof(item)=="number")
				va.addItemF(item);
			else if(typeof(item)=="string")
				va.addItemS(item);
			else if(typeof(item)=="boolean")
				va.addItemB(item);
			else
				va.addItem(item);
		}
		return va;
	}
	function toNativeArray(valueArray,type)
	{
		var type = type || "object";
		if(valueArray==null)
			return null;
		var count = valueArray.getCount();
		var array = new Array(count);
		for(var i=0; i<count; i++){
			array[i] = valueArray.getItemAt(i);
			switch(type){
				case "string":
					array[i] = new String(array[i]);
					break;
				case "number":
					array[i] = new Number(array[i]);
					break;
			}
		}
		return array;
	}

	var MouseActionRotateXY   = 0;
	var MouseActionMove       = 1;
	var MouseActionZoom       = 2;
	var MouseActionRotateXZ   = 3;
	var MouseActionScale      = 4;//supported only in the deisgner

	var MouseDisableBoth      = 0;
	var MouseDisableX         = 1;
	var MouseDisableY         = 2;

	var DragModeRegular       = 0;
	var DragModeWire          = 1;
	var DragModeFlat          = 2;

	var ShadeTypeGouraud      = 0;
	var ShadeTypeEnv          = 1;
	var ShadeTypeTextureMap   = 2;
	var ShadeTypeFlat         = 3;
	var ShadeTypeWire         = 4;
	var ShadeTypeTextureGur   = 5;
	var ShadeTypeTextureEnv   = 6;
	var ShadeTypePhong        = 7;
	var ShadeTypeTexturePhong = 8;
	var ShadeTypeBump         = 9;
	var ShadeTypeTextureBump  = 10;
	var ShadeTypeCartoon      = 11;
	var ShadeTypeWireAA       = 12;

	var AntiAliasNone		= 0;
	var AntiAliasFSAA		= 1;
	var AntiAliasRGSS2x2	= 2;
	var AntiAliasRGSS4x4	= 3;

	var BilinearNever         = 0;
	var BilinearOnNoMotion    = 1;
	var BilinearAlways        = 2;

	var BlendTypeMultiply     = 0;
	var BlendTypeSum          = 1;
	var BlendTypeAverage      = 2;
	var BlendTypeCombina      = 3;

	var MapTexture            = 0;
	var MapAlpha              = 1;
	var MapEnv                = 2;
	var MapBump               = 3;

	var FontPlain             = 0;
	var FontBold              = 1;
	var FontItalic            = 2;
	var FontItalicBold        = 3;

	var CursorDefault         = 0;
	var CursorCrosshair       = 1;
	var CursorText            = 2;
	var CursorWait            = 3;
	var CursorResizeSWNE      = 4;
	var CursorResizeSENW      = 5;
	var CursorResizeNS        = 8;
	var CursorResizeWE        = 10;
	var CursorHand            = 12;
	var CursorMove            = 13;

	var EventShapeClicked         = 1;//param1 is the shape/ApiWrapper, param2 is its transform/ApiWrapper
	var EventSelectedTransChange  = 2;//param1 is the new transform/ApiWrapper, param2 is the old transform/ApiWrapper
	var EventToolButtonPressed    = 3;//param1 is the toolbutton (entity/ApiWrapper), param2 is the toolbutton's message
	var EventSceneLoadFinished    = 4;//no parameters
	var EventTextureLoadFinished  = 5;//param1 is the material/ApiWrapper param2 is the texture url, param2 is the remaining number of pending textures
	var EventOverShapeChange      = 6;//param1 is the new shape/ApiWrapper we are over, param2 is the preious shape/ApiWrapper
	var EventAnimationFinished    = 7;//param1 is the animation/ApiWrapper

	var CameraControllerWalk          = 0;
	var CameraControllerFly           = 1;
	var CameraControllerFlyReversed   = 2;
	var CameraControllerStudy         = 3;

	var StereoModeDisabled       = 0;
	var StereoModeRedBlueGlasses = 1;

	var BillboardFlipNone       = 0;
	var BillboardFlipHorizontal = 1;
	var BillboardFlipVertical   = 2;
	var BillboardFlipBoth       = 3;

	var OutlinesNone                    = 0;
	var OutlinesShape                   = 1;
	var OutlinesSharpEdges              = 2;
	var OutlinesShapeAndSharpEdges      = 3;
	var OutlinesFaceColors              = 4;
	var OutlinesShapeAndFaceColors      = 5;
	var OutlinesSharpEdgesAndFaceColors = 6;
	var OutlinesAll                     = 7;

	var ControlledTransformMovement  = 0;
	var ControlledTransformRotationX = 1;
	var ControlledTransformRotationY = 2;
	var ControlledTransformRotationZ = 3;

	var SortTypeAvg = 0;
	var SortTypeMax = 1;
	var SortTypeMin = 2;

	var EntityAll          = -1;
	var EntityTransform    = 0;
	var EntityShape        = 1;
	var EntityCamera       = 2;
	var EntityLight        = 3;
	var EntityMaterial     = 4;
	var EntityAnimation    = 5;
	var EntityInterpolator = 6;
	var EntityGroup        = 7;
	var EntityBillboard    = 8;
	var EntityLineset      = 9;
	var EntityToolbutton   = 10;

	var UVMappingFace				= 0;
	var UVMappingPlanar			= 1;
	var UVMappingBox				= 2;
	var UVMappingSpherical			= 3;
	var UVMappingCylindrical			= 4;
	var UVMappingCylindricalCapped 		= 5;

	var AxisX = 0;
	var AxisY = 1;
	var AxisZ = 2;

	var UVMappingFlipNone	= 0;
	var UVMappingFlipU	= 1;
	var UVMappingFlipV	= 2;
	var UVMappingFlipBoth	= 3;

	var TransInterpPosition = 0;
	var TransInterpRotation = 1;
	var TransInterpScale    = 2;
