extend(Shop, createjs.Container);

function Shop()
{	
	this.initialize();
	var th = this
//--------------------------------//
	var logic;
	var items = new Array()
	var name_items = ["life", "bombs", "submarine", "torpedo", "air_strike"]
	var coor_items = [[73, 125], [345, 125], [14, 443], [217, 443], [423, 443]]
	var num_bonuses, listeners, listeners_pars

	var t = new createjs.Sprite(jsons["JSON2"]);
	t.gotoAndStop("window")
	t.x = WIDTHGAME/2 - t.getBounds().width/2
	t.y = HEIGHTGAME/2 - t.getBounds().height/2

	var title1 = new createjs.Sprite(jsons["JSON2"]);			/// Заголовок
	title1.gotoAndStop("text_red_shop");
	setCoor(title1, 140, 6)
	title1.x = WIDTHGAME/2 - title1.getBounds().width/2
	// title1.addEventListener("click", function(){window.open(__config.url, "_blank")})

	var pod_money = new createjs.Sprite(jsons["JSON1"])
	pod_money.gotoAndStop("area_money")
	setCoor(pod_money, -108, 115)
	var money = new Button({pod:"btn_money", i:"icon_money", iconX: -1, iconY: 1, txt: "0", font: "numbers_green_small_", txtX:99, txtY: 42, refTxt: "Left"})
	setCoor(money, 2-4, 104-20)

	var btn_back = new Arrow("left")
	setCoor(btn_back, 54, 19)
	btn_back.addEventListener("click", function(){
		v_choiseLocation("game", {dont_update: true, unPause: true});		
	})
	// dragAndDrop(btn_back)

	for(var a=0; a<5; a++){
		var i = new ItemShop(name_items[a])
		setCoor(i, coor_items[a][0], coor_items[a][1])
		i.setPrice(__config.price_bonuses[name_items[a]])
		// dragAndDrop(i)
		this.addChild(i)
		items.push(i)
	}

	var frame = new FloatFrame()
	frame.addToTopPlatform(title1)
	frame.addToTopPlatform(btn_back)
	frame.addToTopPlatform(pod_money)
	frame.addToTopPlatform(money)

	// this.addChild(t)
	// this.addChild(title1)
	// this.addChild(btn_back)
	// this.addChild(coins)
	// this.addChild(text_coins)
	this.addChild(frame)

	// dragAndDrop(btn_back)
	// dragAndDrop(title1)
	// dragAndDrop(coins)
	// dragAndDrop(text_coins)

	this.update = function(p){
		if(p && p.logic){
			logic = p.logic
			money.setText(p.logic.getData().user_money)
			pod_money.x = -133/__koefDisplay + p.logic.getData().user_money.toString().length*20/__koefDisplay
			num_bonuses = [logic.getData().life_user, logic.getData().game_data.dinamite_num_user, logic.getData().game_data.periskope_num_user, logic.getData().game_data.torpedo_num_user, logic.getData().game_data.multibomb_num_user]
			listeners = [logic.setLife, logic.setNumBonus, logic.setNumBonus, logic.setNumBonus]
			// listeners_pars = [["user", 1], ["user", "multibomb", 1], ["user", "periscope", 1], ["user", "torpedo", 1]]
			for(var a=0; a<items.length; a++){
				items[a].setNum(num_bonuses[a])
				items[a].removeAllEventListeners()
				items[a].addEventListener("click", function(e){
					// console.log(logic.getData().user_money, e.target.getPrice())
					if(logic.getData().user_money >= e.target.getPrice())
						if(e.target.getName() == name_items[0]){
							logic.setLife("user", 1)
							logic.setMoney("user", -e.target.getPrice())
						}else if(e.target.getName() == name_items[1]){
							logic.setNumBonus("user", "dinamite", 1)
							logic.setMoney("user", -e.target.getPrice())
						}else if(e.target.getName() == name_items[2]){
							logic.setNumBonus("user", "periscope", 1)
							logic.setMoney("user", -e.target.getPrice())
						}else if(e.target.getName() == name_items[3]){
							logic.setNumBonus("user", "torpedo", 1)
							logic.setMoney("user", -e.target.getPrice())
						}else if(e.target.getName() == name_items[4]){
							logic.setNumBonus("user", "multibomb", 1)
							logic.setMoney("user", -e.target.getPrice())
						}
					th.update(p)
					p.notify()
				})
			}
		}
	}
}