<krpano>

	<events name="objectskin"
	        onnewpano="setup_object_viewer(backup);"
	        onremovepano="setup_object_viewer(restore);"
	        onenterfullscreen="set(plugin[openfs].visible,false); set(plugin[closefs].visible,true);"
	        onexitfullscreen ="set(plugin[openfs].visible,true); set(plugin[closefs].visible,false);"
	        onmousedown="mdown();"
	        onmouseup="mup();"
	        onidle="showup_rotate_buttons();"
	        onviewchange="if(fullviewfov===null, if(view.fov != 90, copy(fullviewfov,view.fov);roundval(fullviewfov,1); ));
	                      copy(fovrounded,view.fov);
	                      roundval(fovrounded,1);
	                      if(fovrounded LT fullviewfov, set(control.mousespeed,10), set(control.mousespeed,0));"
	        />

	<action name="backup">
		copy(objectbackup.%1,%1);
		set(%1,%2);
	</action>
	
	<action name="restore">
		copy(%1,objectbackup.%1);
	</action>

	<action name="setup_object_viewer">
		<!-- backup and set or restore all settings for viewing objects -->
		%1(idletime, 2.0);
		%1(view.fovtype, HFOV);
		%1(view.limitview, fullrange);
		%1(view.maxpixelzoom, 1.0);
		%1(control.zoomtocursor, true);
		%1(control.zoomoutcursor, true);
		%1(control.mousetype, drag2D);
		%1(control.mousespeed, mousespeed);
		%1(display.stillquality, HIGHSHARP);
	</action>
	

	<!-- object mouse rotate actions -->
	
	<action name="mdown">
		if(control.mousespeed == 0,
			set(mbdown, true);
			set(lastframepos,null);
			objectrotate();
		  );
	</action>

	<action name="mup">
		set(mbdown, false);
	</action>

	<action name="objectrotate">
		div(mxpos, mouse.x, stagewidth);
		mul(framepos, mxpos, image.frames);
		roundval(framepos);

		if(lastframepos == null, copy(lastframepos,framepos));

		sub(framemove, lastframepos, framepos);
		copy(lastframepos,framepos);

		set(rotatedirection, right);
		if(framemove LT 0, mul(framemove,framemove,-1); set(rotatedirection, left); );

		if(mbdown,
			if(framemove != 0,
				if(rotatedirection == left,
					dec(image.frame,get(framemove),1,get(image.frames));
				   ,
					inc(image.frame,get(framemove),get(image.frames),1);
				  );
			  );

			delayedcall(0.01,objectrotate());
		  );
	</action>


	<!-- object UI skin - buttons -->

	<plugin name="rotaterightbg" url="%FIRSTXML%/skin/object_black.png" align="right" width="125" height="100%" alpha="0.0" zorder="1" onover="tween(plugin[rotaterightbg].alpha,0.7);" onout="tween(plugin[rotaterightbg].alpha,0);" ondown="startrotateleft();"  onup="stoprotate();" />
	<plugin name="rotateleftbg"  url="%FIRSTXML%/skin/object_black.png" align="left"  width="125" height="100%" alpha="0.0" zorder="1" onover="tween(plugin[rotateleftbg].alpha,0.7);"  onout="tween(plugin[rotateleftbg].alpha,0);"  ondown="startrotateright();" onup="stoprotate();" />

	<plugin name="rotaterighticon" url="%FIRSTXML%/skin/object_arrow.png" align="right" x="10" scale="0.5" zorder="2" enabled="false" parent="rotaterightbg" />
	<plugin name="rotatelefticon"  url="%FIRSTXML%/skin/object_arrow.png" align="left" edge="right" rotate="180" x="10" scale="0.5" zorder="2" enabled="false"  parent="rotateleftbg" />


	<!-- button actions -->

	<action name="showup_rotate_buttons">
		tween(plugin[rotaterightbg].alpha, 0.7, 1.5, easeOutQuad, tween(plugin[rotaterightbg].alpha, 0.0, 2.5, easeInExpo));
		tween(plugin[rotateleftbg].alpha,  0.7, 1.5, easeOutQuad, tween(plugin[rotateleftbg].alpha,  0.0, 2.5, easeInExpo));
	</action>

	<action name="startrotateleft">
		set(rotateing,true);
		rotateleft();
	</action>

	<action name="startrotateright">
		set(rotateing,true);
		rotateright();
	</action>

	<action name="rotateleft">
		dec(image.frame,1,1,get(image.frames));
		delayedcall(0.02, if(rotateing,rotateleft()) );
	</action>

	<action name="rotateright">
		inc(image.frame,1,get(image.frames),1);
		delayedcall(0.02, if(rotateing,rotateright()) );
	</action>

	<action name="stoprotate">
		set(rotateing,false);
	</action>

</krpano>