<?xml version="1.0" encoding="UTF-8"?>
<krpano>
  <!-- Global variables used by actions and plugins -->
  <krpano 
        tour_soundson="true" 
        tour_soundsvolume="89" 
        tour_autotourenabled="false"
        tour_autorotateenabled="false"
        tour_controlmodemousetype="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="tablet|mobile" />
  <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 (isdesktop, setControlMode(get(tour_controlmodemousetype)););</action>
  <action name="setControlModeDragTo">setControlMode(drag2d);</action>
  <action name="setControlModeMoveTo">setControlMode(moveto);</action>
  <action name="setControlMode">
    set(control.mousetype, %1);
    set(tour_controlmodemousetype, %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>

  <krpano tour_firststartactiondone="false" />


  <action name="startbehavioursxmlcompleteaction">
    events.dispatch(onPanoStart);
    ifnot (tour_firststartactiondone,
      events.dispatch(onTourStart);
      set(tour_firststartactiondone, true);
    );
  </action>

<!--Ajout d'un écran pour indiquer qu'il s'agit d'une version de travail-->
  
<layer name="splashscreenlayerbg"
         keep="true"
         align="center"
         type="container"
         width="100%" height="100%"
         bgalpha="0.00"
         bgcolor="0x000000"
         preload="true"
         onclick="hideintroimage();"
         bgcapture="true"
         zorder="98"
         enabled="true"/>
		 
  <layer name="splashscreenlayer"
         url="graphics/bandeau-travauxv2.png"
         align="top"
		 y="20"
         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">
    tween(layer[splashscreenlayer].alpha, 1.0, WAIT);
    delayedcall(hideintroimagecall, 10, hideintroimage() ); 
  </action>

  <action name="skipintroaction">
  
   </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"/>
  <action name="startautorotation">
    set(tour_autorotateenabled, true );
    set(autorotate.enabled, true);
    set(tour_autorotation_pausecounter, 0);
    events.dispatch(onstartautorotation);
  </action>
  <action name="stopautorotation">
    set(tour_autorotateenabled, false);
    set(autorotate.enabled, false);
    events.dispatch(onstopautorotation);
  </action>
  <action name="pauseautorotation">
    if(tour_autorotateenabled,
      if(%1 == forceplugin,
        inc(tour_autorotation_pauseplugin);
      );
      set(autorotate.enabled, false);
      inc(tour_autorotation_pausecounter);
      events.dispatch(onpauseautorotation);
    );
  </action>
  <action name="resumeautorotation">
    if(tour_autorotateenabled,
      if(%1 == forceplugin,
        if (tour_autorotation_pauseplugin GT 0,
          dec(tour_autorotation_pauseplugin);
        );
      );
      if (tour_autorotation_pausecounter GT 0,
        if(%1 == forceresume,
          set(tour_autorotation_pausecounter, 0);
          set(tour_autorotation_pauseplugin, 0);
         ,
          dec(tour_autorotation_pausecounter);
        );
        if(tour_autorotation_pausecounter == 0,
          set(autorotate.enabled, true);
          events.dispatch(onresumeautorotation);
        );
      );
    );
  </action>
  <events name="autorotation_events" onnewpano="if(tour_autorotation_pauseplugin LE 0,resumeautorotation(forceresume););" keep="true"/>
  <events name="autorotationstartevents" onTourStart="autorotationatstart();" keep="true"/>
  <action name="autorotationatstart">
    if (norotation === null, startautorotation(););
    set(events[autorotationstartevents].keep, false);
  </action>

  <!-- AUTOTOUR -->

  <krpano autotourdelay="5" />
  <action name="startautotour">
    set(tour_autotourenabled, true);startautorotation();
    events.dispatch(onstartautotour);
    resetautotourvariables();
  </action>

  <action name="resetautotourvariables">
    Math.abs(rotationspeed, autorotate.speed);
    if (rotationspeed == 0, set(rotationspeed, 5));

    sub(viewfov, view.hlookatmax, view.hlookatmin);
    if (viewfov LT 360, mul(viewfov, 2));

    div(halfspeed, rotationspeed, 2);
    div(angleonspeed, viewfov, rotationspeed);

    set(autotourdelay, 0);
    add(autotourdelay, halfspeed, angleonspeed);

    add(autotourdelay, autorotate.waittime);
    delayedcall(autotour_call_id, get(autotourdelay), autotourtimer);
  </action>
  <action name="stopautotour">
    set(tour_autotourenabled, false);
    stopdelayedcall(autotour_call_id);stopautorotation();
    events.dispatch(onstopautotour);
  </action>
  <action name="autotourtimer">
    if (tour_autotourenabled,
      if (tour_autorotateenabled,
        if (autorotate.enabled,loadNextScene();
        );
      );
    );
  </action>
  <events name="autotourevents"
          onnewpano="autotouronnewpanoaction"
          onmousedown="autotouronuseraction"
          onkeydown="autotouronuseraction"
          keep="true"/>
  <action name="autotouronnewpanoaction">
    if (tour_autotourenabled, stopdelayedcall(autotour_call_id); resetautotourvariables(););
  </action>
  <action name="autotouronuseraction">
    if (tour_autotourenabled, stopdelayedcall(autotour_call_id); resetautotourvariables(););
  </action>

  <krpano tour_deeplinkingvars=""/>
  <action name="computeDeepLinkingURL">
    txtadd(tour_deeplinkingvars, "s=", get(xml.scene));
    Math.round(viewhlookat, view.hlookat);
    mod(viewhlookat, 360);
    if (viewhlookat GT 180,
      sub(viewhlookat, 360);
     ,
      if (viewhlookat LT -180, add(viewhlookat, 360));
    );
    Math.round(viewvlookat, view.vlookat);
    Math.round(viewfov    , view.fov);
    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,
        inc(hotspot[%1].frame,1,get(hotspot[%1].lastframe),0);
        mul(hotspot[%1].ypos,hotspot[%1].frame,hotspot[%1].frameheight);
        txtadd(hotspot[%1].crop,'0|',get(hotspot[%1].ypos),'|',get(hotspot[%1].framewidth),'|',get(hotspot[%1].frameheight));
        delayedcall(%2, animate(%1,%2) );
      );
    );
  </action>
  <action name="startspotanimation">
    set(tour_stopsequence, false);
    set(stopspotsequence , false);
    animate(get(name)    , %1);
  </action>
  <action name="stopspotanimation">
    set(stopspotsequence, true);
    setdefaultanimatedspotframe();
  </action>
  <action name="setdefaultanimatedspotframe">
    txtadd(defaultcrop, "0|0|", get(framewidth), "|", get(frameheight));
    set(crop, get(defaultcrop));
  </action>
  <action name="interruptAnimation">
    ifnot (tour_stopsequence === undefined,
      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");
	,
		if(%2 == "",
			set(tooltipCurrentTextfieldLayer, "panotourTooltipDefaultText");
		,
			set(tooltipCurrentTextfieldLayer, %2);
		);
	);
	ifnot (currentTooltipText == "",
		
		tooltipTextSettingsUpdate(%1, %3, %4);
		
		set(tooltipHtmlText, get(currentTooltipText));
		escape(tooltipHtmlText);
		
		set(layer[get(tooltipCurrentTextfieldLayer)].html, get(tooltipHtmlText));

		set(layer[get(tooltipCurrentTextfieldLayer)].visible, true);
		
		
		div(halfWidth, layer[get(tooltipCurrentTextfieldLayer)].width, 2);
		
		
		if(%1 != "center",
			sub(leftMargin, get(mouse.x), get(halfWidth));
			add(rightMargin, get(mouse.x), get(halfWidth));
		,
			set(leftMargin, 0);
			set(rightMargin, 0);
		);
		
		
		indexoftxt(alignedOnRight, %1, right, 0);
		indexoftxt(alignedOnLeft, %1, left, 0);
		if(%3 == "right",
			if(alignedOnRight != -1,
				set(rightMargin, 0);
			);
		);
		if(%3 == "left",
			if(alignedOnLeft != -1,
				set(leftMargin, 0);
			);
		);
		
		
		set(totalHeight, get(layer[get(tooltipCurrentTextfieldLayer)].height));
		
		
		if(%1 != "center",
			sub(topMargin, get(mouse.y), get(totalHeight));
			if(%3 == "top",
				add(bottomMargin, get(mouse.y), get(totalHeight));
			,
				set(bottomMargin, get(mouse.y));
			);
		,
			set(topMargin, 0);
			set(bottomMargin, 0);
		);
		
		
		indexoftxt(alignedOnBottom, %1, bottom, 0);
		indexoftxt(alignedOnTop, %1, top, 0);
		if(%3 == "top",
			if(alignedOnTop != -1,
				set(topMargin, 0);
			);
		);
		if(%3 == "bottom",
			if(alignedOnBottom != -1,
				set(bottomMargin, 0);
			);
		);
		
		if(leftMargin LT 0,
			set(tooltipPositionX, get(halfWidth));
			
			
			if(%1 == "hotspot",
				if(topMargin LT 0,
					set(layer[get(tooltipCurrentTextfieldLayer)].align, topleft);
				,
					if(bottomMargin GT stageheight,
						set(layer[get(tooltipCurrentTextfieldLayer)].align, bottomleft);
					,
						set(layer[get(tooltipCurrentTextfieldLayer)].align, left);
					);
				);
			);
		,
			if(rightMargin GT stagewidth,
				if(alignedOnRight != -1,
					set(tooltipPositionX, get(halfWidth));
				,
					sub(tooltipPositionX, get(stagewidth), get(halfWidth));
				);
				
				
				if(%1 == "hotspot",
					if(topMargin LT 0,
						set(layer[get(tooltipCurrentTextfieldLayer)].align, topleft);
					,
						if(bottomMargin GT stageheight,
							set(layer[get(tooltipCurrentTextfieldLayer)].align, bottomleft);
						,
							set(layer[get(tooltipCurrentTextfieldLayer)].align, left);
						);
					);
				);
			,
				if(alignedOnRight != -1,
					sub(tooltipPositionX, stagewidth, get(mouse.x));
				,
					if(alignedOnLeft != -1,
						set(tooltipPositionX, get(mouse.x));
					,
						div(tooltipPositionX, stagewidth, 2);
						sub(tooltipPositionX, get(mouse.x), get(tooltipPositionX));
					);
				);
			);
		);
		
		
		set(layer[get(tooltipCurrentTextfieldLayer)].x, get(tooltipPositionX));
		
		if(topMargin LT 0,
			set(tooltipPositionY, get(totalHeight));
			
			
			if(%1 == "hotspot",
				if(leftMargin LT 0,
					set(layer[get(tooltipCurrentTextfieldLayer)].align, topleft);
				,
					if(rightMargin GT stagewidth,
						set(layer[get(tooltipCurrentTextfieldLayer)].align, topright);
					,
						set(layer[get(tooltipCurrentTextfieldLayer)].align, top);
					);
				);
			);
		,
			if(bottomMargin GT stageheight,
				sub(tooltipPositionY, get(stageheight), get(totalHeight));
				
				
				if(%1 == "hotspot",
					if(leftMargin LT 0,
						set(layer[get(tooltipCurrentTextfieldLayer)].align, bottomleft);
					,
						if(rightMargin GT stagewidth,
							set(layer[get(tooltipCurrentTextfieldLayer)].align, bottomright);
						,
							set(layer[get(tooltipCurrentTextfieldLayer)].align, bottom);
						);
					);
				);
			,
				if(alignedOnBottom != -1,
					sub(tooltipPositionY, stageheight, get(mouse.y));
				,
					if(alignedOnTop != -1,
						set(tooltipPositionY, get(mouse.y));
					,
						div(tooltipPositionY, stageheight, 2);
						sub(tooltipPositionY, get(mouse.y), get(tooltipPositionY));
					);
				);
			);
		);
		
		
		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) != "",
		
		if (%1 == "hotspot",
			set(layer[get(tooltipCurrentTextfieldLayer)].align, center);
		,
			set(layer[get(tooltipCurrentTextfieldLayer)].align, %1);
		);
		if (%2 == null,
			set(layer[get(tooltipCurrentTextfieldLayer)].edge, "bottom");
		,
			set(layer[get(tooltipCurrentTextfieldLayer)].edge, %2);
		);
		if (%3 != null,
			set(layer[get(tooltipCurrentTextfieldLayer)].width, %3);
		);
		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"
	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,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="flash"/>
  <action name="setCursor">
    if (tour_controlmodemousetype == moveto, 
      setarrowcursors();
     ,
      sethandcursors();
    );
  </action>
  <!-- Change Cursors Appearance -->
  <!-- Due to a bug over HTML5 plugins on MacOS, we do not set the cursors on Mac -->
  <action name="setarrowcursors">
    if (device.flash,
      if (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);
      );
    );
  </action>
  <action name="sethandcursors">
    if (device.flash,
      if (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);
      );
    );
  </action>

</krpano>