<krpano version="1.20.9" north="0" logkey="true">

//SOUND

   <action name="PrepareSounds" autorun="onstart">
        preloadsound(over.m4a);
		preloadsound(open.m4a);
		preloadsound(close.m4a);
		preloadsound(move.mp3);
    </action>

//WEBVR

	<include url="%VIEWER%/vrmenu/vrmenu.xml" devices="html5" />
	<include url="%VIEWER%/plugins/webvr.xml" devices="html5" />

	<plugin name="webvr" keep="true" devices="html5.and.webgl"
	        url="%VIEWER%/plugins/webvr.js"
			onavailable="vicinity_webvr_onavailable();"
            onentervr="vicinity_webvr_onentervr()"
	        />

	<action name="vicinity_webvr_onavailable" scope="local">
		if(webvr.isvrbrowser OR simulatevr,
			set(layer[webvr_enterbutton],
				type=text, align=center,x=0,y=0, width='100%', height='100%', bgcolor='0x000000', vcenter=true, zorder=100, bgalpha=1,scale=1,parent='',edge='center',
				css='color:#ffffff;font-family:Primary;font-size:60px;text-align:center;',
				html='Enter VR'
			);
		);
		webvr.loadsettings();
	</action>

	<action name="vicinity_webvr_onentervr">
	set(stagescale,0.6);

		if(layer[webvr_enterbutton], tween(layer[webvr_enterbutton].alpha,0,0); );
		hs_to_googlenav();
		webvr_showbuttons();
		webvr_hide_all_non_vr_layers();

		if(webvr.isfake, webvr_show_fakemode_info(true); );
		webvr_load_vr_cursor_hs();

		webvr_setup();
	</action>

	<action name="webvr_onexitvr">
	set(stagescale,1);
		removehotspot('vr_cursor');
		removehotspot('vr_controller_l');
		removehotspot('vr_controller_r');
		set(have_vr_controllers, false);

		stopdelayedcall(vr_button_fadeout);

		if(layer[webvr_enterbutton], tween(layer[webvr_enterbutton].alpha,1); );
		tween(layer[webvr_exitbutton].alpha,0);
		tween(layer[webvr_setupbutton].alpha,0);

		webvr_show_fakemode_info(false);

		webvr_restore_layers();
	</action>

		<layer name="webvr_enterbutton" keep="true" vr="true"
	       type="text" html="Enter VR"
	       align="bottom" y="15" scale="0.6"
	       autoalpha="true" alpha="0.0"
	       onclick="webvr.enterVR();"
		   devices="all"
	       />

	<action name="vrcontroller_target_point" scope="localonly">
		addhotspot(vrpoint, hs);
		set(hs, keep=true, type=text, bgcolor=0xFFFFFF, bgalpha=1.0, width=10, height=10, bgroundedge=5, bgborder='1 0x000000 1.0', oversampling=2,
			scale=0.4, torigin=world, depth=0, distorted=false, zoom=true, zorder=99998, enabled=false
		  );
		renderloop(
			if(!caller.loaded,
				removehotspot(get(hs.name));
				stoprenderloop();
			  ,
				if(global.display.havedepthmap,
					<!-- use the laser for depthmap panos -->
					removehotspot(get(hs.name));
					stoprenderloop();
					webvr_load_vr_controller_hs('vrcontroller_laser');
				  ,
					calc(hs.bgcolor, caller.pressed ? 0x049AFF : (caller.hovering ? 0x00FF00 : 0xFFFFFF));
					calc(distance, (caller.target AND caller.target.hitd GT 0 ? caller.target.hitd : 1000));
					calc(hs.scale, 0.4 * (distance GT 1000 ? distance / 1000 : (distance LT 200 ? 0.25 : (0.25 + (distance - 200)/800 * 0.75))));
					calc(hs.tx, caller.tx + caller.dx * distance);
					calc(hs.ty, caller.ty + caller.dy * distance);
					calc(hs.tz, caller.tz + caller.dz * distance);
				);
			);
		);
	</action>

//HIDE TOOLTIPS TOUCH

<events name="hidehstouch" onmousedown="hide_touch_hs()" devices="touch" keep="true"/>
<action name="hide_touch_hs">
	for(set(i,0),i LT hotspot.count,inc(i),
	if(hotspot[get(i)].style == popup_hs,
	callwith(hotspot[get(i)],onouttouch());
	););
</action>

//AIR HOTSPOTS

<style name="googlestyle_vr" url="googlehs.png" isvrnav="true" distorted="true" inverserotation="true" edge="top" onclick="googlenav_vr" scale="0.3" atv="-30" rx="-75" alpha="0.5" onover="tween(alpha|scale,1|0.5);playsound(over,over.m4a);"  onout="tween(alpha|scale,0.5|0.3)" mipmapping="true" oversampling="2"
onloaded="if(contains(linkedscene,'3d'),set(url,%SWFPATH%/googlehs_red.png));" />

		<action name="googlenav_vr" scope="local">
		if(caller.linkedscene,
			loadscene(get(caller.linkedscene),null, MERGE|KEEPVIEW|KEEPMOVING, ZOOMBLEND(1.0, calc:(caller.distance / 10)+2, easeInOutSine));
		);
		playsound(move,move.mp3);
	</action>

//POPUP VR

<style name="popup_close" url="close.png" edge="topright" onclick="closepopup()" alpha="0" zorder="24" depth="off" />

<style name="popup_container" type="text" html="" bgroundedge="5" bgcolor="0x000000" width="640" height="0" handcursor="false" bgshadow="0 10 20 0x000000 0.7" zorder="21"  alpha="0" onclick="closepopup()" depth="off" mipmapping="true" oversampling="2"/>

<style name="popup_text" type="text" html="" bg="false" padding="20" width="640" css="font-size:20px;color:#ffffff;" enabled="false" zorder="22"  alpha="0" depth="off" mipmapping="true" oversampling="2"/>

<style name="bar_hotspot" type="text" html="" bgcolor="0xb68250" width="1" height="2" ox="calc:-170" alpha="0" zorder="22" depth="off" mipmapping="true" oversampling="2"/>


<action name="popupvr" protect="true">
hideallhotspots(false);
addhotspot(close_hs,xh);
copy(xh.ath,hotspot[%1].ath);
copy(xh.atv,hotspot[%1].atv);
xh.loadstyle(popup_close);

addhotspot(cont_hs,ch);
copy(ch.ath,hotspot[%1].ath);
copy(ch.atv,hotspot[%1].atv);
ch.loadstyle(popup_container);

addhotspot(txt_hs,th);
copy(th.ath,hotspot[%1].ath);
copy(th.atv,hotspot[%1].atv);
th.loadstyle(popup_text);
set(th.html,data:%1);
set(th.onautosized,add(ch.height,th.height);set(th.onautosized,'');set(textloaded,true));

addhotspot(hs_bar,bh);
copy(bh.ath,hotspot[%1].ath);
copy(bh.atv,hotspot[%1].atv);
bh.loadstyle(bar_hotspot);

callwhen(textloaded,
	tween(xh.oy,calc(- (ch.height /2) * stagescale));
	tween(xh.ox, calc((ch.width /2) * stagescale));
	set(bh.oy,calc((- (ch.height /2) + 80) * stagescale));
	tween(bh.width,40);
);

	tween(xh.alpha,1,1);
	tween(ch.alpha,1,0.3);
	tween(th.alpha,1,0.3);
	tween(bh.alpha,1,0.3);
	set(popupon,true);
    set(plugin[pp_blur].phase, 1);
    tween(plugin[pp_blur].range, 40.0);
	playsound(open,open.m4a);
</action>

<action name="hideallhotspots" protect="true">
	for(set(i, 0), i LT hotspot.count, inc(i),
	if(hotspot[get(i)].ispopup,set(hotspot[get(i)].visible,%1));
	if(hotspot[get(i)].isvrnav,set(hotspot[get(i)].visible,%1));
	);
</action>

<action name="closepopup" protect="true">
tween(plugin[pp_blur].range, 0.0);
set(textloaded,false);
removehotspot(close_hs);
removehotspot(cont_hs);
removehotspot(txt_hs);
removehotspot(hs_bar);
set(popupon,false);
hideallhotspots(true);
playsound(close,close.m4a);
</action>

<plugin name="soundinterface"
        url="%SWFPATH%/plugins/soundinterface.js"
        preload="true"
        rootpath="%VIEWER%/mp3/"
        volume="1.0"
        mute="false"
        panningmodel="simple"
        worldscale="1.0"
        autopause="true"
        autounlock="true"
        />

</krpano>
