﻿Common.Object.extend(Common.Utils, {
	getWindowSize: function(){
		var oResult = {
			iWidth: 0,
			iHeight: 0
		};
		oResult.iWidth = window.innerWidth ? window.innerWidth - 18 : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth ? document.body.clientWidth : 0;
		oResult.iHeight = window.innerHeight ? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight ? document.body.clientHeight : 0;
		return oResult;
	},
	
	getWindowScroll: function(){
		var oResult = {
			iScrollLeft: 0,
			iScrollTop: 0
		};
		oResult.iScrollLeft = window.pageXOffset ? window.pageXOffset : document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
		oResult.iScrollTop = window.pageYOffset ? window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
		return oResult;
	}
});


var oPhoto = {
	create: function(oParams){
		this.eNavigation = oParams.eNavigation;
		this.eContent = oParams.eContent;
		if(oParams.hLabel){
			this.sBigPictureLabel = (oParams.hLabel.sBigPicture)? oParams.hLabel.sBigPicture : 'Большая картинка';
		}
		var oThis = this;
		Common.Event.add(window, 'load', function(){
			oThis.init(oParams);
		});
	},

	init: function(oParams){
		var eNavigation_control = document.createElement('div');
		eNavigation_control.id = 'scroll';
		this.eNavigation.appendChild(eNavigation_control);
		eNavigation_control.innerHTML = '<div class="button left"></div><div class="button right"></div>' +
				'<div class="handler"><div class="left"></div><div class="right"></div></div>' +
				'<div class="getter"></div>'  +
				'<div class="clear"></div>' +
				'<div class="marks_container"></div>';
		var eNavigationReducer = Common.Dom.getElementsByClassName(oPhoto.eNavigation, 'reducer')[0]
		
			this.aeItems = Common.Dom.getElementsByClassName(oPhoto.eNavigation, 'coin_item');
		//this.aeItems = eNavigationReducer.getElementsByTagName('a');
		// Инициализируем только если есть область контента для показа большой фотки
		if(oParams.eContent){			
			this.oContent.create(oParams);
			if(oParams.bVertical){
				oPhoto.oContent.oControl.horizontal_mode();
			}
		}
		if(oParams.aoLabel.length > 1){
			for(var i = 0; i < oParams.aoLabel.length; i++){
				var eNavigation_mark = document.createElement('div');
				eNavigation_mark.className = 'mark';
				eNavigation_mark.style.left = oParams.aoLabel[i].iPosition / oPhoto.aeItems.length * 100 + '%';
				eNavigation_control.lastChild.appendChild(eNavigation_mark);
				eNavigation_mark.innerHTML = oParams.aoLabel[i].sTitle;
			}
		}
		this.Scroll.create(oParams);
	}
};


oPhoto.oContent = {

	create: function(oParams){
		var oPage;

		// Достаем уз урла hash - строку после символа решетки
		var locationParts = location.href.split('#');
		// Если есть якорь, то активируем соответствующую картинку, иначе активируем первую картинку
		var currentNumber = (locationParts && locationParts[1]) ? locationParts[1] : 0;

		this.hPage = [];
		
		for(var i = 0; i < oPhoto.aeItems.length; i++){
			var eDescription = Common.Dom.getElementsByClassName(oPhoto.aeItems[i], 'description')[0];
			if (eDescription) {
				var sDescription = eDescription.innerHTML;
			}
			var eDownload = Common.Dom.getElementsByClassName(oPhoto.aeItems[i], 'download')[0];
			if (eDownload) {
				var sDownload = eDownload.innerHTML;
			}
			oPage = new oPhoto.oContent.Page({
				eOn: oPhoto.aeItems[i],
				sDescription: sDescription,
				sDownload: sDownload,
				iNum: i,
				bCurrent: (currentNumber == i) ? true : false
			});
			this.hPage[i] = oPage;
		}
		
		Common.Event.add(document, 'keydown', function(oEvent) {
			var oEvent = Common.Event.normalize(oEvent);
			if(!oEvent.ctrlKey){
				return true;
			}
			if(oEvent.iKeyCode == 0x27){
				if(oPhoto.oContent.oCurrent.oNext){
					oPhoto.oContent.oCurrent.oNext.click();
				}
			}else if(oEvent.iKeyCode == 0x25){
				if(oPhoto.oContent.oCurrent.oPrev){
					oPhoto.oContent.oCurrent.oPrev.click();
				}
			}
		});
		Common.Event.add(window, 'resize', function(){
			oPhoto.oContent.resize();
		});
		/*Common.Event.add(oPhoto.eContent, 'mousemove', function(oEvent){
			oPhoto.oContent.mousemove(oEvent);
		});
		Common.Event.add(document.body, 'mouseout', function(oEvent){
			oPhoto.oContent.hide_pager(Common.Event.getAbsoluteCoords(oEvent));
		});
		Common.Event.add(oPhoto.eContent, 'mouseout', function(oEvent){
			oPhoto.oContent.mouseout(oEvent);
		});*/
		this.oControl.create(oParams);
	},

	set_current: function(oContent){
		this.oCurrent = oContent;
		this.resize();
	},

	mousemove: function(oEvent){
		this.oCoords = Common.Event.getAbsoluteCoords(oEvent);
		this.show_pager(this.oCoords);
		this.hide_pager(this.oCoords);
	},

	show_pager: function(oCoords){
		if(oCoords && oCoords.iTop >= this.oImage_coords.iTop && oCoords.iTop <= this.oImage_coords.iTop + this.oCurrent.eImage.offsetHeight){
			var iLeft = this.iContent_half_width - oCoords.iLeft;
			var iDelta = 1 - (this.iImage_half_width - Math.abs(iLeft)) / this.iImage_half_width;
			iDelta = iDelta <= 1 ? iDelta : 1;
			if(iLeft > 0){
				if(this.oCurrent.oPrev){
					iLeft = this.iContent_half_width - this.iImage_half_width - iDelta * iDelta * this.iPager_half_width;
					this.oCurrent.oPrev.iLeft = iLeft < -this.iPager_half_width ? -this.iPager_half_width : iLeft;
					this.oCurrent.oPrev.show();
				}
			}else if(this.oCurrent.oNext){
				iLeft = this.iImage_half_width + iDelta * iDelta * this.iPager_half_width - this.iPager_width;
				this.oCurrent.oNext.iLeft = iLeft < 0 ? this.iContent_width - this.iPager_half_width : iLeft;
				this.oCurrent.oNext.show();
			}
		}
	},

	mouseout: function(oEvent){
		this.hide_pager(Common.Event.getAbsoluteCoords(oEvent));
	},

	hide_pager: function(oCoords, bNow){
		if(!oCoords){
			if(this.oCurrent.oPrev){
				this.oCurrent.oPrev.hide(0);
			}
			if(this.oCurrent.oNext){
				this.oCurrent.oNext.hide(0);
			}
		}else if(oCoords.iTop < this.oImage_coords.iTop || oCoords.iLeft <=0 || oCoords.iLeft >= this.iContent_width){
			if(this.oCurrent.oPrev){
				this.oCurrent.oPrev.hide(1);
			}
			if(this.oCurrent.oNext){
				this.oCurrent.oNext.hide(-1);
			}
		}
	},

	resize: function(){
		if(this.oCurrent.eReducer){
			this.oImage_coords = Common.Dom.getAbsoluteCoords(this.oCurrent.eImage);
			
			var windowSize = Common.Utils.getWindowSize();

			var sHeight = this.oControl.bVertical ? windowSize.iHeight - this.oImage_coords.iTop  :
					(this.oCurrent.eImage.offsetHeight ? this.oCurrent.eImage.offsetHeight : 'auto');
					// this.oCurrent.eImage.offsetHeight - 24 
					
					if(sHeight != 'auto'){ if (sHeight < 400) {sHeight = 400 + 'px'} else {sHeight += 'px';}}
			//alert(windowSize.iHeight + ' - ' + this.oImage_coords.iTop + ' = ' + sHeight);
			this.oCurrent.eReducer.style.height = sHeight;
			if(this.oCurrent.oNext){
				this.oCurrent.oNext.eOn.style.height = sHeight;
			}
			if(this.oCurrent.oPrev){
				this.oCurrent.oPrev.eOn.style.height = sHeight;
			}
			this.iContent_width = windowSize.iWidth;
			this.iContent_half_width = this.iContent_width / 2;
			this.iImage_half_width = this.oCurrent.eImage.offsetWidth / 2;
			if(this.oCurrent.eImage_ghost){
				this.oCurrent.eImage_ghost.style.left = this.oCurrent.eImage.offsetLeft + 'px';
				this.oCurrent.eImage_ghost.style.width = this.oCurrent.eImage.offsetWidth + 'px';
				this.oCurrent.eImage_ghost.style.height = this.oCurrent.eImage.offsetHeight + 'px';
			}
			//this.hide_pager(null);
		}
	}
};


oPhoto.oContent.oControl = {
	create: function(oParams){
		var eParent = document.createElement('div');
		eParent.className = 'control';
		oPhoto.eContent.appendChild(eParent);
		eParent.innerHTML = '<span class="button horizontal selected" id="horizont"><ins class="icon"><ins></ins></ins>' + oParams.hLabel.sHorizontal + '</span>' +
				'<span id="vertical" class="button vertical"><ins class="icon"><ins></ins></ins>' + oParams.hLabel.sVertical + '</span>';
		var aeButton = eParent.getElementsByTagName('span');
		this.eHorizontal = aeButton[0];
		this.eVertical = aeButton[1];
		Common.Event.add(this.eHorizontal, 'click', function(){
			oPhoto.oContent.oControl.horizontal_mode();
		});
		Common.Event.add(this.eVertical, 'click', function(){
			oPhoto.oContent.oControl.vertical_mode();
		});
	},

	horizontal_mode: function(){
		this.bVertical = false;
		Common.Class.remove(this.eVertical, 'selected');
		Common.Class.add(this.eHorizontal, 'selected');
		Common.Class.remove(oPhoto.eContent, 'vertical');
		oPhoto.oContent.resize();
	},

	vertical_mode: function(){
		this.bVertical = true;
		Common.Class.remove(this.eHorizontal, 'selected');
		Common.Class.add(this.eVertical, 'selected');
		Common.Class.add(oPhoto.eContent, 'vertical');
		oPhoto.oContent.resize();
	}
};


oPhoto.oContent.Page = function(oParams){
	var oThis = this;
	this.eOn = oParams.eOn;
	this.sDescription = oParams.sDescription;
	this.sDownload = oParams.sDownload;
	this.iNum = oParams.iNum;
	if(oParams.bCurrent){
		this.bLoaded = true;
		this.eContent = document.createElement('div');
		this.eContent.className = 'content';
		this.eContent.innerHTML = '<p class="description">' +
					this.sDescription +
				'</p>' +
				'<p class="download"><a href="' + this.eOn.getElementsByTagName('a')[0].href + '">' + oPhoto.sBigPictureLabel + '</a><br/>' + this.sDownload + '</p>' +
				'<div class="reducer">' +
					'<img src="' + this.eOn.getElementsByTagName('a')[0].href + '"/>' + 
					//'<i class="arrow prev"></i>' +
					//'<i class="arrow next"></i>' +
				'</div>';
		//alert(this.eOn.href);
		oPhoto.eContent.appendChild(this.eContent);
		this.init();
		oPhoto.oContent.set_current(this);
		Common.Class.add(this.eOn, 'selected');
		//oPhoto.oContent.show_pager(oPhoto.oContent.oCoords);
		this.resize();
	}else{
		this.eContent = document.createElement('div');
		this.eContent.className = 'content hidden';
		oPhoto.eContent.appendChild(this.eContent);
	}
	Common.Event.add(oParams.eOn, 'click', function(oEvent){
		oThis.show();
		Common.Event.cancel(oEvent);
	});
};

oPhoto.oContent.Page.prototype = {
	show: function(){
		if(this.bLoaded){
			this.select();
		}else{
			this.onload();
		}
	},

	select: function(){
		this.start_animation();
		window.location.hash = this.iNum;
	},

	start_animation: function(){
		this.iStep = 0;
		this.iSteps = 10;
		this.iHalf_step = this.iSteps / 2;
		this.animation();
	},

	animation: function(){
		this.iStep++;
		if(this.iStep <= this.iSteps){
			if(this.iStep < this.iHalf_step){
				var iOpacity = (this.iHalf_step - this.iStep) / this.iHalf_step;
				oPhoto.oContent.oCurrent.eContent.style.opacity = iOpacity;
				oPhoto.oContent.oCurrent.eContent.style.filter = 'alpha(opacity=' + iOpacity * 100 + ')';
			}else if(this.iStep == this.iHalf_step){
				Common.Class.remove(oPhoto.oContent.oCurrent.eOn, 'selected');
				Common.Class.add(oPhoto.oContent.oCurrent.eContent, 'hidden');
				this.eContent.style.opacity = 0;
				this.eContent.style.filter = 'alpha(opacity=0)';
				Common.Class.remove(this.eContent, 'hidden');
				oPhoto.oContent.set_current(this);
				Common.Class.add(this.eOn, 'selected');
				//oPhoto.oContent.show_pager(oPhoto.oContent.oCoords);
				this.resize();
			}else if(this.iStep >= this.iHalf_step){
				var iOpacity = (this.iStep - this.iHalf_step) / this.iHalf_step;
				this.eContent.style.opacity = iOpacity;
				this.eContent.style.filter = '';
			}
			var oThis = this;
			setTimeout(function(){oThis.animation();}, 0);
		}
	},

	resize: function(){
		if(this.eImage.offsetHeight < 30){
			var oThis = this;
			setTimeout(function(){oThis.resize();}, 200);
		}else{
			oPhoto.oContent.resize();
			//oPhoto.oContent.show_pager(oPhoto.oContent.oCoords);
		}
	},

	onload: function(){
		this.eContent.innerHTML = '<p class="description">' +
					this.sDescription +
				'</p>' +
				'<p class="download"><a href="' + this.eOn.getElementsByTagName('a')[0].href + '">Большая картинка</a><br/>' + this.sDownload + '</p>' +
				'<div class="reducer">' +
					'<img src="' + this.eOn.getElementsByTagName('a')[0].href + '"/>' + 
					//'<i class="arrow prev"></i>' +
					//'<i class="arrow next"></i>' +
				'</div>';
		this.bLoaded = true;
		this.init();
		this.select();
	},

	init: function(){
		this.eReducer = Common.Dom.getElementsByClassName(this.eContent, 'reducer')[0];
		this.eImage = this.eReducer.getElementsByTagName('img')[0];
		/*if(this.eImage.runtimeStyle){
			Common.Dom.setStyle(
				this.eImage,
				'z-index: 2; filter: alpha(opacity=0);'
			);
			var eImage = document.createElement('div');
			Common.Dom.setStyle(
				eImage,
				'position: absolute; z-index: 1; top: 0; left: 0; width: 100%; height: 1px;'
			);
			this.eReducer.appendChild(eImage);
			this.eImage_ghost = document.createElement('span');
			eImage.appendChild(this.eImage_ghost);
			Common.Dom.setStyle(
				this.eImage_ghost,
				'position: absolute; z-index: 1; ' +
						'width: ' + this.eImage.offsetWidth + 'px; ' +
						'height: ' + this.eImage.offsetHeight + 'px; ' +
						'filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + this.eImage.src + '", sizingMethod="scale")'
			);
		}*/
		/*var aeA = this.eReducer.getElementsByTagName('i'),
			oPager;
		for(var i = 0; i < aeA.length; i++){
			if (Common.Class.match(aeA[i], 'next')) {
				oPager = new oPhoto.oContent.Pager({eOn: aeA[i], iNum: this.iNum + 1});
				this.oNext = oPager
			} else if (Common.Class.match(aeA[i], 'prev')) {
				oPager = new oPhoto.oContent.Pager({eOn: aeA[i], iNum: this.iNum - 1});
				this.oPrev = oPager;
			}
		}*/
	}
};


oPhoto.oContent.Pager = function(oParams){
	this.eOn = oParams.eOn;
	this.iNum = oParams.iNum;
	oParams.eOn.innerHTML = '<ins></ins>';
	this.eMove = oParams.eOn.firstChild;
	var iWidth = this.eMove.offsetWidth;
	if(iWidth){
		oPhoto.oContent.iPager_width = iWidth;
		oPhoto.oContent.iPager_half_width = iWidth / 2;
	}
	Common.Dom.setStyle(this.eMove, 'display: none;');
	var oThis = this;
	Common.Event.add(oParams.eOn, 'click', function(oEvent){
		oThis.click();
		Common.Event.cancel(oEvent);
	});
};

oPhoto.oContent.Pager.prototype = {
	show: function(){
		this.eMove.style.display = 'block';
		this.eMove.style.left = this.iLeft + 'px';
		this.iPosition = 0;
		this.iDX = 0;
	},

	hide: function(iDX){
		if(!iDX){
			this.iDX = 0;
			this.eMove.style.display = 'none'
		}else if(!this.iDX){
			this.iDX = iDX;
			this.iPosition = oPhoto.oContent.iPager_half_width;
			if(this.iLeft || this.iLeft == 0){
				this.hiding();
			}
		}
	},

	hiding: function(){
		if(this.iPosition){
			this.iPosition--;
			this.iLeft += 2* this.iDX;
			this.eMove.style.left = this.iLeft + 'px';
			var oThis = this;
			setTimeout(function(){oThis.hiding();}, 0);
		}else if(this.iDX){
			this.iDX = 0;
			this.hide(0);
		}
	},

	click: function(){
		if (oPhoto.oContent.hPage[this.iNum]) {
			oPhoto.oContent.hPage[this.iNum].show();
		}
	}
};


oPhoto.Scroll = {
	iScroll_button_step: 10,
	timer: 0,
	create: function(oParams) {
		var iMouseX = 0;
		var iHandleX = 0;
		var bIs_drag = false;

		this.eVisible_area = oParams.eNavigation;
		this.eContent = Common.Dom.getElementsByClassName(this.eVisible_area, 'content')[0];
		this.eSlider = document.getElementById('scroll');
		this.eGetter = Common.Dom.getElementsByClassName(this.eSlider, 'getter')[0];
		this.eHandle = Common.Dom.getElementsByClassName(this.eSlider, 'handler')[0];
		this.iCurrent_position = 0;
		this.iMax_displacement = 0;

		this.iButton_width = Common.Dom.getElementsByClassName(this.eSlider, 'button')[0].offsetWidth;
		this.scroll_bar_recalculate();
		this.get_selected_photo();

		this.eGetter.unselectable = "on";

		this.slider();

		var oThis = this;
		Common.Event.add(window, 'resize', function(){
			oThis.scroll_bar_recalculate();
			oThis.content_position_recalculate();
		});
		Common.Class.add(this.eVisible_area, 'inited');
		this.content_position_recalculate();
	},

	buttons: function(oEvent) {
		if(oEvent.clientX > (this.eVisible_area.offsetLeft + this.iCurrent_position + this.eHandle.offsetWidth + this.iButton_width * 2)) {
			this.iNew_position = oEvent.clientX - this.iButton_width * 2 - this.eHandle.offsetWidth / 2;
		}else if(oEvent.clientX < (this.eVisible_area.offsetLeft + this.iCurrent_position)) {
			this.iNew_position = oEvent.clientX - this.iButton_width * 2 - this.eHandle.offsetWidth / 2;
		}else{
			this.start_drag(oEvent);
		}
		if(this.iNew_position < 0 ) {
			this.iNew_position = 0;
		}else if(this.iNew_position > this.iMax_displacement){
			this.iNew_position = this.iMax_displacement;
		}
		this.start_content_scrolling();
	},

	start_content_scrolling: function(){
		this.iSteps = 30;
		this.iStep = 0;
		this.iOld_position = this.iCurrent_position;
		this.iDX = (this.iNew_position - this.iCurrent_position) / this.iSteps;
		this.content_scrolling_animation();
	},

	content_scrolling_animation: function(){
		if(!this.bIs_drag && this.iStep < this.iSteps){
			this.iStep++;
			this.iCurrent_position = this.iOld_position + this.iDX * Math.sqrt(this.iSteps * this.iSteps - (this.iSteps - this.iStep) * (this.iSteps - this.iStep));
			this.content_scrolling();
			var oThis = this;
			setTimeout(function(){oThis.content_scrolling_animation();}, 10);
		}
	},

	content_scrolling: function() {
		this.scroll_bar_recalculate();
		this.eContent.style.left = - this.iCurrent_position * this.correction_calculate() + 'px';
	},

	correction_calculate: function() {
		return this.eContent.offsetWidth / (this.eVisible_area.offsetWidth - 2 * this.iButton_width);
	},

	scroll_bar_recalculate: function() {
		if(this.eVisible_area.offsetWidth >= this.eContent.offsetWidth) {
			var aeButton = Common.Dom.getElementsByClassName(this.eSlider, 'button');
			for(var i=0; i < aeButton.lenght; i++){
				aeButton[i].style.visibility = 'hidden';
			}
			this.eSlider.style.display = 'none';
			this.eHandle.style.width = '100px';
		}
		else {
			var iCorrection = this.correction_calculate();
			this.eSlider.style.display = 'block';
			this.iSlider_width = this.eVisible_area.offsetWidth - 2 * this.iButton_width;
			this.iHandle_width = this.eVisible_area.offsetWidth * this.iSlider_width / this.eContent.offsetWidth;
			this.eHandle.style.width = this.iHandle_width + 'px';
			this.iMax_displacement = (this.eContent.offsetWidth - this.eVisible_area.offsetWidth) / iCorrection;
			if(this.iCurrent_position > this.iMax_displacement) {
				this.iCurrent_position = this.iMax_displacement;
			}
			else if(!this.iCurrent_position || this.iCurrent_position < 0) {
				this.iCurrent_position = 0;
			}
			this.eHandle.style.left = this.iCurrent_position + 'px';
		}
	},

	content_position_recalculate: function() {
		var iVisible_area_width = this.eVisible_area.offsetWidth;
		var iContent_width = this.eContent.offsetWidth;
		if(iContent_width <= iVisible_area_width) {
			this.eContent.style.left = 0;
		}
		else if(iVisible_area_width > (iContent_width - iVisible_area_width + this.eContent.offsetLeft)) {
			var iCorrection = this.correction_calculate();
			this.eContent.style.left = - this.iCurrent_position * iCorrection + 'px';
		}
	},

	get_selected_photo: function() {
		var eSelected_photo = Common.Dom.getElementsByClassName(this.eContent, 'selected')[0];
		eSelected_photo = eSelected_photo || this.eContent.getElementsByTagName('a')[0];
		var iLeft_position = eSelected_photo.offsetLeft + eSelected_photo.offsetWidth/2;
		var iVisible_area_width = this.eVisible_area.offsetWidth;
		if(iVisible_area_width/2 < iLeft_position) {
			var iCorrection = this.correction_calculate();
			this.iCurrent_position = (iLeft_position - iVisible_area_width/2) / iCorrection;
			if(this.iCurrent_position > this.iMax_displacement) {
				this.iCurrent_position = this.iMax_displacement;
 			}
		}
		else if(iVisible_area_width/2 > (this.eContent.offsetWidth - iLeft_position)) {
			this.iCurrent_position = this.iMax_displacement;
		}

		this.content_scrolling();
		this.content_position_recalculate();
		this.scroll_bar_recalculate();
	},

	slider: function() {
		var oThis = this;
		Common.Event.add(document, 'mousemove', function(oEvent){
			oThis.drag_handle(oEvent);
		});
		Common.Event.add(document, 'mouseup', function(oEvent){
			oThis.stop_drag(oEvent);
		});
		Common.Event.add(oThis.eGetter, 'mousedown', function(oEvent){
			oThis.buttons(oEvent);
			Common.Event.cancel(oEvent);
		});
	},

	start_drag: function(oEvent) {
		iMouseX = oEvent.clientX;
		iHandleX = this.eHandle.offsetLeft - this.iButton_width;
		this.bIs_drag = true;
	},

	drag_handle: function(oEvent) {
		if(this.bIs_drag) {
			if(oEvent.clientX < 2 || oEvent.clientX > document.body.offsetWidth) {
				this.stop_drag();
			}
			var iDX = oEvent.clientX - iMouseX;
			this.iCurrent_position = iHandleX + iDX;
			if (this.iCurrent_position < 0) {
				this.iCurrent_position = 0;
			}
			else if (this.iCurrent_position > this.iMax_displacement) {
				this.iCurrent_position = this.iMax_displacement;
			}
			this.scroll_bar_recalculate();
			this.content_scrolling();
		}
	},

	stop_drag: function(oEvent) {
		this.bIs_drag = false;
	}
};