// Use this for initialization
	void Start () {
		_instance = this;
		BuyLogic.InitMe = this;
		sh1_Put_on.onClick.AddListener (delegate {SoundScript.Instance.PlaySound(SoundTitle.btn_click_snd);ToggleUpgrade ("shu1");});
		sh1_Put_off.onClick.AddListener (delegate {SoundScript.Instance.PlaySound(SoundTitle.btn_click_snd);ToggleUpgrade ("shu1");});
		sh2_Put_on.onClick.AddListener (delegate {SoundScript.Instance.PlaySound(SoundTitle.btn_click_snd);ToggleUpgrade ("shu2");});
		sh2_Put_off.onClick.AddListener (delegate {SoundScript.Instance.PlaySound(SoundTitle.btn_click_snd);ToggleUpgrade ("shu2");});
		sh3_Put_on.onClick.AddListener (delegate {SoundScript.Instance.PlaySound(SoundTitle.btn_click_snd);ToggleUpgrade ("shu3");});
		sh3_Put_off.onClick.AddListener (delegate {SoundScript.Instance.PlaySound(SoundTitle.btn_click_snd);ToggleUpgrade ("shu3");});
		su1_Put_on.onClick.AddListener (delegate {SoundScript.Instance.PlaySound(SoundTitle.btn_click_snd);ToggleUpgrade ("suu1");});
		su1_Put_off.onClick.AddListener (delegate {SoundScript.Instance.PlaySound(SoundTitle.btn_click_snd);ToggleUpgrade ("suu1");});
		su2_Put_on.onClick.AddListener (delegate {SoundScript.Instance.PlaySound(SoundTitle.btn_click_snd);ToggleUpgrade ("suu2");});
		su2_Put_off.onClick.AddListener (delegate {SoundScript.Instance.PlaySound(SoundTitle.btn_click_snd);ToggleUpgrade ("suu2");});
		sh1_Buy.onClick.AddListener (BuyLogic.ShowBuyItem1);
		sh2_Buy.onClick.AddListener (BuyLogic.ShowBuyItem2);
		sh3_Buy.onClick.AddListener (BuyLogic.ShowBuyItem3);
		su1_Buy.onClick.AddListener (BuyLogic.ShowBuyItem4);
		su2_Buy.onClick.AddListener (BuyLogic.ShowBuyItem5);
		gold1_Buy.onClick.AddListener (BuyLogic.BuyGold1);
		gold2_Buy.onClick.AddListener (BuyLogic.BuyGold2);
		gold3_Buy.onClick.AddListener (BuyLogic.BuyGold3);

		gold1.FindChild ("Icon").GetComponent<Button> ().onClick.AddListener (ShowDescriptionGold);
		gold1.FindChild ("Description_txt").GetComponent<Button> ().onClick.AddListener (ShowDescriptionGold);
		gold2.FindChild ("Icon").GetComponent<Button> ().onClick.AddListener (ShowDescriptionGold);
		gold2.FindChild ("Description_txt").GetComponent<Button> ().onClick.AddListener (ShowDescriptionGold);
		gold3.FindChild ("Icon").GetComponent<Button> ().onClick.AddListener (ShowDescriptionGold);
		gold3.FindChild ("Description_txt").GetComponent<Button> ().onClick.AddListener (ShowDescriptionGold);

		transform.FindChild ("Buy_item").GetComponent<Button> ().onClick.AddListener (BuyLogic.HideBuyItem);
		transform.FindChild ("close_btn").GetComponent<Button> ().onClick.AddListener (MainScript.Instance.HideShopOverlay);
		transform.FindChild ("money_field").GetComponent<Button>().onClick.AddListener(() => {ToggleSide (ShopShopData.Gold);});
		PreviouslyAnimatedShit = ShopShopData.Ship;
		gameObject.SetActive (false);
	}
	IEnumerator PlayAnimations(ShopShopData animateSomeShit) {
		ToggleUpgradesVisibility (false, 1, PreviouslyAnimatedShit);
		yield return new WaitForSeconds (0.15f);
		ToggleUpgradesVisibility (false, 2, PreviouslyAnimatedShit);
		yield return new WaitForSeconds (0.15f);
		ToggleUpgradesVisibility (false, 3, PreviouslyAnimatedShit);
		yield return new WaitForSeconds (0.2f);

		ToggleUpgradesVisibility (true, 123, animateSomeShit);
		switch (animateSomeShit) {
		case ShopShopData.Gold:
			//gold1.GetComponent<Animation> ().Play ();
			gold1.FindChild("Icon").GetComponent<Animation> ().Play ();
			gold1_Buy.GetComponent<Animation> ().Play ();
			//gold2.GetComponent<Animation> ().Play ();
			gold2.FindChild("Icon").GetComponent<Animation> ().Play ();
			gold2_Buy.GetComponent<Animation> ().Play ();
			//gold3.GetComponent<Animation> ().Play ();
			gold3.FindChild("Icon").GetComponent<Animation> ().Play ();
			gold3_Buy.GetComponent<Animation> ().Play ();
			break;
		case ShopShopData.Ship:
			//sh1.GetComponent<Animation> ().Play ();

			sh1.FindChild("Icon").GetComponent<Animation> ().Play ();
			sh1.FindChild("Description_txt").GetComponent<Animation> ().Play ();
			if (sh1_Buy.gameObject.activeSelf)
				sh1_Buy.GetComponent<Animation> ().Play ();
			if (sh1_Put_off.gameObject.activeSelf)
				sh1_Put_off.GetComponent<Animation> ().Play ();
			if (sh1_Put_on.gameObject.activeSelf)
				sh1_Put_on.GetComponent<Animation> ().Play ();

			//sh2.GetComponent<Animation> ().Play ();
			sh2.FindChild("Icon").GetComponent<Animation> ().Play ();
			sh2.FindChild("Description_txt").GetComponent<Animation> ().Play ();
			if (sh2_Buy.gameObject.activeSelf)
				sh2_Buy.GetComponent<Animation> ().Play ();
			if (sh2_Put_off.gameObject.activeSelf)
				sh2_Put_off.GetComponent<Animation> ().Play ();
			if (sh2_Put_on.gameObject.activeSelf)
				sh2_Put_on.GetComponent<Animation> ().Play ();

			//sh3.GetComponent<Animation> ().Play ();
			sh3.FindChild("Icon").GetComponent<Animation> ().Play ();
			sh3.FindChild("Description_txt").GetComponent<Animation> ().Play ();
			if (sh3_Buy.gameObject.activeSelf)
				sh3_Buy.GetComponent<Animation> ().Play ();
			if (sh3_Put_off.gameObject.activeSelf)
				sh3_Put_off.GetComponent<Animation> ().Play ();
			if (sh3_Put_on.gameObject.activeSelf)
				sh3_Put_on.GetComponent<Animation> ().Play ();
			break;
		case ShopShopData.Submarine:
			//su1.GetComponent<Animation> ().Play ();
			su1.FindChild("Icon").GetComponent<Animation> ().Play ();
			su1.FindChild("Description_txt").GetComponent<Animation> ().Play ();
			if (su1_Buy.gameObject.activeSelf)
				su1_Buy.GetComponent<Animation> ().Play ();
			if (su1_Put_off.gameObject.activeSelf)
				su1_Put_off.GetComponent<Animation> ().Play ();
			if (su1_Put_on.gameObject.activeSelf)
				su1_Put_on.GetComponent<Animation> ().Play ();

			//su2.GetComponent<Animation> ().Play ();
			su2.FindChild("Icon").GetComponent<Animation> ().Play ();
			su2.FindChild("Description_txt").GetComponent<Animation> ().Play ();
			if (su2_Buy.gameObject.activeSelf)
				su2_Buy.GetComponent<Animation> ().Play ();
			if (su2_Put_off.gameObject.activeSelf)
				su2_Put_off.GetComponent<Animation> ().Play ();
			if (su2_Put_on.gameObject.activeSelf)
				su2_Put_on.GetComponent<Animation> ().Play ();

			break;
		default:
			break;
		}

		PreviouslyAnimatedShit = animateSomeShit;
	}
	void ToggleUpgradesVisibility(bool isVisible, byte i123, ShopShopData someShit){
		if (!gameObject.activeSelf)
			return;
		switch (someShit) {
		case ShopShopData.Gold:
			if (i123 == 1 || i123 == 123)
				gold1.gameObject.SetActive (isVisible);
			if (i123 == 2 || i123 == 123)
				gold2.gameObject.SetActive (isVisible);
			if (i123 == 3 || i123 == 123)
				gold3.gameObject.SetActive (isVisible);
			break;
		case ShopShopData.Ship:
			if (i123 == 1 || i123 == 123)
				sh1.gameObject.SetActive (isVisible);
			if (i123 == 2 || i123 == 123)
				sh2.gameObject.SetActive (isVisible);
			if (i123 == 3 || i123 == 123)
				sh3.gameObject.SetActive (isVisible);
			break;
		case ShopShopData.Submarine:
			if (i123 == 1 || i123 == 123)
				su1.gameObject.SetActive (isVisible);
			if (i123 == 2 || i123 == 123)
				su2.gameObject.SetActive (isVisible);
			break;
		default:
			break;
		}
	}
	public void ToggleSide(ShopShopData showSomeShit)
	{
//		sh1.gameObject.SetActive (showSomeShit == ShopShopData.Ship);
//		sh2.gameObject.SetActive (showSomeShit == ShopShopData.Ship);
//		sh3.gameObject.SetActive (showSomeShit == ShopShopData.Ship);
//		su1.gameObject.SetActive (showSomeShit == ShopShopData.Submarine);
//		su2.gameObject.SetActive (showSomeShit == ShopShopData.Submarine);
//		gold1.gameObject.SetActive (showSomeShit == ShopShopData.Gold);
//		gold2.gameObject.SetActive (showSomeShit == ShopShopData.Gold);
//		gold3.gameObject.SetActive (showSomeShit == ShopShopData.Gold);

		//PlayAnimations (showSomeShit);
		if (gameObject.activeInHierarchy)
			StartCoroutine(PlayAnimations(showSomeShit));
	}