function updateAutoReviveCounter() {
  auto_revive_seconds -= 1;
  
  if (auto_revive_seconds <= -1) {
    if (auto_revive_min <= 0) {
      clearInterval(auto_revive_interval);
      hp = hp_max;
      $('hp').set('text',hp);
      $('auto-revive-subnote').setStyle('display','none');
      Animation($('hp-bar')).from('width', '0px').to('125px').go();
    } else {
      auto_revive_min -= 1;
      auto_revive_seconds = 59;
    }        
  }
  
  $('auto-revive-min').set('text',auto_revive_min);
  if(auto_revive_seconds >= 0 && auto_revive_seconds <= 9) {
    $('auto-revive-seconds').set('text','0' + auto_revive_seconds);
  } else {
    $('auto-revive-seconds').set('text',auto_revive_seconds);
  }
  
}

function updateEnergyCounter() {
  energy_refresh_seconds -= 1;
  
  if (energy_refresh_seconds <= -1) {
    if (energy_refresh_min <= 0) {
      energy += 1;
      energy_refresh_min = Math.floor((energy_refresh_rate - 1) / 60);
      energy_refresh_seconds = (energy_refresh_rate - 1) - (energy_refresh_min * 60);

      $('energy').set('text',energy);
      
      if (energy >= energy_max) {
        clearInterval(energy_refresh_interval);
        $('energy-refresh-subnote').setStyle('display','none');
      }
      
    } else {
      energy_refresh_min -= 1;
      energy_refresh_seconds = 59;
    }        
  }
  
  var energyRefreshMin = $('energy-refresh-min');
  if (energyRefreshMin != null) {
    energyRefreshMin.set('text',energy_refresh_min);    
    if (energy_refresh_seconds >= 0 && energy_refresh_seconds <= 9) {
      $('energy-refresh-seconds').set('text','0' + energy_refresh_seconds);
    } else {
      $('energy-refresh-seconds').set('text',energy_refresh_seconds);
    }
  }

  
}

function updateHpCounter() {
  hp_refresh_seconds -= 1;
  
  if (hp_refresh_seconds <= -1) {
    if (hp_refresh_min <= 0) {
      hp += hp_refresh_amount; // this needs to be done through ajax
      if (hp > hp_max) {
        hp = hp_max;
      }
      hp_refresh_min = Math.floor((hp_refresh_rate - 1) / 60);
      hp_refresh_seconds = (hp_refresh_rate - 1) - (hp_refresh_min * 60);
      
      Animation($('hp-bar')).from('width', (((hp - 1) / hp_max) * 125) + 'px').to((hp / hp_max) * 125).go();
      $('hp').set('text',hp);
            
      if (hp >= hp_max) {
        clearInterval(hp_refresh_interval);
        $('hp-refresh-timer-block').setStyle('display','none');
      }
      
    } else {
      hp_refresh_min -= 1;
      hp_refresh_seconds = 59;
    }        
  }
  
  $('hp-refresh-min').set('text',hp_refresh_min);
  if (hp_refresh_seconds >= 0 && hp_refresh_seconds <= 9) {
    $('hp-refresh-seconds').set('text','0' + hp_refresh_seconds);
  } else {
    $('hp-refresh-seconds').set('text',hp_refresh_seconds);
  } 
}

function updateMoneyCounter() {
  money_refresh_seconds -= 1;
  
  if (money_refresh_seconds <= -1) {
    if (money_refresh_min <= 0) {
      money += income; // this needs to be done through ajax
      money_refresh_min = Math.floor((money_refresh_rate - 1) / 60);
      money_refresh_seconds = (money_refresh_rate - 1) - (money_refresh_min * 60);
      
      if (money <= 0) {
        money = 0;
        clearInterval(money_refresh_interval);
        $('money-refresh-timer-container').setStyle('display','none'); // hide the "in 12:43" or whatever
      }
      
      $('money').set('text',money);
    } else {
      money_refresh_min -= 1;
      money_refresh_seconds = 59;
    }        
  }
  
  $('money-refresh-min').set('text',money_refresh_min);
  if (money_refresh_seconds >= 0 && money_refresh_seconds <= 9) {
    $('money-refresh-seconds').set('text','0' + money_refresh_seconds);
  } else {
    $('money-refresh-seconds').set('text',money_refresh_seconds);
  }
}


function updateEnergyPackCounter() {
  pack_refresh_seconds -= 1;
  
  if (pack_refresh_seconds <= -1) {
    pack_refresh_min -= 1;
    pack_refresh_seconds = 59;	
    if (pack_refresh_min <= -1) {
	    pack_refresh_min = 59;
	    pack_refresh_hour -= 1;
			
			if (pack_refresh_hour <= -1) {
        clearInterval(pack_refresh_interval);
			}
    }
  }
  
  

	$('pack-refresh-hour').set('text',pack_refresh_hour);
	
  if (pack_refresh_min >= 0 && pack_refresh_min <= 9) {
    $('pack-refresh-min').set('text','0' + pack_refresh_min);
  } else {
    $('pack-refresh-min').set('text',pack_refresh_min);
  }

  if (pack_refresh_seconds >= 0 && pack_refresh_seconds <= 9) {
    $('pack-refresh-seconds').set('text','0' + pack_refresh_seconds);
  } else {
    $('pack-refresh-seconds').set('text',pack_refresh_seconds);
  }
}
