extend(Mine, createjs.Container);

function Mine(_sh, name, num)
{	
	this.initialize();
	var _direct = "goriz"
	var th = this
	var nu = num ? "_" + num : ""
//--------------------------------//
	var cur_start_X = field_params.startX_mine
	var cur_start_Y = field_params.startY_mine
	var listeners = new Array()

	var start_time = 0
	var _parent, _viewmod, interval
	var _mine = new createjs.Sprite(jsons["JSON1"])
	var cells = new Array()

	if(name)
		_mine.gotoAndStop(name + nu)
	this.mouseChildren = false

	if(name)
		this.addChild(_mine)

	// var anch = new createjs.Shape()
	// anch.graphics.beginFill("#000000").drawCircle(0, 0, 10)
	// this.addChild(anch)
	// dragAndDrop(this)

	init()
	this.setGraphics = function(json, name, anim, x, y){
		var _mine = new createjs.Sprite(json)
		if(!anim)
			_mine.gotoAndStop(name)
		else
			_mine.gotoAndPlay(name)
		if(typeof(x) == "number" && typeof(y) == "number")
			setCoor(_mine, x, y)
		this.addChild(_mine)
	}

	this.clearGraphics = function(){
		this.removeAllChildren()
	}

	this.setStartCoor = function(x, y){
		cur_start_X = x
		cur_start_Y = y
	}

	this.changeDir = function(){
		_direct = _direct == "goriz" ? "vert" : "goriz"
	}

	this.getDirect = function(){
		return _direct
	}
//
	this.setAlpha = function(v){
		
	}
// Установка корабля в ячейку(i, j)
	this.setToCell = function(i, j){
		setCoor(this, cur_start_X * __koefDisplay + (field_params.dx * __koefDisplay * j) + (field_params.dx * __koefDisplay * i), cur_start_Y * __koefDisplay + (-field_params.dy * __koefDisplay * j) + (field_params.dy * __koefDisplay * i))
	}
// Установка родителя и viewmodel
	this.setParent = function(parent, viewmod){
		_parent = parent
		_viewmod = viewmod
	}
// Вынужденный интерфейс SeaObjects (HERNIK)
	this.moveUp = function(e){
						if(start_time > 1){
								var cur_cell = {i: 0, j: 0}
								var min = distXY(th.x, th.y, cur_start_X + (field_params.dx * 0) + (field_params.dx * 0), cur_start_Y + (-field_params.dy * 0) + (field_params.dy * 0))
								for(var a=0; a<_viewmod.getDimension(); a++)
									for(var b=0; b<_viewmod.getDimension(); b++){
										var m = distXY(th.x, th.y, cur_start_X + (field_params.dx * b) + (field_params.dx * a), cur_start_Y + (-field_params.dy * b) + (field_params.dy * a))
										if(m < min){
											min = m
											cur_cell = {i: a, j: b}
										}
									}
								_viewmod.setToCell(_sh, cur_cell.i, cur_cell.j)
							}else{
								_viewmod.rotateShip(_sh, "goriz")
							}
							_parent.addDragAndDrop()
							}

	this.moveDown = function(){
						_parent.removeDragAndDrop()
						th.parent.addChild(th)
						t_delInTicker(interval)
						start_time = 0
						var ca = function(){
							start_time++
							interval = t_delayOn(.1, ca)
						}
						ca()
					}
	this.movePress = function(){
						th.parent.addChild(th)						
					}

	dragAndDrop(th, th.moveUp, th.moveDown, th.movePress)
	this.getCheck = function(){
		return true
	}

	this.setCell = function(i, j){
		cells.push({i: i, j: j})
	}

	this.setListener = function(a, b, c){
		th.removeAllEventListeners()
		if(a)
			listeners.push(a)
		if(b)
			listeners.push(b)
		if(c)
			listeners.push(c)

		dragAndDrop(th, th.moveUp, th.moveDown, th.movePress, listeners)
	}

	this.getTakes = function(v){
		var shift = _sh.getTakes()[0]
		var ret = new Array()
		for(var a=0; a< cells.length; a++)
			ret.push({i:cells[a].i + shift.i, j:cells[a].j + shift.j})

		if(v)
			return _sh.getTakes()
		else{
			return ret
		}
	}

	this.getName = function(){
		return _sh.getName()
	}

	this.getVisual = function(){
		return this
	}

	this.setMouseEnabled = function(v){
		if(name == "part_ship" || name == "rock" || name == "debris" || name == "empty" || name == "chest" || (name == "mine" && shots))
			return
		else
			this.mouseEnabled = v
	}

// PRIVATE //

	function init(){
		th.regX = 19/__koefDisplay
		th.regY = 46/__koefDisplay
	}

}