<krpano>
	
	<include url="plugins/webvr.xml" />

	<plugin name="WebVR"
	        multireslock="false"
	        mobilevr_fake_support="true"
	        onavailable="skin_webvr_onavailable();"
	        />

	<action name="skin_webvr_onavailable" scope="local">
		if(webvr.isgearvr,
			<!-- show a special enter VR screen for Gear VR browsers (Oculus Browser or Samsung Internet VR) -->
			set(layer[webvr_enterbutton], 
				align=center, y=0, padding='10 20', 
				css='color:#FFFFFF;font-size:40px;text-align:center;',
			);
		);
		webvr_onavailable();
	</action>


	<!-- WebVR zooming - after 2 seconds staring start zooming, stop and zoom back when looking around -->
	<action name="webvr_zooming" scope="local" autorun="onstart">
		set(movement_tolerance, 0.01);
		set(zoom_speed, 1.0);
		<!--set(max_zoom, 75);-->
		
		copy(last_tick, timertick);
		copy(last_movement_tick, last_tick);
		copy(last_view_hlookat, view.hlookat);
		copy(last_view_vlookat, view.vlookat);
		
		setinterval(webvr_zooming, 0.1,
			copy(cur_tick, timertick);
			if(webvr.isenabled,
				getlooktodistance(move_distance, last_view_hlookat, last_view_vlookat);
				calc(movespeed, move_distance / (cur_tick-last_tick));
				
				calc(movement_tolerance, 0.01 / (webvr.zoom^0.5));
				if(movespeed GT movement_tolerance,
					copy(last_movement_tick, cur_tick);
					tween(zoom_speed, 1.0, 0);
					Math.pow(movespeed, 0.5);
				);
				
				if((cur_tick - last_movement_tick) GT 2000,
					tween(zoom_speed, 1.04);
				);
				
				calc(new_zoom, webvr.zoom * (zoom_speed * (1.0 - movespeed)) );
				clamp(new_zoom, 1, get(max_zoom));
				tween(webvr.zoom, get(new_zoom), 0.1, linear);
				
				calc(webvr.friction, new_zoom GT 2.0 ? (new_zoom - 2.0) / 100.0 : 0);
			  ,
				copy(last_movement_tick, cur_tick);
			);
			copy(last_tick, cur_tick);
			copy(last_view_hlookat, view.hlookat);
			copy(last_view_vlookat, view.vlookat);
		);
	</action>
	
	
	<!-- load a pano image -->	
	<memory maxmem.mobile.or.tablet="200" />
	
	<action autorun="onstart">
		if(example === null, set(example,1); );
		if(example == 1, set(panourl, '../../panos/tokyo45gp/tokyo.xml'); set(max_zoom,75); );
		if(example == 2, set(panourl, '../../panos/ecliptique/ok.xml'); set(max_zoom,10); );
		if(example == 3, set(panourl, 'tour.xml'); set(max_zoom,3); );
		loadpano(get(panourl), null, MERGE|IMAGEONLY);
	</action>
	
</krpano>