<?xml version="1.0" encoding="UTF-8"?>
<rmml>
<!--
$RCSfile:  rnmc_scrollMenu.xml$
$Revision: 957 $

last change: $Date: 2009-02-17 14:00:06 +0300 (Вт, 17 фев 2009) $
             $Author: toha $

	Lacerta Project
	version 1.0.0.1
	Copyright (C) 2007-2009 RNMC
-->

<composition name="rnmc_ScrollMenu">
<xml name="settingsXML"/>
<script><![CDATA[
	this.targetObject = null;
	
	this.menuAttachPoint = ROLLOVERMENU_POINT_RIGHTBOTTOM;
	this.menuOffsetX = 0;
	this.menuOffsetY = 0;
	
	this.btnScrollLeft = null;
	this.btnScrollUp = null;
	this.btnScrollDown  = null;
	this.btnScrollRight = null;
	
	this.scrollSpeed = 12;
	
	this.callBackObject = null;
	this.callBackFunction = null;
	
	function initObject(){
		var xmlNode = null;
		var xmlAttributeMap = null;
		var xmlAttribute = null;
		var settingsSrc = def_scroll_menu_xml;
		
		if(!resourceExists(settingsSrc)){
trace("ОШИБКА: Файл настроек rollovermenu не найден.");
			return false;
		}
		settingsXML.src = settingsSrc;
		if (!settingsXML.XMLDocument){
			// Если загружаемый файл не правильный - пишем в трэйсер и выходим
trace("Файл " + settingsSrc + " не является правильным XML файлом.");
			return false;
		} else {
			settingsXML.XMLDocument.source = settingsXML.src;
			xmlNode = settingsXML.XMLDocument.firstChild.firstChild;
			while(xmlNode){	
				if(xmlNode.nodeName == "param"){
					xmlAttributeMap = xmlNode.attributes;
					if(xmlAttributeMap){
						xmlAttribute =  xmlAttributeMap.getNamedItem("point");
						if (xmlAttribute != null && xmlAttribute.specified){
							switch(xmlAttribute.value){
							case "TOP_LEFT":
								this.menuAttachPoint = ROLLOVERMENU_POINT_LEFTTOP;
								break;
							case "BOTTOM_LEFT":
								this.menuAttachPoint = ROLLOVERMENU_POINT_LEFTBOTTOM;
								break;
							case "TOP_RIGHT":
								this.menuAttachPoint = ROLLOVERMENU_POINT_RIGHTTOP;
								break;
							case "BOTTOM_RIGHT":
								this.menuAttachPoint = ROLLOVERMENU_POINT_RIGHTBOTTOM;
								break;
							}
						}
						xmlAttribute =  xmlAttributeMap.getNamedItem("x");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.menuOffsetX = parseInt(xmlAttribute.value);
						xmlAttribute =  xmlAttributeMap.getNamedItem("y");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.menuOffsetY = parseInt(xmlAttribute.value);
				
						xmlAttribute = xmlAttributeMap.getNamedItem("buttonCoords");
						if(xmlAttribute != null && xmlAttribute.specified){
							var coords = (xmlAttribute.value).split(";");
							for(var i = 0; i < coords.length; i++){
								var subCoords = coords[i].split(",");
								this.buttonCoords.push(subCoords);
							};
						}
					}
				} else if(xmlNode.nodeName == "background"){
					xmlAttributeMap = xmlNode.attributes;
					if(xmlAttributeMap){
						xmlAttribute = xmlAttributeMap.getNamedItem("options");
						if(xmlAttribute != null && xmlAttribute.specified){
							var optionCount =  xmlAttribute.value;
							xmlAttribute = xmlAttributeMap.getNamedItem("src");
							if(xmlAttribute != null && xmlAttribute.specified){
								this.menuBackgroundSrc[optionCount] = xmlAttribute.value;
								//trace("#FF00FF" + this.menuBackgroundSrc[optionCount]);
							}
						}
					}	
				}else if(xmlNode.nodeName == "button"){
					xmlAttributeMap = xmlNode.attributes;
					if(xmlAttributeMap){
						xmlAttribute = xmlAttributeMap.getNamedItem("id");
						if(xmlAttribute != null && xmlAttribute.specified){
							if(xmlAttribute.value == "left"){
								this.btnScrollLeft = new Composition();
								this.btnScrollLeft._class = "rnmc_stdButton"
								this.btnScrollLeft.parent = this;
								this.btnScrollLeft.depth = -2;
								this.btnScrollLeft.initFromNode(xmlNode);
								this.btnScrollLeft.setPressCallBack(this, this.buttonDispatcher);
							} else if (xmlAttribute.value == "up" ){
								this.btnScrollUp = new Composition();
								this.btnScrollUp._class = "rnmc_stdButton"
								this.btnScrollUp.parent = this;
								this.btnScrollUp.depth = -2;
								this.btnScrollUp.initFromNode(xmlNode);
								this.btnScrollUp.setPressCallBack(this, this.buttonDispatcher);
							} else if(xmlAttribute.value == "down"){
								this.btnScrollDown = new Composition();
								this.btnScrollDown._class = "rnmc_stdButton"
								this.btnScrollDown.parent = this;
								this.btnScrollDown.depth = -2;
								this.btnScrollDown.initFromNode(xmlNode);
								this.btnScrollDown.setPressCallBack(this, this.buttonDispatcher);
							} else if(xmlAttribute.value == "right"){
								this.btnScrollRight = new Composition();
								this.btnScrollRight._class = "rnmc_stdButton"
								this.btnScrollRight.parent = this;
								this.btnScrollRight.depth = -2;
								this.btnScrollRight.initFromNode(xmlNode);
								this.btnScrollRight.setPressCallBack(this, this.buttonDispatcher);
							}
						}
					}
				}
				xmlNode = xmlNode.nextSibling;
			}
		}
		return true;
	}
	
	
	function attachToObject(targetObject, targetPoint, targetX, targetY){
		if(targetPoint != undefined)
			this.menuAttachPoint = targetPoint;
		if(targetX != undefined)
			this.menuOffsetX = targetX;
		if(targetY != undefined)
			this.menuOffsetY = targetY;
		this.reattachToObject(targetObject);
	}
	
	function setCallBack(pointerToObject, callbackFunction){
		this.callBackObject = pointerToObject;
		this.callBackFunction = callbackFunction;
	};
	
	function showObject(){
		if(this.btnScrollLeft){
			this.btnScrollLeft.showObject();
		}
		if(this.btnScrollRight){
			this.btnScrollRight.showObject();
		}
		if(this.btnScrollUp){
			this.btnScrollUp.showObject();
		}
		if(this.btnScrollDown){
			this.btnScrollDown.showObject();
		}
		this.visible = true;
	}
	
	function hideObject(){
		if(this.btnScrollLeft){
			this.btnScrollLeft.hideObject();
		}
		if(this.btnScrollRight){
			this.btnScrollRight.hideObject();
		}
		if(this.btnScrollUp){
			this.btnScrollUp.hideObject();
		}
		if(this.btnScrollDown){
			this.btnScrollDown.hideObject();
		}
		this.visible = false;
	}
	
	function buttonDispatcher(btnId){
		//trace("scrollMenu.buttonDispatcher");
		if(this.callBackObject && this.callBackFunction)
			this.callBackFunction.call(this.callBackObject, btnId, this.scrollSpeed);
	}
]]></script>
</composition>
</rmml>