function TweenerObjects()
{
	var th = this
//--------------------------------//
	var x_min = 270/__koefDisplay
	var x_max = 370/__koefDisplay
	var y_min = 430/__koefDisplay
	var y_max = 530/__koefDisplay
	
	this.tweenTo = function(o, pars, container, callback, bezier, dont_move, call_after_cont){
		var everyTick = function(){
			var global = container.localToGlobal(o.x * container.scaleX, o.y * container.scaleX)
			if(checkPointBelong(global.x, global.y)){
				// if(call_after_cont)
				// 	call_after_cont()
				// call()
				// console.log("stop")
				return
			}
			var diff = searchDiff(global.x, global.y)
			// console.log("move", container.scaleX)
			container.x += diff.x
			container.y += diff.y
		}
		var call = function(){
			// console.log("fly")
			if(!pars){
				if(callback)
					callback()
				// console.log("END")
				return
			}
			if(!dont_move)
				pars.everyTick = everyTick		
			if(bezier){
				var tw = new ClassBezier()
				tw.setObject(o)
				tw.setSpeed(.04)
				tw.setEveryTick(pars.everyTick)
				var mid_x = o.x + (pars.x - o.x)/2
				var mid_y = o.y + (pars.y - o.y)/2 - 300/__koefDisplay
				tw.set(o.x, o.y, mid_x, mid_y, pars.x, pars.y)
				var end = false
				var loop = function(){
					tw.Iter(function(){
						end = true
						if(o.parent)
							o.parent.removeChild(o)
						// console.log("END")
						if(pars.call)
							pars.call()
					})
					if(!end)
						t_delayOn(.001, loop)
				}
				loop()
			}else{
				tw_tweenTo(o, pars)
			}
		}
		if (!o)
			return;
		var global = container.localToGlobal(o.x, o.y)
		var diff = searchDiff(global.x, global.y)
		var dx = diff.x
		var dy = diff.y
		if(dont_move){
			if(call_after_cont)
				call_after_cont()
			call()
		}else{
			var sca = container.scaleX
			// tw_removeTween(container)
			tw_tweenTo(container, {x:container.x + dx, y:container.y + dy, d: .5, call: function(){
				if(call_after_cont)
					call_after_cont()
				call()
			},
			everyTick: function(){
				// console.log("everyTick")
				if(container.scaleX == sca)
					return
				tw_removeTween(container)
				sca = container.scaleX
				if(call_after_cont)
					call_after_cont()
				call()
			}
			})
		}

	}

// Проверка на попадание в экран
	function checkPointBelong(x, y, container){
		if(x>x_min && x<x_max && y>y_min && y<y_max)
			return true
	}

// Нахождение разницы по координатам (dx, dy)
	function searchDiff(x, y){
		var dx, dy
		if(checkPointBelong(x, y))
			return {x: 0, y: 0}

		if(x>x_min && x<x_max)
			dx = 0
		else
			if(distXY(x, y, x_min, y) > distXY(x, y, x_max, y))
				dx = x_max - x
			else
				dx = x_min - x

		if(y>y_min && y<y_max)
			dy = 0
		else
			if(distXY(x, y, x, y_min) > distXY(x, y, x, y_max))
				dy = y_max - y
			else
				dy = y_min - y

		return {x: dx, y: dy}
	}
}

__tweener = new TweenerObjects()