<div class="tower tower-level<?php echo $level; ?>">
  <div class="tower-background tower_scene_sky"></div>
  <div class="tower-background tower_scene_clouds"></div>
  <div class="tower-background tower_scene_bg"></div>
  
  <div class="tower-row">
    <div class="tower-row-item tower-row-item-left">
      <div class="tower-modal <?php echo (!empty($TOWER_NOTIFICATION) ? 'tower-modal-open' : ''); ?>" id="towerModal" data-this="">
        <div class="tower-modal-content <?php echo (!empty($TOWER_NOTIFICATION_CLASS) ? $TOWER_NOTIFICATION_CLASS : ''); ?>" id="notification"<?php echo (!empty($TOWER_NOTIFICATION) ? ' style="display: block;"' : ''); ?>>
          <?php echo (!empty($TOWER_NOTIFICATION) ? $TOWER_NOTIFICATION : ''); ?>
        </div>
        <div class="tower-modal-content towerBomb" id="towerBomb">
          <?php if ($userTower['bomb'] == 0) { ?>
            <div class="tower-modal-title" style="font-weight: normal;">You dont have bombs!</div>
          <?php } ?>
          <div class="tower-modal-title" style="font-weight: normal; padding: 10px;">Bombs are needed to crush other peoples towers and get prizes.</div>
          <div class="tower-box"><img src="components/img/bomb.png" /><span class="<?php echo ($userTower['bomb'] == 0 ? 'bg-gray' : ''); ?>"><?php echo $userTower['bomb']; ?></span></div>
          <?php if ($user['id'] == $uid) { ?>
            <a class="tower-link bg-red" href="?act=search">Search Towers</a>
          <?php } ?>
          <?php if ($user['id'] != $uid && $userTower['bomb'] > 0 && $userTower['height'] >= 10) { ?>
            <a class="tower-link <?php echo ($tower['height'] < 10 ? 'bg-gray' : 'bg-green'); ?>" href="?act=fire&amp;uid=<?php echo $uid; ?>">Make a shot</a>
          <?php } elseif ($user['id'] != $uid && $userTower['height'] < 10) { ?>
            <div class="tower-modal-title" style="font-weight: normal; padding: 10px;">Your tower is less than 10 meters, you can not demolish other peoples towers.</div>
          <?php } ?>
          <div class="tower-modal-title" style="font-weight: normal; padding: 10px;">You can get bombs in the box builder.</div>
        </div>
        <div class="tower-modal-content towerPay" id="towerPay">
         From your account will be charged <?php echo des2num($TOWER_PRICE, $TOWER_COINS_NAME); ?> Are you sure?
          
          <div class="tower-modal-button">
            <a href="?act=box">Yes</a>
            <a onclick="towerModalClose()">No</a>
          </div>
        </div>
        <div class="tower-modal-content towerInfo" id="towerInfo">
          <div>
            You build a tower and get points for it. <?php echo $TOWER_USER_RATING_NAME; ?>. 
            Tower height is not limited.
             The higher the tower, the more extra points <?php echo $TOWER_USER_RATING_NAME; ?> You wll get.
          </div>
          <div>
            Every <?php echo getTowerShieldTime($TOWER_FREE_TIME); ?> All users can open the Builders Box and get 3 random stones for construction for free.
            If you do not want to wait <?php echo getTowerShieldTime($TOWER_FREE_TIME); ?>, The builders box can be opened for a fee.
             In total, the Tower has 16 types of stones, they have a different shape and fit only on suitable stones. 
          </div>
          <div>
            With the help of bombs, you can demolish other Towers (fully or partially) and get prizes for it.. 
            You can bomb towers that have reached a height of 10 meters.
             In the event of the destruction of your tower, you lose points <?php echo $TOWER_USER_RATING_NAME; ?> for the destroyed site.
             Your main rating, which is not obtained from the Tower, will not be affected.
          </div>
          <div>
            How to protect the tower: 100% protection keeps <?php echo getTowerShieldTime($TOWER_TIME_SHIED_FULL); ?>, 
            then starts to fall every <?php echo getTowerShieldTime($TOWER_TIME_SHIED); ?> by 10% until it reaches zero.
             During this period, the tower may be attacked and may be damaged.
            You can recover 100% protection on <?php echo getTowerShieldTime($TOWER_TIME_SHIED_FULL); ?>, putting 1 stone on the tower.
             While the tower is under 100% protection, newly laid stones increase your rating,
             but do not extend the protection time.
          </div>
          <div>
            If the tower is still damaged, it will be under 100% protection. <?php echo getTowerShieldTime($TOWER_TIME_SHIED_FULL); ?>, 
            then the defense will start to fall.
             You will have the opportunity to restore the destroyed part of the tower and
             glasses <?php echo $TOWER_USER_RATING_NAME; ?> at extra charge.
          </div>
        </div>
        <div class="tower-modal-content towerLosBack" id="towerLosBack">
          From your account will be charged <?php echo des2num($_TOWER_HEIGHT_COST[array_search($tower['los'], $_TOWER_HEIGHT_LOSE)], $TOWER_COINS_NAME); ?> Are you sure?
          
          <div class="tower-modal-button">
            <a href="?act=los">Yes</a>
            <a onclick="towerModalClose()">No</a>
          </div>
        </div>
        <div class="tower-modal-content towerNoMoney" id="towerNoMoney">
          You do not have enough money. On your account <?php echo des2num($user[$TOWER_PRICE_TABLE], $TOWER_COINS_NAME); ?>
          <div class="tower-modal-button">
            <a href="<?php echo $TOWER_URL_BILLING; ?>">Top up account</a>
          </div>
        </div>
        
        <?php 
        foreach($TOWER_GIFT AS $key => $value) { 
            echo '<div class="tower-modal-content towerGift" id="GFT' . $key . '"><img src="' . $value['img_big'] . '"><div>' . $value['name'] . '</div></div>'; 
        } 
        ?>
        
        <div class="tower-modal-content towerBlocks" id="towerBlocks">
          <?php 
          $blocks = getTowerBlocks($uid, $tower['color']); 
          
          if (!empty($blocks)) {
              echo '<div class="tower-modal-title">Suitable stones</div>';
              if (!empty($blocks['there'])) {
                  foreach($blocks['there'] AS $key => $value) {
                      echo '<a href="?act=build&key=' . $key . '"><img src="components/img/blocks/' . $key . '.png" /><span>' . $value . '</span></a>';
                  }
              }
              
              else {
                  echo '<div class="tower-modal-title" style="font-weight: normal; padding: 10px;">Stones suitable for the continuation of construction, no.</div>';
              }
              
              if (!empty($blocks['other'])) {
                  echo '<div class="tower-modal-title">Remaining stones</div>';
                  foreach($blocks['other'] AS $key => $value) {
                      echo '<div><img src="components/img/blocks/' . $key . '.png" /><span>' . $value . '</span></div>';
                  }              
              }              
          }
          
          else {
              echo '<div class="tower-modal-title" style="font-weight: normal; padding: 10px;">You do not have a single stone. You can get stones in the Builders Box or as a gift from other users.<br /><img src="components/img/chest@2x.png" /></div>';
          }
          ?>
        </div>
        <div class="tower-modal-close">
          <a onclick="towerModalClose()">Close</a>
        </div>
      </div>
      
      <div class="tower-top tower-top-<?php echo $top; ?>">
        <img src="components/img/top_<?php echo $top; ?>@2x.png" />
        <div class="tower-top-info">
          <?php echo $tower['height']; ?>M
          <?php echo ($tower['step'] > 0 ? '<span class="tower-fraction tower-fraction-' . $tower['step'] . '"></span>' : ''); ?>
          <div class="tower-top-star-<?php echo $level; ?>"><?php echo star2galaxy($tower['height'] * 5); ?></div>
        </div>
      </div>
      
      <div class="tower-action tower-action-<?php echo $topAction; ?>">
        <div class="tower-bg-opacity"></div>
        
        <div>
        <?php if ($user['id'] == $uid) { ?>
          <a class="tower-link <?php echo (empty($blocks['there']) ? 'bg-gray' : 'bg-green'); ?>" onclick="towerModalOpen('towerBlocks', '1')">Build</a>
          <?php if ($tower['los']) { ?>   
          <a class="tower-link bg-white" onclick="towerModalOpen('<?php echo ($user[$TOWER_PRICE_TABLE] >= $_TOWER_HEIGHT_COST[array_search($tower['los'], $_TOWER_HEIGHT_LOSE)] ? 'towerLosBack' : 'towerNoMoney'); ?>', '1')">Restore<br /><?php echo $tower['los']; ?>M / <?php echo des2num($_TOWER_HEIGHT_COST[array_search($tower['los'], $_TOWER_HEIGHT_LOSE)], $TOWER_COINS_NAME); ?></a>
          <?php } ?>
        <?php } else { ?>
          <a class="tower-link <?php echo (!$userTower['bomb'] || $tower['height'] < 10 || $userTower['height'] < 10 ? 'bg-gray' : 'bg-green'); ?>" onclick="towerModalOpen('towerBomb', '1')">Bomb</a>
        <?php } ?>
        </div>
        
        <?php if ($tower['height'] >= 10) { ?>
          <div class="tower-shield">
            Protection - <?php echo $tower['heart']; ?>%<br />
            <?php if ($shield > 0) { ?>
              Still <?php echo getTowerShieldTime($shield); ?>
            <?php } ?>
          </div>
        <?php } ?>
      </div>
      
      <div class="tower-z tower-z-<?php echo $height_end; ?>">
        <img src="components/img/tower_<?php echo $tower['color']; ?>_1@2x.png" />
      </div>
    </div><div class="tower-row-item tower-row-item-right">
    <?php if ($user['id'] == $uid) { ?>
      <a class="tower-btn tower-btn-blocks" onclick="towerModalOpen('towerBlocks', '1')"><img src="components/img/blocks_button@2x.png" /><span class="tower-btn-title">Stones</span><?php echo (!empty($count['blocks']) ? '<span class="tower-btn-count">' . $count['blocks'] . '</span>' : ''); ?></a>
    <?php } ?>
    
      <a class="tower-btn tower-btn-blocks" onclick="towerModalOpen('towerBomb', '1')"><img src="components/img/bombs_button@2x.png" /><span class="tower-btn-title">Bombs</span><?php echo (!empty($userTower['bomb']) ? '<span class="tower-btn-count">' . $userTower['bomb'] . '</span>' : ''); ?></a>
      
    <?php if ($user['id'] == $uid) { ?>  
      <a class="tower-btn tower-btn-blocks" <?php echo (!$box_is ? 'onclick="towerModalOpen(\'' . ($user[$TOWER_PRICE_TABLE] >= $TOWER_PRICE ? 'towerPay' : 'towerNoMoney') . '\')"' : 'href="?act=box"'); ?>><img src="components/img/chest_<?php echo ($box_is ? 2 : 1); ?>_button@2x.png" />
      <span class="tower-btn-title">
      <?php if (!$box_is) { ?>
        <i>IS FREE<br /><?php echo getTowerFreeTime($tower['lastfreebox']); ?></i>
      <?php } ?>
      Оpen<?php if (!$box_is) { ?><br /><?php echo des2num($TOWER_PRICE, $TOWER_COINS_NAME); } ?></span></a>
      
      <a class="tower-btn tower-btn-blocks" href="?act=rating"><img src="components/img/ratings_button@2x.png" /><span class="tower-btn-title">Best</span></a>
      
    <?php } else { ?>
      
      <a class="tower-btn tower-btn-blocks" href="?act=search"><img src="components/img/search_tower_button@2x.png" /><span class="tower-btn-title">Search<br />Towers</span></a>
      
      <?php if ($uid != $user['id']) { ?>
        <div class="tower-gift">
        <div class="tower-gift-title">
          PRIZES<br />BEHIND<br />DESTRUCTION
        </div>
        <?php 
        foreach($TOWER_GIFT AS $key => $value) { 
            echo '<div><a onclick="towerModalOpen(\'GFT' . $key . '\')"><img src="' . $value['img'] . '" /></a></div>'; 
        } 
        ?>
        </div>
      <?php } ?>
      <a class="tower-btn tower-btn-blocks" href="?"><img src="components/img/my_tower_button@2x.png" /><span class="tower-btn-title">Мy Tower</span></a>
    <?php } ?>
    
    <a style="margin-top: 30px;" class="tower-btn tower-btn-blocks" onclick="towerModalOpen('towerInfo')"><img style="width: 50px;" src="components/img/help_button@2x.png" /></a>
    </div>
  </div>
  <div class="tower-background tower_scene_front"></div>
</div>
<script>
function towerModalOpen(uid, close) {
    $('#towerModal').addClass('tower-modal-open'); 
    if (uid) {
        $('#towerModal').attr('data-this', uid);
        $('.tower-modal-content').css('display', 'none');
        $('#' + uid).css('display', 'block');
    }
}
function towerModalClose() {
    $('#towerModal').removeClass('tower-modal-open'); 
}
</script>
