<?xml version="1.0" encoding="UTF-8"?>
<krpano>
  <!-- Global variables used by actions and plugins -->
  <krpano 
        tour_soundson="false" 
        tour_soundsvolume="100" 
        tour_autotourenabled="false"
        tour_autorotateenabled="false"
        tour_controlmodemousetype="moveto"
        tour_controlmodetouchtype="drag2d"
        tour_fullscreen="false"
        tour_displaymap="false"
        tour_displaythumbnails="true"
        tour_displayfloorplan="false"
        tour_displayinfo="false"
        tour_displayspots="true"
        tour_displaycontrols="true"
        tour_language="en"/>
  <krpano tour_gyroscopedevices="true" devices="no-desktop.and.html5" />
  <krpano videos_sounds_path="%FIRSTXML%" devices="html5" />
  <krpano videos_sounds_path="%SWFPATH%" devices="flash" />

  <!-- Control Mode Management -->
  <events name="controlmodenewpanoevent" onnewpano="controlmodenewpanoaction();" keep="true"/>
  <action name="controlmodenewpanoaction">if (device.desktop, setControlMode(get(tour_controlmodemousetype));, setControlMode(get(tour_controlmodetouchtype)););</action>
  <action name="setControlModeDragTo">setControlMode(drag2d);</action>
  <action name="setControlModeMoveTo">setControlMode(moveto);</action>
  <action name="setControlMode">
    if (device.desktop,
      set(control.mousetype, %1);
      set(tour_controlmodemousetype, %1);
    ,
      set(control.touchtype, %1);
      set(tour_controlmodetouchtype, %1);
    );
    events.dispatch(oncontrolmodechanged);
  </action>



  <!-- Tour Messages -->
  <action name="getmessage">
    txtadd(real_message_id, get(tour_language), "_", %2);
    set(%1, get(data[get(real_message_id)].content));
  </action>

  <!-- Hide / Show Hotspots -->
  <action name="hideHotspots">
    set(tour_displayspots, false);
    set(nb_spots, get(hotspot.count));
    if (nb_spots != 0, hidepanospotsaction(); );
    events.dispatch(hotspots_visibility_changed);
  </action>
  <action name="showHotspots">
    set(tour_displayspots, true);
    set(nb_spots, get(hotspot.count));
    if (nb_spots != 0, showpanospotsaction(); );
    events.dispatch(hotspots_visibility_changed);
  </action>

  <events name="hideShowHotspotsOnNewPanoEvent" onPanoStart="hideShowHotspotsOnNewPanoAction" keep="true"/>
  <action name="hideShowHotspotsOnNewPanoAction">
    set(nb_spots, get(hotspot.count));
    if (nb_spots != 0,
      if (tour_displayspots, showpanospotsaction(); , hidepanospotsaction(); );
    );
  </action>


  <action name="startbehavioursxmlcompleteaction">
    if (skipintro !== null,
      events.dispatch(onPanoStart);
      ifnot (tour_firststartactiondone,
        events.dispatch(onTourStart);
        set(tour_firststartactiondone, true);
      );
    ,



    set(tour_firststartactiondone, true);

    events.dispatch(onPanoStart);
    );
  </action>


  <layer name="splashscreenlayerbg"
         keep="true"
         align="center"
         type="container"
         width="100%" height="100%"
         bgalpha="0.588235294117647"
         bgcolor="0x3b699e"
         preload="true"
         onclick="hideintroimage();"
         bgcapture="true"
         zorder="98"
         enabled="true"/>
  <layer name="splashscreenlayer"
         url="graphics/ferst.png"
         align="center"
         onclick="hideintroimage();"
         alpha="0"
         onloaded="autohideintroimage();"
         zorder="99"
         keep="true"/>
  <action name="hideintroimage">
    stopdelayedcall(hideintroimagecall);
    tween(layer[splashscreenlayer].alpha, 0.0, 0.5, default,
      tween(layer[splashscreenlayerbg].alpha , 0.0, 0.5, default,
        removelayer(splashscreenlayer);
        
        events.dispatch(onTourStart);
        removelayer(splashscreenlayerbg);
      );
    );
  </action>
  <action name="autohideintroimage">
    hideTooltip();tween(layer[splashscreenlayer].alpha, 1.0, WAIT);
    delayedcall(hideintroimagecall, 5, hideintroimage() ); 
  </action>

  <action name="skipintroaction">
    stopdelayedcall(hideintroimagecall);
    removelayer(splashscreenlayerbg);
    removelayer(splashscreenlayer);
   </action>




  <events name="startTourForJsEvents" onTourStart="startTourForJsEventsAction();" keep="true" />
  <action name="startTourForJsEventsAction">
    js(eventTourStarted());
  </action>





  <action name="mainloadscene">
    interruptAnimation();
    if (xml.scene != %1, loadscene(%1, NULL, MERGE, BLEND(1)); );
  </action>

  <!-- Load Previous Scene -->
  <action name="loadPreviousScene">
    if (%1 != findscene, sub(i, scene.count, 1));
    copy(scenenamei, scene[get(i)].name);
    dec(i);
    if (scenenamei == xml.scene,
      if (i GE 0,
        mainloadscene(get(scene[get(i)].name));
       ,
        sub(lasti, scene.count, 1);
        mainloadscene(get(scene[get(lasti)].name));
      );
     ,
      if(i GE 0, loadPreviousScene(findscene));
    );
  </action>

  <!-- Load Next Scene -->
  <action name="loadNextScene">
    if (%1 != findscene, set(i,0));
    copy(scenenamei, scene[get(i)].name);
    inc(i);
    if (scenenamei == xml.scene,
      if (i LT scene.count,
        mainloadscene(get(scene[get(i)].name));
       ,
        mainloadscene(get(scene[0].name)); );
     ,
      if(i LT scene.count, loadNextScene(findscene));
    );
  </action>


  <!-- AUTOROTATION -->
  <autorotate enabled="false"/>
  <krpano tour_autorotation_pausecounter="0"/>
  <krpano tour_autorotation_pauseplugin="0"/>
  <krpano tour_autorotation_openatstartplugin="0"/>
  <action name="startautorotation">
    if(tour_autorotation_pausecounter LE 0,
      set(tour_autorotateenabled, true );

      invalidatescreen();
      set(autorotate.enabled, true);
      set(tour_autorotation_pausecounter, 0);
      events.dispatch(onstartautorotation);

      if(tour_autotourenabled,
        resetautotourvariables();
      );
    );
  </action>
  <action name="stopautorotation">
    set(tour_autorotateenabled, false);
    set(autorotate.enabled, false);
    events.dispatch(onstopautorotation);

    if(tour_autotourenabled,
      stopautotourtimer();
    );
  </action>
  <action name="pauseautorotation">
    if(%1 == forceplugin,
      inc(tour_autorotation_pauseplugin);
    );
    inc(tour_autorotation_pausecounter);
    if(tour_autorotateenabled,
      set(autorotate.enabled, false);
      events.dispatch(onpauseautorotation);

      if(tour_autotourenabled,
        stopautotourtimer();
      );
    );
  </action>
  <action name="resumeautorotation">
    if(%1 == forceplugin,
      if (tour_autorotation_pauseplugin GT 0,
        dec(tour_autorotation_pauseplugin);
      );
    );
    if (tour_autorotation_pausecounter GE 0,
      if(%1 != forceresume,
        if ((tour_autorotation_pausecounter GT 0) AND (tour_autorotation_pausecounter GT tour_autorotation_pauseplugin),
         dec(tour_autorotation_pausecounter);
        );
      );
    );
    if(tour_autorotateenabled,
      if(tour_autorotation_pausecounter == 0,
        if(%1 != forceresume,
          set(autorotate.enabled, true);
          events.dispatch(onresumeautorotation);

          if(tour_autotourenabled,
            resetautotourvariables();
          );
        );
      );
    ,
      if(%1 != forceresume,
        if(%1 != forceplugin,
          if(%1 != forcehotspot,
            startautorotation();
          );
        ,

          if(tour_autorotation_openatstartplugin == 1,
            if((tour_autorotation_pauseplugin LE 0) AND (tour_autorotation_pausecounter LE 0),
              startautorotation();
            );
          );
        );
      );
    );
  </action>
  <events name="autorotation_events" onnewpano="if(tour_autorotation_pauseplugin LE 0,resumeautorotation(forceresume););" keep="true"/>


  <!-- AUTOTOUR -->

  <krpano autotourdelay="25" />
  <action name="startautotour">
    set(tour_autotourenabled, true);startautorotation();

    events.dispatch(onstartautotour);

  </action>

  <action name="resetautotourvariables">
    stopautotourtimer();
    delayedcall(autotour_call_id, get(autotourdelay), autotourtimer);
  </action>
  <action name="stopautotour">
    set(tour_autotourenabled, false);
    stopautotourtimer();stopautorotation();

    events.dispatch(onstopautotour);
  </action>
  <action name="autotourtimer">
    if (tour_autotourenabled,
      if (tour_autorotateenabled,
        if (autorotate.enabled,loadNextScene();

        );
      );
    );
  </action>
  <action name="stopautotourtimer">
    stopdelayedcall(autotour_call_id);
  </action>
  <events name="autotourevents"
          onnewpano="autotouronnewpanoaction"
          onmousedown="autotouronuseraction"
          onkeydown="autotouronuseraction"
          keep="true"/>
  <action name="autotouronnewpanoaction">
    if (tour_autotourenabled,resetautotourvariables(););
  </action>
  <action name="autotouronuseraction">
    if (tour_autotourenabled,resetautotourvariables(););
  </action>
  <events name="autotourstartevents" onTourStart="autotouratstart();" keep="true"/>
  <action name="autotouratstart">
    if (norotation === null, if (noautotour === null, startautotour();););
    set(events[autotourstartevents].keep, false);
  </action>




  <krpano tour_deeplinkingvars=""/>
  <action name="computeDeepLinkingURL">
    txtadd(tour_deeplinkingvars, "s=", get(xml.scene));
    set(viewhlookat, get(view.hlookat));roundval(viewhlookat, 4);
    mod(viewhlookat, 360);
    if (viewhlookat GT 180,
      sub(viewhlookat, 360);
     ,
      if (viewhlookat LT -180, add(viewhlookat, 360));
    );
    set(viewvlookat, get(view.vlookat));roundval(viewvlookat, 4);
    set(viewfov, get(view.fov));roundval(viewfov, 4);
    txtadd(tour_deeplinkingvars, get(tour_deeplinkingvars), "&amp;h=", get(viewhlookat));
    txtadd(tour_deeplinkingvars, get(tour_deeplinkingvars), "&amp;v=", get(viewvlookat));
    txtadd(tour_deeplinkingvars, get(tour_deeplinkingvars), "&amp;f=", get(viewfov));
    if (%1 !== null,if (%1, txtadd(tour_deeplinkingvars, get(tour_deeplinkingvars), "&amp;skipintro");););
    if (%2 !== null,if (%2, txtadd(tour_deeplinkingvars, get(tour_deeplinkingvars), "&amp;norotation");););

  </action>


  <!-- Spot animation management -->
  <action name="animate">
    if (tour_stopsequence == false,
      if (stopspotsequence == false,
        txtadd(delayedname, %1, 'delay');
        if(hotspot[%1].loaded,
          inc(hotspot[%1].frame,1,get(hotspot[%1].lastframe),0);
          mul(hotspot[%1].ypos,get(hotspot[%1].frame),get(hotspot[%1].frameheight));
          txtadd(hotspot[%1].crop,'0|',get(hotspot[%1].ypos),'|',get(hotspot[%1].framewidth),'|',get(hotspot[%1].frameheight));
        );
        delayedcall(get(delayedname),%2,animate(%1,%2));
      );
    );
  </action>
  <action name="startspotanimation">
    set(tour_stopsequence, false);
    set(stopspotsequence , false);
    animate(get(name), %1);
  </action>
  <action name="stopspotanimation">
    set(hotspot[%1].stopspotsequence, true);
    txtadd(delayedname, %1, 'delay');
    stopdelayedcall(get(delayedname));

  </action>
  <action name="setdefaultanimatedspotframe">
    txtadd(defaultcrop, "0|0|", get(framewidth), "|", get(frameheight));
    set(crop, get(defaultcrop));
  </action>
  <action name="interruptAnimation">
    if(tour_stopsequence == false,
      set(tour_stopsequence, true);
      wait(0.1);
    );
  </action>

  <!-- Disable the default fullscreen mode as it does a fullscreen only on the viewer not "on the tour" -->
  <contextmenu fullscreen="false" versioninfo="false" />

  <!-- Tooltips management -->
<!-- Tooltip Management -->
<krpano tooltipCurrentTextfieldLayer="panotourTooltipDefaultText" coretooltipmess=""/>

<events name="showHideTooltipEvents" onremovepano="hideTooltip();" keep="true" />

<action name="showTooltip">
  if (tooltip !== null,
	getmessage(currentTooltipText, get(tooltip));
	if (%2 == null,
		set(tooltipCurrentTextfieldLayer, "panotourTooltipDefaultText");
	,
		set(tooltipCurrentTextfieldLayer, %2);
	);
	ifnot (currentTooltipText == "",

		tooltipTextSettingsUpdate(%1, %3, %4, %5, %6);
		
		set(tooltipHtmlText, get(currentTooltipText));
		escape(tooltipHtmlText);
		set(layer[get(tooltipCurrentTextfieldLayer)].html, get(tooltipHtmlText));
		set(layer[get(tooltipCurrentTextfieldLayer)].visible, true);
		
		div(halfWidth, get(layer[get(tooltipCurrentTextfieldLayer)].width), 2);
		div(halfHeight, get(layer[get(tooltipCurrentTextfieldLayer)].height), 2);
		
		<!-- Default edge center -->
		set(usedWidth, get(halfWidth));
		set(usedHeight, get(halfHeight));
		
		if(layer[get(tooltipCurrentTextfieldLayer)].edge == "left",
			set(usedWidth, get(layer[get(tooltipCurrentTextfieldLayer)].width));
			add(rightMargin, get(mouse.x), get(usedWidth));
			set(leftMargin, get(mouse.x));
		,
			if(layer[get(tooltipCurrentTextfieldLayer)].edge == "right",
				set(usedWidth, get(layer[get(tooltipCurrentTextfieldLayer)].width));
				set(rightMargin, get(mouse.x));
				sub(leftMargin, get(mouse.x), get(usedWidth));
			,
				add(rightMargin, get(mouse.x), get(usedWidth));
				sub(leftMargin, get(mouse.x), get(usedWidth));
			);
		);
		
		add(rightMargin, get(layer[get(tooltipCurrentTextfieldLayer)].xoffset));
		add(leftMargin, get(layer[get(tooltipCurrentTextfieldLayer)].xoffset));
		
		if(layer[get(tooltipCurrentTextfieldLayer)].edge == "bottom",
			set(usedHeight, get(layer[get(tooltipCurrentTextfieldLayer)].height));
			sub(topMargin, get(mouse.y), get(usedHeight));
			set(bottomMargin, get(mouse.y));
		,
			if(layer[get(tooltipCurrentTextfieldLayer)].edge == "top",
				set(usedHeight, get(layer[get(tooltipCurrentTextfieldLayer)].height));
				set(topMargin, get(mouse.y));
				add(bottomMargin, get(mouse.y), get(usedHeight));
			,
				sub(topMargin, get(mouse.y), get(usedHeight));
				add(bottomMargin, get(mouse.y), get(usedHeight));
			);
		);
		
		add(topMargin, get(layer[get(tooltipCurrentTextfieldLayer)].yoffset));
		add(bottomMargin, get(layer[get(tooltipCurrentTextfieldLayer)].yoffset));
		
		if(leftMargin LT 0,
			set(layer[get(tooltipCurrentTextfieldLayer)].align, "left");
			set(tooltipPositionX, get(usedWidth));
		,
			if(rightMargin GT stagewidth,
				set(layer[get(tooltipCurrentTextfieldLayer)].align, "right");
				set(tooltipPositionX, get(usedWidth));
			,
				div(tooltipPositionX, stagewidth, 2);
				sub(tooltipPositionX, get(mouse.x), get(tooltipPositionX));
				add(tooltipPositionX, get(layer[get(tooltipCurrentTextfieldLayer)].xoffset));
			);
		);
		
		set(layer[get(tooltipCurrentTextfieldLayer)].x, get(tooltipPositionX));
		
		if(topMargin LT 0,
			if(layer[get(tooltipCurrentTextfieldLayer)].align == "center",
				set(layer[get(tooltipCurrentTextfieldLayer)].align, "top");
			,
				txtadd(layer[get(tooltipCurrentTextfieldLayer)].align, "top");
			);
			set(tooltipPositionY, get(usedHeight));
		,
			if(bottomMargin GT stageheight,
				if(layer[get(tooltipCurrentTextfieldLayer)].align == "center",
					set(layer[get(tooltipCurrentTextfieldLayer)].align, "bottom");
				,
					txtadd(layer[get(tooltipCurrentTextfieldLayer)].align, "bottom");
				);
				set(tooltipPositionY, get(usedHeight));
			,
				div(tooltipPositionY, stageheight, 2);
				sub(tooltipPositionY, get(mouse.y), get(tooltipPositionY));
				add(tooltipPositionY, get(layer[get(tooltipCurrentTextfieldLayer)].yoffset));
			);
		);
		
		set(layer[get(tooltipCurrentTextfieldLayer)].y, get(tooltipPositionY));
	);
  );
</action>
<action name="hideTooltip">
	set(layer[get(tooltipCurrentTextfieldLayer)].visible, false);
	set(layer[get(tooltipCurrentTextfieldLayer)].html, '');
</action>

<action name="tooltipTextSettingsUpdate">
	if(get(tooltipCurrentTextfieldLayer) != "",

		set(layer[get(tooltipCurrentTextfieldLayer)].align, "center");
		if (%2 == null,
			set(layer[get(tooltipCurrentTextfieldLayer)].edge, "bottom");
		,
			set(layer[get(tooltipCurrentTextfieldLayer)].edge, %2);
		);
		if (%3 != null,
			set(layer[get(tooltipCurrentTextfieldLayer)].autowidth, false);
			set(layer[get(tooltipCurrentTextfieldLayer)].wordwrap, true);
			set(layer[get(tooltipCurrentTextfieldLayer)].width, %3);
		);
		if (%4 != null,
			set(layer[get(tooltipCurrentTextfieldLayer)].xoffset, %4);
		);
		if (%5 != null,
			set(layer[get(tooltipCurrentTextfieldLayer)].yoffset, %5);
		);
		set(layer[get(tooltipCurrentTextfieldLayer)].zorder, 99);
	);
</action>


<!-- Default HTML5 tooltip style -->
<layer name="panotourTooltipDefaultText"
	keep="true"
	enabled="false"
	capture="false"
	url="%FIRSTXML%/graphics/textfield.swf"
	align="center"
	background="false"
	border="false"
	textshadow="1" textshadowrange="4.0" textshadowangle="45" textshadowcolor="0x000000" textshadowalpha="1"
	css="color:#ffffff;font-family:Arial;font-weight:bold;font-size:14px;text-align:left;"
	height="20" 
	autoheight="true"
	autowidth="auto"
	edge="bottom"
	selectable="false"
	zorder="0"
	padding="2"
	xoffset="0"
	yoffset="0"
	visible="false"
	html=""
/>


  <!-- Keyboard management -->


  <krpano tour_ctrlPressed="false"/>
  <events name="zoomEvents" onkeydown="onKDZ" onkeyup="onKUZ" keep="true"/>
  <action name="onKDZ">if(keycode==17,set(tour_ctrlPressed,true );,if(keycode==107,set(fov_moveforce,-1);,if(keycode==109,set(fov_moveforce,+1);,if(keycode==189,set(fov_moveforce,+1);,if(tour_ctrlPressed==true,if(keycode==96,hideTooltip();lookto(get(panoview.h),get(panoview.v),get(panoview.fov));););););););</action>
  <action name="onKUZ">if(keycode==17,set(tour_ctrlPressed,false);,if(keycode==107,set(fov_moveforce, 0);,if(keycode==109,set(fov_moveforce, 0);,if(keycode==189,set(fov_moveforce, 0);););););</action>

  <!-- Indicate if a scene is seen or not - dispatch an event if the state is changed -->
  <events name="sceneSeenEvents" onnewpano="changeSeenState" keep="true"/>
  <action name="changeSeenState">
    ifnot (scene[get(xml.scene)].seen,
      set(scene[get(xml.scene)].seen, true);
      events.dispatch(onSeenStateChanged);
    );
  </action>


  <!-- Cursors management -->
  <events name="cursorsEvents" onnewpano="setCursor" oncontrolmodechanged="setCursor" keep="true" devices="desktop" />
  <action name="setCursor">
    if (tour_controlmodemousetype == moveto, 
      setarrowcursors();
     ,
      sethandcursors();
    );
  </action>
  <!-- Change Cursors Appearance -->

  <action name="setarrowcursors">
    if (device.flash,
      ifnot(device.mac,
        set(cursors.url  , %FIRSTXML%/graphics/cursors_move.png); 
        set(cursors.type , 8way);
        set(cursors.move    ,   0|0|16|16);
        set(cursors.drag    ,  16|0|16|16);
        set(cursors.arrow_u ,  32|0|16|16);
        set(cursors.arrow_d ,  48|0|16|16);
        set(cursors.arrow_l ,  64|0|16|16);
        set(cursors.arrow_r ,  80|0|16|16);
        set(cursors.arrow_lu,  96|0|16|16);
        set(cursors.arrow_ru, 112|0|16|16);
        set(cursors.arrow_rd, 128|0|16|16);
        set(cursors.arrow_ld, 144|0|16|16);
      );
    ,
      js(kpanotour.Cursors.setMoveCursor());
    );
  </action>
  <action name="sethandcursors">
    if (device.flash,
      ifnot(device.mac,
        set(cursors.url , %FIRSTXML%/graphics/cursors_drag.png);
        set(cursors.type, 2way);
        set(cursors.move,  0|0|32|32);
        set(cursors.drag, 32|0|32|32);
      );
    ,
      js(kpanotour.Cursors.setDragCursor());
    );
  </action>

</krpano>