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

last change: $Date: 2009-03-23 17:20:36 +0300 (Пн, 23 мар 2009) $
             $Author: Pavel $

	Lacerta Project
	version 1.0.0.1
	Copyright (C) 2007-2009 RNMC
-->
<composition name="rnmc_stdSlider" class="rnmc_stdObject">
<script><![CDATA[
// 	идентификатор объекта
	this.id = null;
//	видимость объекта
	this.visibility = OBJECT_VISIBILITY_TRUE;

//	параметры вывода слайдера
//	вертикальный или горизонтальный
	this.objectOrientation = SLIDER_HORIZONTAL;
//	с делениями или без (непрерывный)
	this.useTicks = false;
//	вызывать ли callback при onMouseMove
	this.callOnMouseMove = false;
//	вызывать ли callback при onRelease
	this.callOnRelease = true;

//	текущее выбранное значение (для дискретного слайдера)
	this.currentItem = 0;
//	текущая позиция (для непрерывного слайдера)
	this.currentPosition = 0;
//	массив положений меток
	this.sliderTicks = null;
//	актуальная ширина
	this.sliderWidth = 0;
//	актуальная высота
	this.sliderHeight = 0;
	
//	крайние значания слайдера при использовании без проигрываемого объекта
	this.min = 0;
	this.max = null;
//	шаг шкалы значений значений слайдера	
	this.delta = 1;

//	действия при выборе некоторого элемента (деления)
	this.onItemSelectedActions = null;
//	действия на смену положения слайдера
	this.onValueChangedActions = null;

//	путь к файлу фонового изображения
	this.backgroundSrc = null;
//	путь к файлу шарика (нормальное состояние)
	this.ballNormalSrc = null;
//	путь к файлу шарика (наведенное состояние)
	this.ballOverSrc = null;	
//	путь к файлу шарика (нажатое состояние)
	this.ballPressedSrc = null;
//	фоновое изображение слайдера
	this.sliderBackground = null;
//	смещение шарика относительно всего контрола по X
	this.ballOffsetX = 0;
//	смещение шарика относительно всего контрола по Y
	this.ballOffsetY = 0;
//	выставлять размер фона в соответствии с размерами
	this.adjustBackgroundSize = false;
//	объект Image шарика
	this.sliderBall = null;
//	смещение курсора мыши
	this.mouseBallOffset = 0;
//	общее количество засечек (только при useTicks == true)
	this.itemsTotal = 0;
	
//	объект число слайдера
	this.numberObject = null;
//	показывается ли число слайдера
	this.showNumber = false;

//	стиль числа слайдера
	this.numberStyle = null;
//	смещение числа слайдера относительно всего слайдера по X
	this.numberOffsetX = 0;
//	смещение числа слайдера относительно всего слайдера по Y
	this.numberOffsetY = 0;
//	глубина числа слайдера относительно самого слайдера
	this.numberDepth = 0;
	this.numberWidth = 0;
	this.numberHeight = 0;

	function initFromNode(srcNode){
		var xmlNode = null;
		var xmlAttributeMap = null;
		var xmlAttribute = null;

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

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

		// Для совместимости со старым синтаксисом
			xmlAttribute = xmlAttributeMap.getNamedItem("x");
			if (xmlAttribute != null && xmlAttribute.specified)
				this.objectX = parseInt(xmlAttribute.value);
			xmlAttribute = xmlAttributeMap.getNamedItem("y");
			if (xmlAttribute != null && xmlAttribute.specified)
				this.objectY = parseInt(xmlAttribute.value);
			xmlAttribute = xmlAttributeMap.getNamedItem("width");
			if (xmlAttribute != null && xmlAttribute.specified)
				this.objectWidth = parseInt(xmlAttribute.value);
			xmlAttribute =  xmlAttributeMap.getNamedItem("ballNormal");
			if (xmlAttribute != null && xmlAttribute.specified)
				this.ballNormalSrc =
					scene.Utils.makePathSrc(srcBase, xmlAttribute.value);
			xmlAttribute =  xmlAttributeMap.getNamedItem("ballPressed");
			if (xmlAttribute != null && xmlAttribute.specified)
				this.ballPressedSrc =
					scene.Utils.makePathSrc(srcBase, xmlAttribute.value);
			xmlAttribute =  xmlAttributeMap.getNamedItem("bgSrc");
			if (xmlAttribute != null && xmlAttribute.specified) {
				this.backgroundSrc =
					scene.Utils.makePathSrc(srcBase, xmlAttribute.value);
				this.adjustBackgroundSize = true;
			}
			xmlAttribute =  xmlAttributeMap.getNamedItem("ball_normal");
			if (xmlAttribute != null && xmlAttribute.specified)
				this.ballNormalSrc =
					scene.Utils.makePathSrc(srcBase, xmlAttribute.value);
			xmlAttribute =  xmlAttributeMap.getNamedItem("ball_pressed");
			if (xmlAttribute != null && xmlAttribute.specified)
				this.ballPressedSrc =
					scene.Utils.makePathSrc(srcBase, xmlAttribute.value);
			xmlAttribute =  xmlAttributeMap.getNamedItem("src");
			if (xmlAttribute != null && xmlAttribute.specified) {
				this.backgroundSrc =
					scene.Utils.makePathSrc(srcBase, xmlAttribute.value);
				this.adjustBackgroundSize = true;
			}
		}
		xmlNode = srcNode.firstChild;
		while(xmlNode){
			if(xmlNode.nodeName == "param"){
				xmlAttributeMap = xmlNode.attributes;
				if(xmlAttributeMap){
					xmlAttribute =  xmlAttributeMap.getNamedItem("orientation");
					if (xmlAttribute != null && xmlAttribute.specified){
						switch((xmlAttribute.value).toLowerCase()){
						case "vertical":
							this.objectOrientation = SLIDER_VERTICAL;
							break;
						case "horizontal":
							this.objectOrientation = SLIDER_HORIZONTAL;
							break;
						}
					}
					xmlAttribute =  xmlAttributeMap.getNamedItem("useTicks");
					if (xmlAttribute != null && xmlAttribute.specified){
						switch((xmlAttribute.value).toLowerCase()){
						case "true":
							this.useTicks = true;
							break;
						case "false":
							this.useTicks = false;
							break;
						}
					}
					xmlAttribute =  xmlAttributeMap.getNamedItem("items");
					if (xmlAttribute != null && xmlAttribute.specified)
						this.itemsTotal = parseInt(xmlAttribute.value);
					xmlAttribute =  xmlAttributeMap.getNamedItem("currentItem");
					if (xmlAttribute != null && xmlAttribute.specified)
						this.currentItem = parseInt(xmlAttribute.value);
					xmlAttribute =  xmlAttributeMap.getNamedItem("x");
					if (xmlAttribute != null && xmlAttribute.specified)
						this.objectX = parseInt(xmlAttribute.value);
					xmlAttribute =  xmlAttributeMap.getNamedItem("y");
					if (xmlAttribute != null && xmlAttribute.specified)
						this.objectY = parseInt(xmlAttribute.value);
					xmlAttribute =  xmlAttributeMap.getNamedItem("width");
					if (xmlAttribute != null && xmlAttribute.specified){
						this.objectWidth = parseInt(xmlAttribute.value);
					} else {
					//	выставляем ширину в ноль, что означает, что её 
					//	надо будет взять при загрузке из изображения
						if (this.objectWidth == 0)
							this.objectWidth = -1;
					}
					xmlAttribute =  xmlAttributeMap.getNamedItem("height");
					if (xmlAttribute != null && xmlAttribute.specified){
						this.objectHeight = parseInt(xmlAttribute.value);
					} else {
						//	выставляем высоту в ноль, что означает, что её 
						//	надо будет взять при загрузке из изображения
						this.objectHeight = -1;
					}
					xmlAttribute =  xmlAttributeMap.getNamedItem("adjustSize");
					if (xmlAttribute != null && xmlAttribute.specified){
						switch((xmlAttribute.value).toLowerCase()){
							case "true":
								this.adjustBackgroundSize = true;
								break;
							case "false":
								this.adjustBackgroundSize = false;
								break;
						}
					}
					xmlAttribute =  xmlAttributeMap.getNamedItem("depth");
					if (xmlAttribute != null && xmlAttribute.specified)
						this.objectDepth = parseInt(xmlAttribute.value);
					
				//	крайние значания слайдера при использовании без проигрываемого объекта
					xmlAttribute =  xmlAttributeMap.getNamedItem("min");
					if (xmlAttribute != null && xmlAttribute.specified)
						this.min = parseInt(xmlAttribute.value);
					xmlAttribute =  xmlAttributeMap.getNamedItem("max");
					if (xmlAttribute != null && xmlAttribute.specified)
						this.max = parseInt(xmlAttribute.value);
				//	шаг значений слайдера
					xmlAttribute =  xmlAttributeMap.getNamedItem("delta");
					if (xmlAttribute != null && xmlAttribute.specified)
						this.delta = parseFloat(xmlAttribute.value);

				// Для совместимости со старым синтаксисом
					xmlAttribute =  xmlAttributeMap.getNamedItem("background");
					if (xmlAttribute != null && xmlAttribute.specified) {
						this.backgroundSrc =
							scene.Utils.makePathSrc(srcBase, xmlAttribute.value);
						this.adjustBackgroundSize = true;
					}

				// Для совместимости с еще одним старым синтаксисом
					xmlAttribute =  xmlAttributeMap.getNamedItem("ballNormal");
					if (xmlAttribute != null && xmlAttribute.specified)
						this.ballNormalSrc =
							scene.Utils.makePathSrc(srcBase, xmlAttribute.value);
					xmlAttribute =  xmlAttributeMap.getNamedItem("ballPressed");
					if (xmlAttribute != null && xmlAttribute.specified)
						this.ballPressedSrc =
							scene.Utils.makePathSrc(srcBase, xmlAttribute.value);
					xmlAttribute =  xmlAttributeMap.getNamedItem("bgSrc");
					if (xmlAttribute != null && xmlAttribute.specified) {
						this.backgroundSrc =
							scene.Utils.makePathSrc(srcBase, xmlAttribute.value);
						this.adjustBackgroundSize = true;
					}
				}
			} else if(xmlNode.nodeName == "ball"){
			// Для совместимости со старым синтаксисом
				xmlAttributeMap = xmlNode.attributes;
				if(xmlAttributeMap){
					xmlAttribute =  xmlAttributeMap.getNamedItem("srcNormal");
					if (xmlAttribute != null && xmlAttribute.specified)
						this.ballNormalSrc =
							scene.Utils.makePathSrc(srcBase, xmlAttribute.value);
					xmlAttribute =  xmlAttributeMap.getNamedItem("srcPressed");
					if (xmlAttribute != null && xmlAttribute.specified)
						this.ballPressedSrc =
							scene.Utils.makePathSrc(srcBase, xmlAttribute.value);
				}
			} else if(xmlNode.nodeName == "layout"){
				xmlAttributeMap = xmlNode.attributes;
				if(xmlAttributeMap){
					xmlAttribute =  xmlAttributeMap.getNamedItem("bg");
					if (xmlAttribute != null && xmlAttribute.specified){
						this.backgroundSrc =  scene.Utils.makePathSrc(srcBase, xmlAttribute.value);
						this.adjustBackgroundSize = true;
					}
					xmlAttribute =  xmlAttributeMap.getNamedItem("ballNormal");
					if (xmlAttribute != null && xmlAttribute.specified)
						this.ballNormalSrc =  scene.Utils.makePathSrc(srcBase, xmlAttribute.value);
					xmlAttribute =  xmlAttributeMap.getNamedItem("ballPressed");
					if (xmlAttribute != null && xmlAttribute.specified)
						this.ballPressedSrc =  scene.Utils.makePathSrc(srcBase, xmlAttribute.value);
					xmlAttribute =  xmlAttributeMap.getNamedItem("ballOver");
					if (xmlAttribute != null && xmlAttribute.specified)
						this.ballOverSrc =
							scene.Utils.makePathSrc(srcBase, xmlAttribute.value);
					xmlAttribute =  xmlAttributeMap.getNamedItem("ballOffsetX");
					if (xmlAttribute != null && xmlAttribute.specified)
						this.ballOffsetX = parseInt(xmlAttribute.value);
					xmlAttribute =  xmlAttributeMap.getNamedItem("ballOffsetY");
					if (xmlAttribute != null && xmlAttribute.specified)
						this.ballOffsetY = parseInt(xmlAttribute.value);
				}
			} else if(xmlNode.nodeName == "number"){
				xmlAttributeMap = xmlNode.attributes;
				this.showNumber = true;
				if(xmlAttributeMap){
					xmlAttribute =  xmlAttributeMap.getNamedItem("style");
					if (xmlAttribute != null && xmlAttribute.specified)
						this.numberStyle = xmlAttribute.value;
					xmlAttribute =  xmlAttributeMap.getNamedItem("offsetX");
					if (xmlAttribute != null && xmlAttribute.specified)
						this.numberOffsetX = parseInt(xmlAttribute.value);
					xmlAttribute =  xmlAttributeMap.getNamedItem("offsetY");
					if (xmlAttribute != null && xmlAttribute.specified)
						this.numberOffsetY = parseInt(xmlAttribute.value);
					xmlAttribute =  xmlAttributeMap.getNamedItem("width");
					if (xmlAttribute != null && xmlAttribute.specified)
						this.numberWidth = parseInt(xmlAttribute.value);
					xmlAttribute =  xmlAttributeMap.getNamedItem("height");
					if (xmlAttribute != null && xmlAttribute.specified)
						this.numberHeight = parseInt(xmlAttribute.value);
					xmlAttribute =  xmlAttributeMap.getNamedItem("depth");
					if (xmlAttribute != null && xmlAttribute.specified)
						this.numberDepth = parseInt(xmlAttribute.value);
				}
			} else if(xmlNode.nodeName == "actions"){
				this.onItemSelectedActions =
					scene.Utils.parseActionsNode(xmlNode, "onItemSelected");
				this.onValueChangedActions =
					scene.Utils.parseActionsNode(xmlNode, "onValueChanged");
			}
			xmlNode = xmlNode.nextSibling;
		}

		if(!this.ballNormalSrc)
			return false;

		return true;
	}

	function loadObject(){
		if(!this.sliderBackground && this.backgroundSrc){
			this.sliderBackground = new Image();
			this.sliderBackground.src = this.backgroundSrc;
			this.sliderBackground.parent = this;
			if(this.objectOrientation == SLIDER_HORIZONTAL && this.objectWidth > 0){
				if(this.adjustBackgroundSize){
					this.sliderBackground.width = this.objectWidth;
				}
			} else if(this.objectOrientation == SLIDER_HORIZONTAL){
				this.objectWidth = this.sliderBackground.width;
			}
			if(this.objectOrientation == SLIDER_VERTICAL && this.objectHeight > 0){
				if(this.adjustBackgroundSize){
					this.sliderBackground.height = this.objectHeight;
				}
			} else if(this.objectOrientation == SLIDER_VERTICAL){
				this.objectHeight = this.sliderBackground.height;
			}
			
			this.sliderBackground.onPress = this.sliderOnPressAlias;
			this.sliderBackground.onRelease = this.sliderOnReleaseAlias;
			this.sliderBackground.onReleaseOutside = this.sliderOnReleaseAlias;
			if (this.ballOverSrc){
				this.sliderBackground.onRollOver = this.sliderOnRollOverAlias;
				this.sliderBackground.onRollOut  = this.sliderOnRollOutAlias;
			}
			
			if(this.objectWidth == -1){
				this.objectWidth = this.sliderBackground.width;
			}
			if(this.objectHeight == -1){
				this.objectHeight = this.sliderBackground.height;
			}
		}
		if(!this.sliderBall){
			this.sliderBall = new Image();
			this.sliderBall.src = this.ballNormalSrc;
			this.sliderBall.parent = this;
			this.sliderBall.onPress = this.ballOnPressAlias;
			this.sliderBall.onRelease = this.ballOnReleaseAlias;
			this.sliderBall.onReleaseOutside = this.ballOnReleaseOutsideAlias;
			this.sliderBall.x = this.ballOffsetX;
			this.sliderBall.y = this.ballOffsetY;
			this.mouseBallOffset = parseInt(this.sliderBall.width/2);
			if (this.ballOverSrc){
				this.sliderBall.onRollOver = this.sliderOnRollOverAlias;
				this.sliderBall.onRollOut  = this.sliderOnRollOutAlias;
			}			
		}
		if(!this.numberObject && this.showNumber){
			this.numberObject = new Composition();
			this.numberObject._class = "rnmc_stdInputEx";
			this.numberObject.parent = this;
			this.numberObject.objectX = this.x + this.numberOffsetX;
			this.numberObject.objectY = this.y + this.numberOffsetY;						
			this.numberObject.objectWidth = this.numberWidth;
			this.numberObject.objectHeight = this.numberHeight;
			this.numberObject.objectDepth = this.depth + this.numberDepth;
			this.numberObject.objectStyle = this.numberStyle;
			this.numberObject.symbols = "digitals";						
		}
	}

	function unloadObject(){
		if(this.sliderBackground){
			this.sliderBackground.parent = null;
			this.sliderBackground = null;
		}
		if(this.sliderBall){
			this.sliderBall.parent = null;
			this.sliderBall = null;
		}
		if(this.numberObject){
			this.numberObject.parent = null;
			this.numberObject = null;
		}
	}

	function showObject(){
//trace("rnmc_stdSlider.showObject()");
		this.loadObject();

		var itemsDelta = 0;
		if(this.sliderBall && this.sliderBall.width > 0 && this.sliderBall.height > 0){
			if(this.objectOrientation == SLIDER_HORIZONTAL){
				this.sliderWidth = this.objectWidth - this.sliderBall.width;
				this.maxBound = this.sliderWidth;
				itemsDelta = parseFloat(this.sliderWidth/(this.itemsTotal - 1));
			} else if(this.objectOrientation == SLIDER_VERTICAL){
				this.sliderHeight = this.objectHeight - this.sliderBall.height;
				this.maxBound = this.sliderHeight;
				itemsDelta = parseFloat(this.sliderHeight/(this.itemsTotal - 1));
			}
		} else {
			trace("#FF0000ОШИБКА!!!!!!!");
		}
		var newItemPos = 0;
		this.sliderTicks = new Array();
		for(var i = 0; i < this.itemsTotal; i++){
			this.sliderTicks.push(parseInt(newItemPos));
			newItemPos = parseFloat(newItemPos + itemsDelta);
		}
		this.x = this.objectX;
		this.y = this.objectY;
		this.depth = this.objectDepth;
		this.visible = true;
		this.updateSliderBall();
		this.onItemSelectedDispatcher();
		
		if(this.numberObject){
			var delta = 0;
			var digitals = 0;
			if(this.max != null && this.max.toString().length > this.min.toString().length)
				digitals = this.max.toString().length
			else
				digitals = this.min.toString().length;
			if(this.delta < 1)
				delta = this.delta.toString().length - 1;
	
			if(this.useTicks){
				if(this.itemsTotal > 0)
					this.numberObject.maxChars = digitals + delta;
				this.numberObject.objectValue = Math.round((this.min + this.currentItem * Math.abs(this.max - this.min) / (this.itemsTotal - 1)) / this.delta) / (1 / this.delta);
			} else{
				if(this.maxBound){
					this.numberObject.maxChars = digitals + delta;
				}
				this.numberObject.objectValue = Math.round((this.min + this.currentPosition * Math.abs(this.max - this.min) / this.maxBound) / this.delta) / (1 / this.delta);
			}
			
			this.numberObject.showObject();
			this.numberObject.objectContent.onKeyDown = this.onKeyDownHandler;
			this.numberObject.objectContent.onKillFocus = this.onKillFocusHandler;
		}
	}

	function hideObject(){
		this.unloadObject();
		this.visible = false;
	}

	
	function onKeyDownHandler(){
		var object = this.parent.parent;
		var max = object.max > object.min ? object.max : object.min;
		var min = object.max < object.min ? object.max : object.min;
		this.parent.onKeyDownHandlerAlias();
		if(Key.keyCode == 13){
			if(object.useTicks)
				if(this.value.valueOf() > max || this.value.valueOf() < min){
					this.value = Math.round((object.min + object.currentItem * (object.max - object.min) / (object.itemsTotal - 1)) / object.delta) / (1 / object.delta);
					return false;
				} else{
					object.currentItem = Math.round(Math.abs(this.value.valueOf() - object.min) * (object.itemsTotal - 1) / Math.abs(object.max - object.min));
					this.value = Math.round((object.min + object.currentItem * (object.max - object.min) / (object.itemsTotal - 1)) / object.delta) / (1 / object.delta);
					object.onValueChangedDispatcher();
				}
			else
				if(this.value.valueOf() > max || this.value.valueOf() < min){
					this.value = Math.round((object.min + object.currentPosition * Math.abs(object.max - object.min) / object.maxBound) / object.delta) / (1 / object.delta);
					return false;
				} else{
					object.currentPosition = Math.round(Math.abs(this.value.valueOf() - object.min) * object.maxBound / Math.abs(object.max - object.min));
					object.onValueChangedDispatcher();
				}
			object.updateSliderBall();
			object.ballOnReleaseAlias();
		}
	}
	
	function onKillFocusHandler(){
		var object = this.parent.parent;
		var max = object.max > object.min ? object.max : object.min;
		var min = object.max < object.min ? object.max : object.min;
		this.parent.onKillFocusHandlerAlias();
		if(object.useTicks)
			if(this.value.valueOf() > max || this.value.valueOf() < min){
				this.value = Math.round((object.min + object.currentItem * (object.max - object.min) / (object.itemsTotal - 1)) / object.delta) / (1 / object.delta);
				return false;
			} else{
				object.currentItem = Math.round(Math.abs(this.value.valueOf() - object.min) * (object.itemsTotal - 1) / Math.abs(object.max - object.min));
				this.value = Math.round((object.min + object.currentItem * (object.max - object.min) / (object.itemsTotal - 1)) / object.delta) / (1 / object.delta);
				object.onValueChangedDispatcher();
			}
		else
			if(this.value.valueOf() > max || this.value.valueOf() < min){
				this.value = Math.round((object.min + object.currentPosition * Math.abs(object.max - object.min) / object.maxBound) / object.delta) / (1 / object.delta);
				return false;
			} else{
				object.currentPosition = Math.round(Math.abs(this.value.valueOf() - object.min) * object.maxBound / Math.abs(object.max - object.min));
				object.onValueChangedDispatcher();
			}
		object.updateSliderBall();
		object.ballOnReleaseAlias();
	}
	
	function setUseTicks(newUseTicks){
		if(newUseTicks != undefined){
			this.useTicks = newUseTicks;
		}
	}

	function setItems(newItems){
		if(newItems != undefined){
			this.itemsTotal = newItems;
		}
	}

	function sliderOnPressAlias(){
		sliderOnPress();
	}

	function sliderOnPress(){
		if(this.objectOrientation == SLIDER_HORIZONTAL){
			this.mouseBallOffset = parseInt(this.sliderBall.width/2);
		} else if(this.objectOrientation == SLIDER_VERTICAL){
			this.mouseBallOffset = parseInt(this.sliderBall.height/2);
		}
		var currentCallVal = this.callOnMouseMove;
		this.callOnMouseMove = true;
		this.calculateCurrentPosition();
		this.callOnMouseMove = currentCallVal;
	}

	function sliderOnReleaseAlias(){
		sliderOnRelease();
	}

	function sliderOnRelease(){
	}

	function ballOnPressAlias(){
		ballOnPress();
	}

	function ballOnPress(){
		this.captured = true;
		if(this.objectOrientation == SLIDER_HORIZONTAL){
			this.mouseBallOffset = this.xMouse - this.sliderBall.x;
		} else if(this.objectOrientation == SLIDER_VERTICAL){
			this.mouseBallOffset = this.yMouse - this.sliderBall.y;
		}
		if (this.ballPressedSrc)
			this.sliderBall.src = this.ballPressedSrc;
		this.onMouseMove = mouseMoveHandler;
	}

	function ballOnReleaseAlias(){
		ballOnRelease();
	}

	function ballOnReleaseOutsideAlias(){
		ballOnRelease();
	}
	
	function ballOnRelease(){
		this.onMouseMove = null;
		this.captured = false;
		
		if (this.ballOverSrc && this.sliderBall.src != this.ballOverSrc){
			this.sliderBall.src = this.ballOverSrc;
		} else if (this.sliderBall.src != this.ballOverSrc)
			this.sliderBall.src = this.ballNormalSrc;

		if(this.objectOrientation == SLIDER_HORIZONTAL){
			this.mouseBallOffset = parseInt(this.sliderBall.width/2);
		} else if(this.objectOrientation == SLIDER_VERTICAL){
			this.mouseBallOffset = parseInt(this.sliderBall.height/2);
		}
		if(this.useTicks){	//	дискретный слайдер
			if(this.callOnRelease){
				var newPercentPosition = parseFloat(this.currentPosition/this.maxBound);
				if(this.callbackObject && this.callbackFunction)
					this.callbackFunction.call(this.callbackObject, this.currentItem);
			}
		} else {	//	непрерывный слайдер
			if(this.callOnRelease){
				var newPercentPosition = parseFloat(this.currentPosition/this.maxBound);
				if(this.callbackObject && this.callbackFunction)
					this.callbackFunction.call(this.callbackObject, newPercentPosition);
			}
		}
	}
	
	function sliderOnRollOverAlias() {
		ballOnRollOver();
	}
	
	function ballOnRollOver() {
		if (this.ballOverSrc && this.sliderBall.src != this.ballOverSrc)
			this.sliderBall.src = this.ballOverSrc;
	}
	
	function sliderOnRollOutAlias() {
		ballOnRollOut();
	}
	
	function ballOnRollOut() {
		if (Mouse.target == this.sliderBall)
			return;

		if (this.sliderBall.src != this.ballNormalSrc)
			this.sliderBall.src = this.ballNormalSrc;
	}

	function mouseMoveHandler(){
		if(this.captured)
			this.calculateCurrentPosition();
	}

//	вычисляет текущую позицию шарика (в пикселях)
	function calculateCurrentPosition(){
		if(this.useTicks){
			var cursorPosition = 0;
			var newItem = 0;
			if(this.objectOrientation == SLIDER_HORIZONTAL){
				cursorPosition = this.xMouse - this.mouseBallOffset;
			} else if(this.objectOrientation == SLIDER_VERTICAL){
				cursorPosition = this.yMouse - this.mouseBallOffset;
			}
			if(cursorPosition < 0){
				newItem = 0;
				if(newItem != this.currentItem){
					this.currentItem = newItem;
					if (this.numberObject)
						this.numberObject.objectContent.value = Math.round((this.min + this.currentItem * (this.max - this.min) / (this.itemsTotal - 1)) / this.delta) / (1 / this.delta);
					this.updateSliderBall();
					this.onItemSelectedDispatcher();
					this.onValueChangedDispatcher();
					if(this.callOnMouseMove){
						if(this.newItemCallbackObject && this.newItemCallbackFunction)
							this.newItemCallbackFunction.call(this.newItemCallbackObject, this.currentItem);
					}
				}
				return;
			} else if(cursorPosition > this.sliderTicks[this.sliderTicks.length-1]){
				newItem = this.itemsTotal - 1;
				if(newItem != this.currentItem){
					this.currentItem = newItem;
					if (this.numberObject)
						this.numberObject.objectContent.value = Math.round((this.min + this.currentItem * (this.max - this.min) / (this.itemsTotal - 1)) / this.delta) / (1 / this.delta);
					this.updateSliderBall();
					this.onItemSelectedDispatcher();
					this.onValueChangedDispatcher();
					if(this.callOnMouseMove){
						if(this.newItemCallbackObject && this.newItemCallbackFunction)
							this.newItemCallbackFunction.call(this.newItemCallbackObject, this.currentItem);
					}
				}
				return;
			} else {
				for(var i = 0; i < this.sliderTicks.length-1; i++){
					if(cursorPosition >= this.sliderTicks[i]
						&& cursorPosition <= this.sliderTicks[i + 1]){
						if((cursorPosition - this.sliderTicks[i]) > (this.sliderTicks[i + 1] - cursorPosition)){
							newItem = i + 1;
						} else {
							newItem = i;
						}
						if(newItem != this.currentItem){
							this.currentItem = newItem;
							if (this.numberObject)
								this.numberObject.objectContent.value = Math.round((this.min + this.currentItem * (this.max - this.min) / (this.itemsTotal - 1)) / this.delta) / (1 / this.delta);
							this.updateSliderBall();
							this.onItemSelectedDispatcher();
							this.onValueChangedDispatcher();
							if(this.callOnMouseMove){
								if(this.newItemCallbackObject && this.newItemCallbackFunction)
									this.newItemCallbackFunction.call(this.newItemCallbackObject, this.currentItem);
							}
							break;
						}
					}
				}
			}
		} else {
			//	непрерывный слайдер
			var cursorPosition = 0;
			if(this.objectOrientation == SLIDER_HORIZONTAL){
				cursorPosition = (this.xMouse - this.ballOffsetX) - this.mouseBallOffset;
			} else if(this.objectOrientation == SLIDER_VERTICAL){
				cursorPosition = (this.yMouse - this.ballOffsetY) - this.mouseBallOffset;
			}
			if(cursorPosition <= 0){
				cursorPosition = 0;
				if(this.callOnMouseMove){
					if(this.newItemCallbackObject && this.newItemCallbackFunction)
						this.newItemCallbackFunction.call(this.newItemCallbackObject, this.currentItem);
				}
			} else if(cursorPosition > this.maxBound){
				cursorPosition = this.maxBound;
				if(this.callOnMouseMove){
					if(this.newItemCallbackObject && this.newItemCallbackFunction)
						this.newItemCallbackFunction.call(this.newItemCallbackObject, this.currentItem);
				}
			}
			this.currentPosition = cursorPosition;
			if (this.numberObject)
				this.numberObject.objectContent.value = Math.round((this.min + this.currentPosition * (this.max - this.min) / this.maxBound) / this.delta) / (1 / this.delta);
			this.updateSliderBall();
			this.onValueChangedDispatcher();
			if(this.callOnMouseMove){
				var newPercentPosition = parseFloat(this.currentPosition/this.maxBound);
				if(this.callbackObject && this.callbackFunction)
					this.callbackFunction.call(this.callbackObject, newPercentPosition);
			}
		}
	}

	function updateSliderBall(){
		if (!this.sliderBall)
			return;

		if(this.useTicks){
			//	слайдер с насечками
			if(this.objectOrientation == SLIDER_HORIZONTAL){
				this.sliderBall.x = this.ballOffsetX + this.sliderTicks[this.currentItem];
			} else if(this.objectOrientation == SLIDER_VERTICAL){
				this.sliderBall.y = this.ballOffsetY + this.sliderTicks[this.currentItem];
			}
		} else {
			//	непрерывный слайдер
			if(this.objectOrientation == SLIDER_HORIZONTAL){
				this.sliderBall.x = this.ballOffsetX + this.currentPosition;
			} else if(this.objectOrientation == SLIDER_VERTICAL){
				this.sliderBall.y = this.ballOffsetY + this.currentPosition;
			}
		}
	}
	
	function onItemSelectedDispatcher(){
		if(this.useTicks && this.onItemSelectedActions){
			for(var i = 0; i < this.onItemSelectedActions.length; i++){
				if(this.onItemSelectedActions[i].eventParam
					&& parseInt(this.onItemSelectedActions[i].eventParam) == this.currentItem){
					parent.dispatchAction(this.onItemSelectedActions[i]);
				}
			}
		}
	}
	
	function onValueChangedDispatcher(){
		if(this.onValueChangedActions){
			for(var i = 0; i < this.onValueChangedActions.length; i++){
				parent.dispatchAction(this.onValueChangedActions[i]);
			}
		}
	}

//	установка текущего элемента	
	function setSliderItem(newItem){
		if(!this.captured){
			if(this.useTicks && newItem != undefined){
				currentItem = newItem;
				this.updateSliderBall();
				this.onItemSelectedDispatcher();
				if(this.newItemCallbackObject && this.newItemCallbackFunction)
					this.newItemCallbackFunction.call(this.newItemCallbackObject, this.currentItem);
			};
		}
	}

//	отличается от setCurrentItem, что не вызывает callback'ов и не
//	обрабатывает действия
	function synchronizeSliderItem(newItem){
		if(!this.captured){
			if(this.useTicks && newItem != undefined){
				currentItem = newItem;
				this.updateSliderBall();
			}
		}
	}

//	установка текущего положения
	function setSliderPosition(newValue){
		if(!this.captured){
			if(!this.useTicks && newValue != undefined){
				this.currentPosition = Math.round(newValue*this.sliderWidth);
				if (this.numberObject)
					this.numberObject.objectContent.value = Math.round((this.min + this.currentPosition * (this.max - this.min) / this.maxBound) / this.delta) / (1 / this.delta);
				this.updateSliderBall();
				this.onItemSelectedDispatcher();
				var newPercentPosition = parseFloat(this.currentPosition/this.maxBound);
				if(this.callbackObject && this.callbackFunction)
					this.callbackFunction.call(this.callbackObject, newPercentPosition);
			};
		}
	}

//	отличается от setSliderPosition, что не вызывает callback'ов и не
//	обрабатывает действия
	function synchronizeSliderPosition(newValue){
		if(!this.captured){
			if(!this.useTicks && newValue != undefined){
				this.currentPosition = Math.round(newValue*this.sliderWidth);
				if (this.numberObject)
					this.numberObject.objectContent.value = Math.round((this.min + this.currentPosition * (this.max - this.min) / this.maxBound) / this.delta) / (1 / this.delta);
				this.updateSliderBall();
			};
		}
	}

	function setCallback(targetObject, targetFunction){
		if(targetObject)
			this.callbackObject = targetObject;
		if(targetFunction)
			this.callbackFunction = targetFunction;
	}

	function clearCallback(){
		this.callbackObject = null;
		this.callbackFunction = null;
	}
]]></script>
</composition>
</rmml>