extend(BottomInterface, createjs.Container);

function BottomInterface(viewmod)
{	
	this.initialize();
	var th = this
//--------------------------------//
	var podl = new createjs.Sprite(jsons["JSON1"])
	podl.gotoAndStop("area_bonus")
	setCoor(podl, 9, 596)
	// dragAndDrop(podl)

	var deck1 = new Button({pod:"btn_2", i:"icon_ship1", iconX: 17, iconY: 12, iconScale: 1, txt: "0", font: "numbers_red_small_", txtX:100, txtY: 105})
	setCoor(deck1, 38, 568)
	deck1.addEventListener("click", function(){ viewmod.clickOnShip(1)})

	var deck2 = new Button({pod:"btn_2", i:"icon_ship2", iconX: 15, iconY: 15, iconScale: 1, txt: "0", font: "numbers_red_small_", txtX:100, txtY: 105})
	setCoor(deck2, 181, 568)
	deck2.addEventListener("click", function(){ viewmod.clickOnShip(2)})

	var deck3 = new Button({pod:"btn_2", i:"icon_ship3", iconX: 17, iconY: 15, iconScale: 1, txt: "0", font: "numbers_red_small_", txtX:100, txtY: 105})
	setCoor(deck3, 327, 568)
	deck3.addEventListener("click", function(){ viewmod.clickOnShip(3)})

	var mine = new Button({pod:"btn_2"})
	var mine1 = new Button({i:"icon_mine", iconX: 16, iconY: 14, iconScale: 1, txt: "0", font: "numbers_red_small_", txtX:100, txtY: 105}, 1)
	setCoor(mine1, 467, 568)
	setCoor(mine, 467, 568)
	mine.addEventListener("click", function(){ viewmod.clickOnMine()})

	// dragAndDrop(deck1)
	// dragAndDrop(deck2)
	// dragAndDrop(deck3)
	// dragAndDrop(mine)
// Second step
	var scale = 1
	var target = new Button({pod:"btn_2", i:"icon_attack1", i2:"icon_attack2", iconX: 21, iconY: 19, iconScale: 1, txt: "0", font: "numbers_red_small_", txtX:100, txtY: 105})
	setCoor(target, 5 * scale, 568)
	target.addEventListener("click", function(){ viewmod.clickOnTarget()})
	target.setText(-1)

	var multiBomb = new Button({pod:"btn_2", i:"3-2", i2:"3-1", iconX: 25, iconY: 36, iconScale: 1, txt: "0", font: "numbers_red_small_", txtX:100, txtY: 105})
	setCoor(multiBomb, 181, 568)
	multiBomb.addEventListener("click", function(){ viewmod.clickOnBonus("dinamite")})

	var dinamite = new Button({pod:"btn_2", i:"1-2", i2:"1-1", iconX: 31, iconY: 32, iconScale: 1, txt: "0", font: "numbers_red_small_", txtX:100, txtY: 105})
	setCoor(dinamite, 327, 568)
	dinamite.addEventListener("click", function(){ viewmod.clickOnBonus("bomb")})

	var periskope = new Button({pod:"btn_2", i:"2-2", i2:"2-1", iconX: 31, iconY: 39, iconScale: 1, txt: "0", font: "numbers_red_small_", txtX:100, txtY: 105})
	setCoor(periskope, 467, 568)
	periskope.addEventListener("click", function(){ viewmod.clickOnBonus("periskop")})

	var torpedo = new Button({pod:"btn_2", i:"4-2", i2:"4-1", iconX: 28, iconY: 34, iconScale: 1, txt: "0", font: "numbers_red_small_", txtX:100, txtY: 105})
	setCoor(torpedo, 38, 568)
	torpedo.addEventListener("click", function(){ viewmod.clickOnBonus("torpedo")})

	// dragAndDrop(multiBomb)
	// dragAndDrop(dinamite)
	// dragAndDrop(periskope)
	// dragAndDrop(torpedo)
	// dragAndDrop(target)

	target.scaleX = target.scaleY = scale
	multiBomb.scaleX = multiBomb.scaleY = scale
	dinamite.scaleX = dinamite.scaleY = scale
	periskope.scaleX = periskope.scaleY = scale
	torpedo.scaleX = torpedo.scaleY = scale

	viewmod.registerObservers(th)

// 	Обновление
	this.updateBottomIface = function(){
		var step = viewmod.getData()
		setStep(step.cur_step)
	}

// Private //
	function setStep(v) {
		th.removeAllChildren()
		var p = viewmod.getData()
		if(v == 1){
			th.addChild(podl);
			th.addChild(deck1);
			th.addChild(deck2);
			th.addChild(deck3);
			th.addChild(mine);
			th.addChild(mine1);
			deck1.mouseEnabled = true
			deck2.mouseEnabled = true
			deck3.mouseEnabled = true
			mine.mouseEnabled = true
			if(p.game_data.num_deck1 > 0)
				deck1.setText(p.game_data.num_deck1)
			else{
				deck1.mouseEnabled = false
				deck1.changeFrame("off", true)
				deck1.setText(-1)
			}
			if(p.game_data.num_deck2 > 0)
				deck2.setText(p.game_data.num_deck2)
			else{
				deck2.mouseEnabled = false
				deck2.changeFrame("off", true)
				deck2.setText(-1)
			}
			if(p.game_data.num_deck3 > 0)
				deck3.setText(p.game_data.num_deck3)
			else{
				deck3.mouseEnabled = false
				deck3.changeFrame("off", true)
				deck3.setText(-1)
			}
			if(p.game_data.num_mine > 0)
				mine1.setText(p.game_data.num_mine)
			else{
				mine.mouseEnabled = false
				mine.changeFrame("off", true)
				mine1.changeFrame("off", true)
				mine1.setText(-1)
			}
		}
		if(v == 2){
			th.addChild(podl);
			th.addChild(target);
			th.addChild(multiBomb);
			th.addChild(dinamite);
			th.addChild(periskope);
			th.addChild(torpedo);
			target.mouseEnabled = true
			target.visible = false
			multiBomb.mouseEnabled = true
			dinamite.mouseEnabled = true
			periskope.mouseEnabled = true
			torpedo.mouseEnabled = true
			if(p.game_data.dinamite_num_user > 0){
				multiBomb.setText(p.game_data.dinamite_num_user)
				multiBomb.changeFrame("on", true)
			}else{
				multiBomb.mouseEnabled = false
				multiBomb.changeFrame("off", true)
				multiBomb.setText(-1)
			}
			if(p.game_data.multibomb_num_user > 0){
				dinamite.setText(p.game_data.multibomb_num_user)
				dinamite.changeFrame("on", true)
			}else{
				dinamite.mouseEnabled = false
				dinamite.changeFrame("off", true)
				dinamite.setText(-1)
			}
			if(p.game_data.periskope_num_user > 0){
				periskope.setText(p.game_data.periskope_num_user)
				periskope.changeFrame("on", true)
			}else{
				periskope.mouseEnabled = false
				periskope.changeFrame("off", true)
				periskope.setText(-1)
			}
			if(p.game_data.torpedo_num_user > 0){
				torpedo.setText(p.game_data.torpedo_num_user)
				torpedo.changeFrame("on", true)
			}else{
				torpedo.mouseEnabled = false
				torpedo.changeFrame("off", true)
				torpedo.setText(-1)
			}

			if(searcInMas(p.game_data.selected_objects, "dinamite"))
				multiBomb.setIcon(2)
			else
				multiBomb.setIcon(1)
			if(searcInMas(p.game_data.selected_objects, "bomb"))
				dinamite.setIcon(2)
			else
				dinamite.setIcon(1)
			if(searcInMas(p.game_data.selected_objects, "periskop"))
				periskope.setIcon(2)
			else
				periskope.setIcon(1)
			if(searcInMas(p.game_data.selected_objects, "torpedo"))
				torpedo.setIcon(2)
			else
				torpedo.setIcon(1)
			
			if(searcInMas(p.game_data.selected_objects, "anim-target"))
				target.setIcon(2)
			else
				target.setIcon(1)
							
		}
	}

	function searcInMas(m, name){
		for(var i=0; i<m.length; i++){
			if(m[i].getName() == name)
				return true
		}

	}
};