<?xml version="1.0" encoding="UTF-8"?>
<rmml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="L:\collaborative-nir\program\Cscl3DWS\rmml\RMML.xsd">
	<composition _name="CKMButton" userEvents="onClick, onPressedChanged">
		<image _name="img" src="a">
			<script event="onRollOver">
				this.parent.handleOnRollOver();
			</script>
			<script event="onRollOut">
				this.parent.handleOnRollOut();
			</script>
			<script event="onPress">
				this.parent.handleOnPress();
			</script>
			<script event="onRelease">
				this.parent.handleOnRelease();
			</script>
			<script event="onReleaseOutside">
				this.parent.handleOnReleaseOutside();
			</script>
		</image>
		<script><![CDATA[
			// 0/1. Normal/Pressed		1/2
			// 0/2. Normal/HL			3/4
			// 0/4. Enabled/Disabled	5/6
			function checkBit(bit)
			{
				if( (this.state&bit)==bit)
				{
					return true;
				}
				return false;
			}

			function isPressed()
			{
				return checkBit(1);
			}
			function isHighlighted()
			{
				return checkBit(2);
			}
			function isEnabled()
			{
				return !checkBit(4);
			}

			function setImagesCount(count)
			{
				this.imCount = count;
				updateButtonImage();
			}

			function setBit(val, bit)
			{
				if( val)
					state = state | bit;
				else
					state &= ~bit;
			}

			function setEnabled(val)
			{
				setBit(!val, 4);
				this.img.enabled=val;
				if( !val)
				{
					setHighlighted(false);
				}
				updateButtonImage();
			}
			function setHighlighted(val)
			{
				setBit(val, 2);
				updateButtonImage();
			}
			function setPressed(val)
			{
				if( isPressed() == val)	return;
				setBit(val, 1);
				updateButtonImage();
				OnPressedChanged();
			}

			function updateButtonImage()
			{
				var mustGrow=false;
				var	activeImage=0;
				if( !isEnabled())
				{
					if( !isPressed())
					{
						activeImage = 5;
					}
					else
					{
						activeImage = 6;
					}
				}
				else
				{
					if( isPressed())
					{
						if( !isHighlighted()) 	activeImage = 3;
						else	 				activeImage = 4;
					}
					else
					{
						if( !isHighlighted())
						{
							activeImage = 1;
							if( this.growOnActivate && this.isGrowed)
							{
								this.isGrowed = false;
//								this.img.x += this.growSize;
//								this.img.y += this.growSize;
//								this.img.width -= 2*this.growSize;
//								this.img.height -= 2*this.growSize;
							}
						}
						else
						{
							activeImage = 2;
							if( this.growOnActivate && !this.isGrowed)
							{
								mustGrow=true;
								this.isGrowed = true;
//								this.img.x -= this.growSize;
//								this.img.y -= this.growSize;
							}
						}
					}
				}

				if( activeImage <= this.imCount)
				{
					img.crop((activeImage-1)*img.getMediaSize().width/imCount, 0, img.getMediaSize().width/imCount, img.getMediaSize().height);
					if( mustGrow)
					{
//						this.img.width += 2*this.growSize;
//						this.img.height += 2*this.growSize;
					}
				}
			}

			function handleOnPress()
			{
				//trace("PRESS");
				if( !this.checkButton)
				{
					this.seqPress.rewindAndPlay();
trace("this.fireEvent");
					this.fireEvent("onClick");
					if( typeof(this.Click) == "function")	this.Click();
				}
			}

			function handleOnReleaseOutside()
			{
				//trace("RELEASE OUTSIDE");
			}

			function handleOnRelease()
			{
				//trace("RELEASE");
				if( this.checkButton)
				{
					setPressed(!isPressed());
				}
			}

			function OnPressedChanged()
			{
				//trace("PRESS CHANGED");
				this.fireEvent("onPressedChanged");
				if( typeof(this.PressedChanged) == "function")	this.PressedChanged();
			}

			function handleOnRollOver()
			{
				//trace("OVER");
				this.setHighlighted(true);
				this.seqHelp.rewindAndPlay();
			}

			function handleOnRollOut()
			{
				//trace("OUT");
				this.setHighlighted(false);
				this.seqHelp.stop();
				if( typeof(this.parent.onHideHelp) == "function")
				{
					this.parent.onHideHelp();
				}
			}

			// Radio beh.
			this.radioGroup = "";
			this.radioDisabledWhenPressed = true;

			this.growOnActivate = false;
			this.growSize = 2;
			this.isGrowed=false;

			this.sHelp = "";
			this.state = 0;
			this.checkButton = true;
			setPressed( false);	setHighlighted( false);	setEnabled( true);

			this.imCount = 4;
			updateButtonImage();
		]]></script>

		<sequencer name="seqPress">
			<script>this.setPressed( true); 500;</script>
			<script>this.setPressed( false);</script>
		</sequencer>

		<sequencer name="seqHelp">
			<script>
				1000;
			</script>
			<script>
				if( typeof(this.parent.onShowHelp) == "function")
				{
					this.parent.onShowHelp( this.x + this.xMouse, this.y + this.yMouse, this.sHelp);
				}
			</script>
		</sequencer>
	</composition>
</rmml>