<?xml version="1.0" encoding="UTF-8"?>
<rmml>
<!--
$RCSfile: rnmc_stdButton.xml,v $
$Revision: 900 $

last change: $Date: 2009-01-23 15:23:45 +0300 (Пт, 23 янв 2009) $
             $Author: Pavel $

	Lacerta Project
	version 1.0.0.1
	Copyright (C) 2008 RNMC
-->

<composition name="rnmc_stdButton" class="rnmc_stdMediaObject">
<button name="zone" depth="-1" enabled="true" useHandCursor="true"/>
<script event="zone.onRollOver">
	rolloverButton();
</script>
<script event="zone.onRollOut">
	rolloutButton()
</script>
<script event="zone.onPress">
	pressButton();
</script>
<script event="zone.onRelease">
	releaseButton();
</script>
<script event="zone.onReleaseOutside">
	releaseOutsideButton();
</script>
<sequencer name="pressSequencer" playing="false" loop="true">
	 <script>
		this.loopPressDelay; // ms
	</script>
	<script>
		continuePressing();
	</script>
</sequencer>
<script><![CDATA[
// общие
// тип кнопки: либо Image либо Text
	this.type = "rnmc_stdButton";
	this.id = null;
	this.visibility = OBJECT_VISIBILITY_UNDEFINED;

	this.objectState = OBJECT_STATE_HIDDEN;
	this.visited = false;

//	для каждого объекта необходимо определить
//	какие эффекты к нему применимы
	this.fadeEffectEnabled = true;
	this.moveEffectEnabled = true;
	this.scaleEffectEnabled = false;

	this.loopPressDelay = 20;
// общие для всех видов кнопок
	//	Тип кнопки. Возможные значения:
	//				BUTTON_TYPE_IMAGE - кнопка состоит из одной или нескольких картинок
	//				(допускает нарезку из одной или нескольких картинок),
	//				BUTTON_TYPE_TEXT - текстовая кнопка
	this.buttonType = BUTTON_TYPE_IMAGE;
	this.buttonStyle = BUTTON_STYLE_NORMAL;
	// может быть еще када кнопку нажимаем и  при отпускании она не "отжимается" BUTTON_STYLE_STICKY = 1; 
	this.buttonWidth = 0;
	this.buttonHeight = 0;

	this.loopPress = false;

	// text button only
	this.textButtonValue = null;
	this.buttonNormalTextStyle = null;
	this.buttonActiveTextStyle = null;
	this.buttonPressedTextStyle = null;
	this.buttonDisabledTextStyle = null;

	// image button only
	this.buttonNormalImageSrc = null;
	this.buttonActiveImageSrc = null;
	this.buttonPressedImageSrc = null;
	this.buttonDisabledImageSrc = null;

	// image crop button only
	this.buttonNormalCropArea = null;
	this.buttonActiveCropArea = null;
	this.buttonPressedCropArea = null;
	this.buttonDisabledCropArea = null;

	// 
	this.enabled = true;
	this.buttonPressed = false;
	this.normalState = null;
	this.activeState = null;
	this.pressedState = null;
	this.disabledState = null;

	this.activeMarkDefined = false;
	this.activeMarkType = BUTTON_ACTIVEMARK_BORDER;
	this.activeMarkSrc = null;
	this.activeBorderColor = null;
	this.activeBorderSize = 0;
	this.activeBgColor = null;
	this.activeMarkXOffset = 0;
	this.activeMarkYOffset = 0;
	this.activeMarkWidth = 0;
	this.activeMarkHeight = 0;
	this.activeMarkDepth = 2;

	this.visitedMarkSrc = null;
	this.visitedMarkX = 0;
	this.visitedMarkY = 0;
	this.visitedMarkWidth = 0;
	this.visitedMarkHeight = 0;
	this.visitedMarkDepth = 0;

	//
	this.onPressActions = null;
	this.onUnpressActions = null;
	this.onShowActions = null;

	//
	this.pressCallBackObject = null;
	this.pressCallBackFunction = null;
	this.releaseCallBackObject = null;
	this.releaseCallBackFunction = null;
	this.rollOverCallBackObject = null;
	this.rollOverCallBackFunction = null;
	this.rollOutCallBackObject = null;
	this.rollOutCallBackFunction = null;

	this.defaultSettings = (scene.defaultSettings && scene.defaultSettings.stdButton) ? true : false;
	
	// инициализация из узла
	function initFromNode(srcNode){
		var xmlNode = null;
		var xmlAttributeMap = null;
		var xmlAttribute = null;

	//	считывание настроек по умолчанию
		if(this.defaultSettings){
			this.buttonType = scene.defaultSettings.stdButton.buttonType;
			this.buttonNormalTextStyle = scene.defaultSettings.stdButton.buttonNormalTextStyle;
			this.buttonActiveTextStyle = scene.defaultSettings.stdButton.buttonActiveTextStyle;
			this.buttonPressedTextStyle = scene.defaultSettings.stdButton.buttonPressedTextStyle;
			this.buttonDisabledTextStyle = scene.defaultSettings.stdButton.buttonDisabledTextStyle;
			this.defaultSettings = false;
		}

		xmlAttributeMap = srcNode.attributes;
		if (xmlAttributeMap){
			xmlAttribute = xmlAttributeMap.getNamedItem("visible");
			if (xmlAttribute != null && xmlAttribute.specified){
				if((xmlAttribute.value).toLowerCase() == "true")
					this.visibility = OBJECT_VISIBILITY_TRUE;
				else if((xmlAttribute.value).toLowerCase() == "false")
					this.visibility = OBJECT_VISIBILITY_FALSE;
			}
			xmlAttribute =  xmlAttributeMap.getNamedItem("id");
			if (xmlAttribute != null && xmlAttribute.specified)
				this.id = xmlAttribute.value;
			xmlAttribute =  xmlAttributeMap.getNamedItem("pressed");
			if (xmlAttribute != null && xmlAttribute.specified
				&& (xmlAttribute.value).toLowerCase() == "true")
				this.buttonPressed = true;
		}

		xmlNode = srcNode.firstChild;
		while(xmlNode){
			if(xmlNode.nodeName == "param"){
        this.parseParamNode(xmlNode);
				xmlAttributeMap = xmlNode.attributes;
				if (xmlAttributeMap){

					var srcBase = null;
					if (srcNode.ownerDocument.source){
						var tmp = new String(srcNode.ownerDocument.source).replace("/\/.g", "\\").split("\\")
						tmp.pop();
						srcBase = tmp.join("\\");
					}

					xmlAttribute =  xmlAttributeMap.getNamedItem("type");
					if (xmlAttribute != null && xmlAttribute.specified){
						if((xmlAttribute.value).toLowerCase() == "text")
							this.buttonType = BUTTON_TYPE_TEXT;
						if((xmlAttribute.value).toLowerCase() == "image")
							this.buttonType = BUTTON_TYPE_IMAGE;
						if((xmlAttribute.value).toLowerCase() == "cropimage")
							this.buttonType = BUTTON_TYPE_CROPPED_IMAGE;
					}

					xmlAttribute =  xmlAttributeMap.getNamedItem("saveState");
					if (xmlAttribute != null && xmlAttribute.specified){
						if((xmlAttribute.value).toLowerCase() == "true")
							this.saveState = true;
						else if((xmlAttribute.value).toLowerCase() == "false")
							this.saveState = false;
					}

					xmlAttribute =  xmlAttributeMap.getNamedItem("sticky");
					if (xmlAttribute != null && xmlAttribute.specified
						&& (xmlAttribute.value).toLowerCase() == "true")
						this.buttonSticky = true;
					xmlAttribute =  xmlAttributeMap.getNamedItem("loopPress");
					if (xmlAttribute != null && xmlAttribute.specified
						&& (xmlAttribute.value).toLowerCase() == "true")
						this.loopPress = true;
					xmlAttribute =  xmlAttributeMap.getNamedItem("x");
					if (xmlAttribute != null && xmlAttribute.specified)
						this.x = parseInt(xmlAttribute.value);
					xmlAttribute =  xmlAttributeMap.getNamedItem("y");
					if (xmlAttribute != null && xmlAttribute.specified)
						this.y = parseInt(xmlAttribute.value);
					xmlAttribute =  xmlAttributeMap.getNamedItem("width");
					if (xmlAttribute != null && xmlAttribute.specified)
						this.buttonWidth = parseInt(xmlAttribute.value);
					xmlAttribute =  xmlAttributeMap.getNamedItem("height");
					if (xmlAttribute != null && xmlAttribute.specified)
						this.buttonHeight = parseInt(xmlAttribute.value);
					xmlAttribute =  xmlAttributeMap.getNamedItem("depth");
					if (xmlAttribute != null && xmlAttribute.specified)
						this.objectDepth = parseInt(xmlAttribute.value);

					switch(this.buttonType){
					case BUTTON_TYPE_TEXT:
						// text button
						xmlAttribute =  xmlAttributeMap.getNamedItem("textValue");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.textButtonValue = xmlAttribute.value;
						xmlAttribute =  xmlAttributeMap.getNamedItem("styleNormal");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.buttonNormalTextStyle = xmlAttribute.value;
						xmlAttribute =  xmlAttributeMap.getNamedItem("styleActive");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.buttonActiveTextStyle = xmlAttribute.value;
						xmlAttribute =  xmlAttributeMap.getNamedItem("stylePressed");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.buttonPressedTextStyle = xmlAttribute.value;
						xmlAttribute =  xmlAttributeMap.getNamedItem("styleDisabled");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.buttonDisabledTextStyle = xmlAttribute.value;
						break;
					case BUTTON_TYPE_IMAGE:
						// crop image button
						xmlAttribute =  xmlAttributeMap.getNamedItem("areaNormal");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.buttonNormalCropArea = xmlAttribute.value;
						xmlAttribute =  xmlAttributeMap.getNamedItem("areaActive");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.buttonActiveCropArea = xmlAttribute.value;
						xmlAttribute =  xmlAttributeMap.getNamedItem("areaPressed");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.buttonPressedCropArea = xmlAttribute.value;
						xmlAttribute =  xmlAttributeMap.getNamedItem("areaDisabled");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.buttonDisabledCropArea = xmlAttribute.value;

						// image button && crop image 
						xmlAttribute =  xmlAttributeMap.getNamedItem("srcNormal");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.buttonNormalImageSrc =
								scene.Utils.makePathSrc(srcBase, xmlAttribute.value);
						xmlAttribute =  xmlAttributeMap.getNamedItem("srcActive");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.buttonActiveImageSrc =
								scene.Utils.makePathSrc(srcBase, xmlAttribute.value);
						xmlAttribute =  xmlAttributeMap.getNamedItem("srcPressed");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.buttonPressedImageSrc =
								scene.Utils.makePathSrc(srcBase, xmlAttribute.value);
						xmlAttribute =  xmlAttributeMap.getNamedItem("srcDisabled");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.buttonDisabledImageSrc =
								scene.Utils.makePathSrc(srcBase, xmlAttribute.value);
						break;
					}
				}
			} else if(xmlNode.nodeName == "actions"){
				this.onRollOverActions = scene.Utils.parseActionsNode(xmlNode, "onRollOver");
				this.onRollOutActions  = scene.Utils.parseActionsNode(xmlNode, "onRollOut");
				this.onPressActions    = scene.Utils.parseActionsNode(xmlNode, "onPress");
				this.onUnpressActions  = scene.Utils.parseActionsNode(xmlNode, "onUnpress");
				this.onReleaseActions  = scene.Utils.parseActionsNode(xmlNode, "onRelease");
				this.onShowActions     = scene.Utils.parseActionsNode(xmlNode, "onShow");
			} else if(xmlNode.nodeName == "effect"){
				this.parseEffectNode(xmlNode);
			} else if(xmlNode.nodeName == "effects"){
				this.parseEffectsNode(xmlNode);
			} else if(xmlNode.nodeName == "objectives"){
				this.parseObjectivesNode(xmlNode);
			} else if(xmlNode.nodeName == "activemark"){
				xmlAttributeMap = xmlNode.attributes;
				if(xmlAttributeMap){
					this.activeMarkDefined = true;
					xmlAttribute =  xmlAttributeMap.getNamedItem("type");
					if (xmlAttribute != null && xmlAttribute.specified){
						if((xmlAttribute.value).toLowerCase() == "border")
							this.activeMarkType = BUTTON_ACTIVEMARK_BORDER;
						if((xmlAttribute.value).toLowerCase() == "image")
							this.activeMarkType = BUTTON_ACTIVEMARK_IMAGE;
					}
					xmlAttribute =  xmlAttributeMap.getNamedItem("src");
					if (xmlAttribute != null && xmlAttribute.specified){
						this.activeMarkSrc = xmlAttribute.value;
					}
					// старые (до исправления синтаксиса)	-------------------
					xmlAttribute =  xmlAttributeMap.getNamedItem("bordercolor");
					if (xmlAttribute != null && xmlAttribute.specified){
						this.activeBorderColor = xmlAttribute.value;
					}
					xmlAttribute =  xmlAttributeMap.getNamedItem("bordersize");
					if (xmlAttribute != null && xmlAttribute.specified){
						this.activeBorderSize = parseInt(xmlAttribute.value);
					}
					xmlAttribute =  xmlAttributeMap.getNamedItem("bgcolor");
					if (xmlAttribute != null && xmlAttribute.specified){
						this.activeBgColor = xmlAttribute.value;
					}
					// новые (после исправления синтаксиса)
					xmlAttribute =  xmlAttributeMap.getNamedItem("borderColor");
					if (xmlAttribute != null && xmlAttribute.specified){
						this.activeBorderColor = xmlAttribute.value;
					}
					xmlAttribute =  xmlAttributeMap.getNamedItem("borderSize");
					if (xmlAttribute != null && xmlAttribute.specified){
						this.activeBorderSize = parseInt(xmlAttribute.value);
					}
					xmlAttribute =  xmlAttributeMap.getNamedItem("bgColor");
					if (xmlAttribute != null && xmlAttribute.specified){
						this.activeBgColor = xmlAttribute.value;
					}
				//	------------------------------------------------------
					xmlAttribute =  xmlAttributeMap.getNamedItem("x");
					if (xmlAttribute != null && xmlAttribute.specified){
						this.activeMarkXOffset = parseInt(xmlAttribute.value);
					}
					xmlAttribute =  xmlAttributeMap.getNamedItem("y");
					if (xmlAttribute != null && xmlAttribute.specified){
						this.activeMarkYOffset = parseInt(xmlAttribute.value);
					}
					xmlAttribute =  xmlAttributeMap.getNamedItem("width");
					if (xmlAttribute != null && xmlAttribute.specified){
						this.activeMarkWidth = parseInt(xmlAttribute.value);
					}
					xmlAttribute =  xmlAttributeMap.getNamedItem("height");
					if (xmlAttribute != null && xmlAttribute.specified){
						this.activeMarkHeight = parseInt(xmlAttribute.value);
					}
					xmlAttribute =  xmlAttributeMap.getNamedItem("depth");
					if (xmlAttribute != null && xmlAttribute.specified){
						this.activeMarkDepth = parseInt(xmlAttribute.value);
					}
				}
			} else if(xmlNode.nodeName == "visitedmark"){
				xmlAttributeMap = xmlNode.attributes;
				if (xmlAttributeMap){
					this.markVisited = true;
					xmlAttribute =  xmlAttributeMap.getNamedItem("src");
					if (xmlAttribute != null && xmlAttribute.specified)
						this.visitedMarkSrc
							 = scene.Utils.makePathSrc(srcBase, xmlAttribute.value);
					xmlAttribute =  xmlAttributeMap.getNamedItem("x");
					if (xmlAttribute != null && xmlAttribute.specified)
						this.visitedMarkX = parseInt(xmlAttribute.value);
					xmlAttribute =  xmlAttributeMap.getNamedItem("y");
					if (xmlAttribute != null && xmlAttribute.specified)
						this.visitedMarkY = parseInt(xmlAttribute.value);
					xmlAttribute =  xmlAttributeMap.getNamedItem("width");
					if (xmlAttribute != null && xmlAttribute.specified)
						this.visitedMarkWidth = parseInt(xmlAttribute.value);
					xmlAttribute =  xmlAttributeMap.getNamedItem("height");
					if (xmlAttribute != null && xmlAttribute.specified)
						this.visitedMarkHeight = parseInt(xmlAttribute.value);
					xmlAttribute =  xmlAttributeMap.getNamedItem("depth");
					if (xmlAttribute != null && xmlAttribute.specified)
						this.visitedMarkDepth = parseInt(xmlAttribute.value);
				}
			} else if(xmlNode.nodeName == "hint"){
				xmlAttributeMap = xmlNode.attributes;
				if (xmlAttributeMap){
					this.hintDefined = true;
					xmlAttribute =  xmlAttributeMap.getNamedItem("type");
					if (xmlAttribute != null && xmlAttribute.specified){
						switch((xmlAttribute.value).toLowerCase()){
						case "text":
							this.hintType = HINT_TYPE_TEXT;
							if(xmlNode.textContent){
								this.hintValue = xmlNode.textContent;
							}
							break;
						case "external_text":
							this.hintType = HINT_TYPE_EXTERNALTEXT;
							break;
						case "image":
							this.hintType = HINT_TYPE_IMAGE;
							break;
						case "audio":
							this.hintType = HINT_TYPE_AUDIO;
							break;
						case "video":
							this.hintType = HINT_TYPE_VIDEO;
							break;
						default:
							break;
						}
					}
					xmlAttribute =  xmlAttributeMap.getNamedItem("src");
					if (xmlAttribute != null && xmlAttribute.specified)
						this.hintValue = xmlAttribute.value;
					xmlAttribute =  xmlAttributeMap.getNamedItem("width");
					if (xmlAttribute != null && xmlAttribute.specified)
						this.hintWidth = parseInt(xmlAttribute.value);
					xmlAttribute =  xmlAttributeMap.getNamedItem("height");
					if (xmlAttribute != null && xmlAttribute.specified)
						this.hintHeight = parseInt(xmlAttribute.value);
					xmlAttribute =  xmlAttributeMap.getNamedItem("depth");
					if (xmlAttribute != null && xmlAttribute.specified)
						this.hintDepth = parseInt(xmlAttribute.value);
					xmlAttribute =  xmlAttributeMap.getNamedItem("bgcolor");
					if (xmlAttribute != null && xmlAttribute.specified)
						this.hintBgColor = xmlAttribute.value;
				}
			}
			xmlNode = xmlNode.nextSibling;
		}
		if(!this.buttonActiveImageSrc)
			this.buttonActiveImageSrc = this.buttonNormalImageSrc;
		if(!this.buttonPressedImageSrc)
			this.buttonPressedImageSrc = this.buttonActiveImageSrc;
		
		if(this.buttonNormalCropArea && !this.buttonActiveCropArea)
			this.buttonActiveCropArea = this.buttonNormalCropArea;
		if(this.buttonActiveCropArea && !this.buttonPressedCropArea)
			this.buttonPressedCropArea = this.buttonActiveCropArea;

		// это обсуждать надо!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

		this.createObject();

		return true;
	}

	function setPressCallBack(pointerToObject, callbackFunction){
		this.pressCallBackObject = pointerToObject;
		this.pressCallBackFunction = callbackFunction;
	}

	function clearPressCallBack(){
		this.pressCallBackObject = null;
		this.pressCallBackFunction = null;
	}
	
	function setReleaseCallBack(pointerToObject, callbackFunction){
		this.releaseCallBackObject = pointerToObject;
		this.releaseCallBackFunction = callbackFunction;
	}

	function clearReleaseCallBack(){
		this.releaseCallBackObject = null;
		this.releaseCallBackFunction = null;
	}

	function setRollOverCallBack(pointerToObject, callbackFunction){
		this.rollOverCallBackObject = pointerToObject;
		this.rollOverCallBackFunction = callbackFunction;
	}

	function clearRollOverCallBack(){
		this.rollOverCallBackObject = null;
		this.rollOverCallBackFunction = null;
	}
	
	function setRollOutCallBack(pointerToObject, callbackFunction){
		this.rollOutCallBackObject = pointerToObject;
		this.rollOutCallBackFunction = callbackFunction;
	}
	
	function clearRollOutCallBack(){
		this.rollOutCallBackObject = null;
		this.rollOutCallBackFunction = null;
	}


	/*
	function setActionDispatchObject(pointerToObject){
		this.actionDispatchObject = pointerToObject;
	}
	*/

	function createObject(){
//trace("createButton()");
		switch(this.buttonType){
		case BUTTON_TYPE_TEXT:
			this.normalState = new Text();
			// проверку на наличие такого стиля
			this.normalState.visible = false;
			this.normalState.adjustHeight = false;
			this.normalState.parent = this;
			if(scene.StyleManager.styleExists(this.buttonNormalTextStyle)){
				this.normalState.style = this.buttonNormalTextStyle;
			} else {
trace("ВНИМАНИЕ: стиль " + this.buttonNormalTextStyle + " не найден.");
			}
			this.normalState.value = this.textButtonValue;
			if(this.buttonWidth > 0){
				this.normalState.width = this.buttonWidth;
			} else {
				this.normalState.width = this.normalState.getMediaSize().width;
			}
			this.normalState.height = this.buttonHeight;
			
			this.activeState = new Text();
			this.activeState.visible = false;
			this.activeState.adjustHeight = false;
			this.activeState.parent = this;
			if(scene.StyleManager.styleExists(this.buttonActiveTextStyle)){
				this.activeState.style = this.buttonActiveTextStyle;
			} else {
trace("ВНИМАНИЕ: стиль " + this.buttonActiveTextStyle + " не найден.");
			}

			this.activeState.value = this.textButtonValue;
			if(this.buttonWidth > 0)
				this.activeState.width = this.buttonWidth;
			this.activeState.height = this.buttonHeight;

			this.pressedState = new Text();
			this.pressedState.adjustHeight = false;
			this.pressedState.visible = false;
			this.pressedState.parent = this;
			if(scene.StyleManager.styleExists(this.buttonPressedTextStyle)){
				this.pressedState.style = this.buttonPressedTextStyle;
			} else {
trace("ВНИМАНИЕ: стиль " + this.buttonPressedTextStyle + " не найден.");
			}
			
			this.pressedState.value = this.textButtonValue;
			if(this.buttonWidth > 0)
				this.pressedState.width = this.buttonWidth;
			this.pressedState.height = this.buttonHeight;
			// disabled state initialization
			/*
			this.disabledState = new Text();
			this.disabledState.style = this.buttonDisabledTextStyle;
			this.disabledState.adjustHeight = false;
			this.disabledState.parent = this;
			this.disabledState.visible = false;
			this.disabledState.value = this.textButtonValue;
			if(this.buttonWidth > 0)
				this.disabledState.width = this.buttonWidth;
			this.disabledState.height = this.buttonHeight;
			*/
			break;
		case BUTTON_TYPE_IMAGE:
			this.normalState = new Image();
			this.normalState.parent = this;
			this.normalState.visible = false;
			this.normalState.src = this.buttonNormalImageSrc;
			if(this.buttonNormalCropArea){
				var rectParams = scene.Utils.parseRectToArray(this.buttonNormalCropArea);
				if(rectParams){
					trace(rectParams[1]);
					this.normalState.crop(rectParams[0], rectParams[1], rectParams[2], rectParams[3]);
				}
			}
			this.activeState = new Image();
			this.activeState.parent = this;
			this.activeState.visible = false;
			this.activeState.src = this.buttonActiveImageSrc;
			if(this.buttonActiveCropArea){
				var rectParams = scene.Utils.parseRectToArray(this.buttonActiveCropArea);
				if(rectParams)
					this.activeState.crop(rectParams[0], rectParams[1], rectParams[2], rectParams[3]);
			}
			this.pressedState = new Image();
			this.pressedState.parent = this;
			this.pressedState.visible = false;
			this.pressedState.src = this.buttonPressedImageSrc;
			if(this.buttonPressedCropArea){
				var rectParams = scene.Utils.parseRectToArray(this.buttonPressedCropArea);
				if(rectParams)
					this.pressedState.crop(rectParams[0], rectParams[1], rectParams[2], rectParams[3]);
			}
			/*
			if(this.buttonDisabledImageSrc){
				this.disabledState = new Image();
				this.disabledState.parent = this;
				this.disabledState.visible = false;
				this.disabledState.src = this.buttonDisabledImageSrc;
			}
			if(this.buttonDisabledCropArea){
				var rectParams = scene.Utils.parseRectToArray(this.buttonDisabledCropArea);
				if(rectParams)
					this.disabledState.crop(rectParams[0], rectParams[1], rectParams[2], rectParams[3]);
			}
			*/
			break;
		}
		if(this.activeMarkDefined){
			if(activeMarkType == BUTTON_ACTIVEMARK_BORDER){
				this.activeMarkBorder = new Text();
				this.activeMarkBorder.visible = false;
				this.activeMarkBorder.adjustHeight = false;
				this.activeMarkBorder.x = this.activeMarkXOffset - this.activeBorderSize;
				this.activeMarkBorder.y = this.activeMarkYOffset - this.activeBorderSize;
				this.activeMarkBorder.width = this.activeMarkWidth;
				this.activeMarkBorder.height = this.activeMarkHeight;
				this.activeMarkBorder.depth = this.activeMarkDepth + 1;
				if (this.activeBorderColor)
					this.activeMarkBorder.bkgColor = this.activeBorderColor;
				this.activeMarkBorder.enabled = false;
				this.activeMarkBorder.parent = this;

				this.activeMarkBackground = new Text();
				this.activeMarkBackground.visible = false;
				this.activeMarkBackground.adjustHeight = false;
				this.activeMarkBackground.x = this.activeMarkXOffset;// + this.activeBorderSize;
				this.activeMarkBackground.y = this.activeMarkYOffset;// + this.activeBorderSize;
				this.activeMarkBackground.width = this.activeMarkWidth - 2*this.activeBorderSize;
				this.activeMarkBackground.height = this.activeMarkHeight - 2*this.activeBorderSize;
				this.activeMarkBackground.depth = this.activeMarkDepth;
				if (this.activeBgColor)
					this.activeMarkBackground.bkgColor = this.activeBgColor;
				this.activeMarkBackground.enabled = false;
				this.activeMarkBackground.parent = this;
			} else if(activeMarkType == BUTTON_ACTIVEMARK_IMAGE){
				this.activeMarkBorder = new Image();
				this.activeMarkBorder.visible = false;
				this.activeMarkBorder.src = this.activeMarkSrc;
				this.activeMarkBorder.x = this.activeMarkXOffset;
				this.activeMarkBorder.y = this.activeMarkYOffset;
				this.activeMarkBorder.depth = this.activeMarkDepth;
				this.activeMarkBorder.enabled = false;
				this.activeMarkBorder.parent = this;
				this.activeMarkBackground = this.activeMarkBorder;
			}
		}
	}

	function showObject(objectId){
    this.depth = this.objectDepth;

		if(this.saveState){
			this.restoreMyState();
		}
		if(this.enabled){
			if(!this.buttonPressed){
				this.setButtonState(BUTTON_STATE_NORMAL);
			} else {
				this.setButtonState(BUTTON_STATE_PRESSED);
			}
			zone.useHandCursor = true;
		} else {
			this.setButtonState(BUTTON_STATE_DISABLED);
		}
		//	запуск присоединённых эффектов для показа
		this.effectsTarget = this;
		var showEffectsCount = this.startEffects(EVENT_ON_SHOW);
		if(showEffectsCount == 0){
			this.visible = true;
		}
		if(this.showCallBackFunction != null && this.showCallBackObject != null)
			this.showCallBackFunction.call(this.showCallBackObject, this.id);
		if(this.visited){
			if(this.markVisited && !this.visitedMark){
				this.visitedMark = new Image();
				this.visitedMark.src = this.visitedMarkSrc;
				this.visitedMark.parent = this;
				this.visitedMark.depth = -3;
				this.visitedMark.x = this.visitedMarkX;
				this.visitedMark.y = this.visitedMarkY;
				if(this.visitedMarkWidth > 0)
					this.visitedMark.width = this.visitedMarkWidth;
				if(this.visitedMarkHeight > 0)
					this.visitedMark.height = this.visitedMarkHeight;
				this.visitedMark.depth = this.visitedMarkDepth;
				this.visitedMark.visible = true;
			}
		}
	//	OBJECTIVES for onShow
		if(this.onShowObjectives && this.objectivesList){
			for(var i = 0; i < this.objectivesList.length; i++){
				if(this.objectivesList[i] == "onShow"){
					this.objectivesList[i].complete = true;
          this.checkObjectives();
				}
			}
		}
	//	END OBJECTIVES for onShow
  
    if(this.onShowActions){
				for(var i = 0; i < this.onShowActions.length; i++){
					parent.dispatchAction(this.onShowActions[i]);
				}
			}
	}

	function hideObject(){
		zone.hitArea = null;
		zone.useHandCursor = false;
		this.normalState.visible = false;
		this.activeState.visible = false;
		this.pressedState.visible = false;
		if(this.disabledState)
			this.disabledState.visible = false;
		this.visible = false;
	//	OBJECTIVES for onHide
		if(this.onHideObjectives && this.objectivesList){
			for(var i = 0; i < this.objectivesList.length; i++){
				if(this.objectivesList[i] == "onHide"){
					this.objectivesList[i].complete = true;
          this.checkObjectives();
				}
			}
		}
	//	END OBJECTIVES for onHide
	}

	function rolloverButton(){
//trace("rolloverButton");
		if(this.hintDefined && scene.Hint){
			scene.Hint.startHint(this.hintType, this.hintValue,
				this.hintScale, this.hintBgColor, this.hintBorderColor);
		}
		if(this.enabled){
			if(!this.buttonPressed){
				this.normalState.visible = false;
				this.activeState.visible = true;
				this.pressedState.visible = false;
				zone.hitArea = "[0,0," + this.activeState.width + "," + this.activeState.height + "]";
			};
			if(this.rollOverCallBackFunction != null && this.rollOverCallBackObject != null)
				this.rollOverCallBackFunction.call(this.rollOverCallBackObject, this.id);
			if(this.onRollOverActions){
				for(var i = 0; i < this.onRollOverActions.length; i++){
					parent.dispatchAction(this.onRollOverActions[i]);
				}
			}
		};
		if(this.activeMarkDefined){
			if(activeMarkType == BUTTON_ACTIVEMARK_BORDER){
				if (this.activeMarkHeight == 0 || this.activeMarkHeight == null){
					var markHeight = 0;
					if (this.activeState.visible)
						markHeight = this.activeState.height;
					else if (this.normalState.visible)
						markHeight = this.normalState.height;
					else if (this.pressedState.visible)
						markHeight = this.pressedState.height;

					markHeight = markHeight + 2*this.activeBorderSize - 2*this.activeMarkYOffset;
					
					this.activeMarkBorder.height = markHeight;
				}
				else
					this.activeMarkBorder.height = this.activeMarkHeight;
				this.activeMarkBackground.height = this.activeMarkBorder.height - 2*this.activeBorderSize;

				if (this.activeMarkWidth == 0 || this.activeMarkWidth == null){
					var markWidth = 0;
					if (this.activeState.visible)
						markWidth = this.activeState.width;
					else if (this.normalState.visible)
						markWidth = this.normalState.width;
					else if (this.pressedState.visible)
						markWidth = this.pressedState.width;

					markWidth = markWidth + 2*this.activeBorderSize - 2*this.activeMarkXOffset;

					this.activeMarkBorder.width = markWidth;
				}
				else
					this.activeMarkBorder.width = this.activeMarkWidth;

				this.activeMarkBackground.width =
					this.activeMarkBorder.width - 2*this.activeBorderSize;
			}
			this.activeMarkBackground.visible = true;
			this.activeMarkBorder.visible = true;
		}
	}
	
	function rolloutButton(){
//trace("rolloutButton");
		if(this.activeMarkDefined){
			this.activeMarkBorder.visible = false;
			this.activeMarkBackground.visible = false;
		}
		if (scene.Hint)
			scene.Hint.stopHint();
		if(this.enabled){
			if(!this.buttonPressed){
				this.activeState.visible = false;
				this.pressedState.visible = false;
				this.normalState.visible = true;
				zone.hitArea = "[0,0," + this.normalState.width + "," + this.normalState.height + "]";
			};
			if(this.rollOutCallBackFunction != null && this.rollOutCallBackObject != null)
				this.rollOutCallBackFunction.call(this.rollOutCallBackObject, this.id);
			if(this.onRollOutActions){
				for(var i = 0; i < this.onRollOutActions.length; i++){
					parent.dispatchAction(this.onRollOutActions[i]);
				}
			}
		};
	}

	function pressButton(){
		if (scene.Hint)
			scene.Hint.stopHint();
		if(this.enabled){
			var prevButtonPressed = this.buttonPressed;
			this.visited = true;
	//	=================== СОХРАНЕНИЕ СОСТОЯНИЯ	=============================
			if(this.saveState)
				this.saveMyState();
			if(!this.buttonPressed){
				this.pressedState.visible = true;
				this.normalState.visible = false;
				this.activeState.visible = false;
				zone.hitArea = "[0,0," + this.pressedState.width + "," + this.pressedState.height + "]";
			}
			if(this.markVisited && !this.visitedMark){
				this.visitedMark = new Image();
				this.visitedMark.src = this.visitedMarkSrc;
				this.visitedMark.parent = this;
				this.visitedMark.depth = -3;
				this.visitedMark.x = this.visitedMarkX;
				this.visitedMark.y = this.visitedMarkY;
				this.visitedMark.visible = true;
			}
			if(this.buttonSticky)
				this.buttonPressed = true;
		//	OBJECTIVES for onPress
			//if(this.onPressObjectives && this.objectivesList){
			if(this.objectivesList){
/*
for(var i = 0; i < this.objectivesList.length; i++){
  trace(this.objectivesList[i].complete)
}
*/
				for(var i = 0; i < this.objectivesList.length; i++){
					if(this.objectivesList[i] == "onPress"){
//trace("#0000FFPRESS");
						this.objectivesList[i].complete = true;
            this.checkObjectives();
					}
				}
/*
for(var i = 0; i < this.objectivesList.length; i++){
	trace(this.objectivesList[i].complete)
}
*/
			}
		//	END OBJECTIVES for onPress
			if(this.loopPress){
				//trace("LOOP BUTTON");
				pressSequencer.playing = true;
			}
			if(pressCallBackFunction != null && pressCallBackObject != null){
				pressCallBackFunction.call(pressCallBackObject, this.id);
			}
			if(this.onPressActions){
				if (prevButtonPressed){
					for(var i = 0; i < this.onPressActions.length; i++)
						if (this.onPressActions[i].eventParam != "unpressed"){
              //trace("BUTTON: unpressed");
							parent.dispatchAction(this.onPressActions[i]);
						}
				}
				else{
					for(var i = 0; i < this.onPressActions.length; i++)
						if (this.onPressActions[i].eventParam != "pressed"){
              //trace("BUTTON: pressed parent = " + parent + "; parent.id = " + parent.id + "; " + this.onPressActions[i]);
							parent.dispatchAction(this.onPressActions[i]);
						}
				}
			}
		}
	}

	function continuePressing(){
		if(pressCallBackFunction != null && pressCallBackObject != null)
				pressCallBackFunction.call(pressCallBackObject, this.id);
	}

	function unpressButton(){
		if (scene.Hint)
			scene.Hint.stopHint();
		if(this.enabled){
			var prevButtonPressed = this.buttonPressed;
			if(this.buttonPressed){
				this.buttonPressed = false;
				this.pressedState.visible = false;
				this.normalState.visible = false;
				this.activeState.visible = true;
				zone.hitArea = "[0,0," + this.activeState.width + "," + this.activeState.height + "]";
			}
			if(this.onUnpressActions){
				if (prevButtonPressed){
					for(var i = 0; i < this.onUnpressActions.length; i++)
						if (this.onUnpressActions[i].eventParam != "unpressed"){
							parent.dispatchAction(this.onUnpressActions[i]);
						}
				}
				else{
					for(var i = 0; i < this.onUnpressActions.length; i++)
						if (this.onUnpressActions[i].eventParam != "pressed"){
							parent.dispatchAction(this.onUnpressActions[i]);
						}
				}
			}
		}
	};
	
	function releaseButton(releaseAnyway){
		if(this.loopPress){
			pressSequencer.playing = false;
		}			
		if(this.enabled){
			if(!this.buttonPressed || releaseAnyway){
				this.activeState.visible = true;
				this.pressedState.visible = false;
				this.normalState.visible = false;
				zone.hitArea = "[0,0," + this.activeState.width + "," + this.activeState.height + "]";
			}
			if(releaseCallBackFunction != null && releaseCallBackObject != null)
				releaseCallBackFunction.call(releaseCallBackObject, this.id);
			if(this.onReleaseActions){
				for(var i = 0; i < this.onReleaseActions.length; i++){
					parent.dispatchAction(this.onReleaseActions[i]);
				}
			}
		}
	}

	function releaseOutsideButton(){
		if(this.loopPress){
			pressSequencer.playing = false;
		}
		if(this.enabled){
			
		}
	}

	//	=================================== CONDITIONS =====================================
	function getObjectProperty(objectId, propertyName){
		if(objectId != this.id)
			return null;
		switch(propertyName){
		case "visited":
			return this.visited;
			break;
		case "pressed":
			return this.buttonPressed;
		default:
			return null;
		}	
	}

	//	======================================================================================
	function setButtonState(newState){
		switch(newState){
		case BUTTON_STATE_NORMAL:
			this.activeState.visible = false;
			this.pressedState.visible = false;
			//this.disabledState.visible = false;
			this.normalState.visible = true;
			zone.hitArea = "[0,0," + this.normalState.width + "," + this.normalState.height + "]";
			this.buttonPressed = false;
			break;
		case BUTTON_STATE_ACTIVE:
			this.normalState.visible = false;
			this.pressedState.visible = false;
			//this.disabledState.visible = false;
			this.activeState.visible = true;
			zone.hitArea = "[0,0," + this.activeState.width + "," + this.activeState.height + "]";
			this.buttonPressed = false;
			break;
		case BUTTON_STATE_PRESSED:
			this.normalState.visible = false;
			this.pressedState.visible = false;
			//this.disabledState.visible = false;
			this.pressedState.visible = true;
			zone.hitArea = "[0,0," + this.pressedState.width + "," + this.pressedState.height + "]";
			break;
		case BUTTON_STATE_DISABLED:
			this.normalState.visible = false;
			this.pressedState.visible = false;
			this.activeState.visible = false;

			//this.disabledState.visible = true;
			//zone.hitArea = "[0,0," + this.disabledState.width + "," + this.disabledState.height + "]";
			this.buttonPressed = false;
			break;
		}
	}
  
  function enableObject(){
    this.enableButton();
  }
 	
	function enableButton(){
		this.enabled = true;
    zone.useHandCursor = true;
		// перерисовка
	}
  
  function disableObject(){
    this.disableButton();
  }
  
	function disableButton(){
		this.enabled = false;
    zone.useHandCursor = false;
		// перерисовка
	}

// Установка функции обратного вызова на события
//	показ объекта
	function setShowCallBack(pointerToObject, callbackFunction){
		this.showCallBackObject = pointerToObject;
		this.showCallBackFunction = callbackFunction;
	}

//	Установка функции обратного вызова на события
//	убирания объекта (будет вызвана тогда когда все эффекты завершатся)
	function setHideCallBack(pointerToObject, callbackFunction){
		this.hideCallBackObject = pointerToObject;
		this.hideCallBackFunction = callbackFunction;
	}

	function getFullPath(){
		if("getFullPath" in parent){
			return parent.getFullPath();
		} else {
			return null;
		}
	}

	function saveMyState(){
		var myPath = this.getFullPath();
		if(myPath && this.id){
			myPath = myPath + "." + this.id;
			var propertiesArray = new Array();
		//	===========  BUTTON SPECIEFIC	============================
			propertiesArray.visited = this.visited;
		//	===========  END BUTTON SPECIEFIC	========================
			scene.Labwork.setStateParamsForObject(myPath, propertiesArray);
		}
	}

	function restoreMyState(){
		var myPath = this.getFullPath();
		if(myPath && this.id){
			myPath = myPath + "." + this.id;
			var propertiesArray = scene.Labwork.getStateParamsForObject(myPath);
			if(propertiesArray){
			//	===========  BUTTON SPECIEFIC	============================
				this.visited = propertiesArray.visited;
			//	===========  END BUTTON SPECIEFIC	========================			
			}
		}
	}

	//	OBJECTIVES	=======================================================================
	function addObjectiveDispatcher(objectiveEvent){
		switch(objectiveEvent){
		case "onShow":
			this.onShowObjectives = true;
			break;
		case "onHide":
			this.onHideObjectives = true;
			break;
		case "onPress":
			this.onPressObjectives = true;
			break;
		case "onRelease":
			this.onReleaseObjectives = true;
			break;
		default:
			rnmc_stdMediaObject_addObjectiveDispatcher(objectiveEvent);
			break;      
    }
	}
	//	END OBJECTIVES	=======================================================================
]]></script>
</composition>
</rmml>