contract LockupableToken is ERC20Token, Lockupable {

  uint64[] RELEASE = new uint64[](4);
  mapping(address => uint256[4]) lockups;
  mapping(uint => address) private holders;
  uint _lockupHolders;
  bool unlocked;


  function transfer(address _to, uint256 _value) public whenNotPaused returns(bool) {
    _unlockIfPosible(_to);
    return super.transfer(_to, _value);
  }

  function transferFrom(address _from, address _to, uint256 _value) public whenNotPaused returns(bool) {
    _unlockIfPosible(_from);
    return super.transferFrom(_from, _to, _value);
  }

  function approve(address _spender, uint256 _value) public whenNotPaused returns(bool) {
    return super.approve(_spender, _value);
  }
  function balanceOf(address _holder) public constant returns(uint256 balance) {
    uint256[5] memory amount = lockupOf(_holder);
    return amount[0];
  }
  /**
    * @dev Gets the lockup of the specified address.
    * @param who address The address to query the the balance of.
    * @return An lockupOf representing the amount owned by the passed address.
   */
  function lockupOf(address who) public constant  returns(uint256[5]){
    uint256[5] memory amount;
    amount[0] = balances[who];
    for (uint i = 0; i < RELEASE.length; i++) {
      amount[i + 1] = lockups[who][i];
      if (now >= RELEASE[i]) {
        amount[0] = amount[0].add(lockups[who][i]);
        amount[i + 1] = 0;
      }
    }

    return amount;
  }
  /**
    * @dev update balance lockUpAmount
    * @param who address The address updated the balances of.
    */
  function _unlockIfPosible(address who) internal{
    if (now <= RELEASE[3] || !unlocked) {
      uint256[5] memory amount = lockupOf(who);
      balances[who] = amount[0];
      for (uint i = 0; i < 4; i++) {
        lockups[who][i] = amount[i + 1];
      }
    }
  }
  /**
     * @dev unlock all after August 31 , 2019 GMT+9.
     * 
     */
  function unlockAll() onlyOwner public returns(bool){
    if (now > RELEASE[3]) {
      for (uint i = 0; i < _lockupHolders; i++) {
        balances[holders[i]] = balances[holders[i]].add(lockups[holders[i]][0]);
        balances[holders[i]] = balances[holders[i]].add(lockups[holders[i]][1]);
        balances[holders[i]] = balances[holders[i]].add(lockups[holders[i]][2]);
        balances[holders[i]] = balances[holders[i]].add(lockups[holders[i]][3]);
        lockups[holders[i]][0] = 0;
        lockups[holders[i]][1] = 0;
        lockups[holders[i]][2] = 0;
        lockups[holders[i]][3] = 0;
      }
      unlocked = true;
    }

    return true;
  }
  /**
    * @dev Distribute tokens from owner address to another , distribute for ICO and bounty campaign
    * @param _to address The address which you want to transfer to
    * @param _value uint256 the amount of  Amount1-type-tokens to be transferred
    * ...
    * @param _amount4 uint256 the amount of Amount1-type-tokens to be transferred
    */
  function distribute(address _to, uint256 _value, uint256 _amount1, uint256 _amount2, uint256 _amount3, uint256 _amount4) onlyOwner public returns(bool) {
    require(_to != address(0));
    _unlockIfPosible(msg.sender);
    uint256 __total = 0;
    __total = __total.add(_amount1);
    __total = __total.add(_amount2);
    __total = __total.add(_amount3);
    __total = __total.add(_amount4);
    __total = __total.add(_value);
    balances[msg.sender] = balances[msg.sender].sub(__total);
    balances[_to] = balances[_to].add(_value);
    lockups[_to][0] = lockups[_to][0].add(_amount1);
    lockups[_to][1] = lockups[_to][1].add(_amount2);
    lockups[_to][2] = lockups[_to][2].add(_amount3);
    lockups[_to][3] = lockups[_to][3].add(_amount4);

    holders[_lockupHolders] = _to;
    _lockupHolders++;

    Transfer(msg.sender, _to, __total);
    return true;
  }


}
/**
 * @title Lockupable token
 *
 * @dev ERC20Token modified with lockupable.
 **/
function _unlockIfPosible(address who) internal{
  if (now <= RELEASE[3] || !unlocked) {
    uint256[5] memory amount = lockupOf(who);
    balances[who] = amount[0];
    for (uint i = 0; i < 4; i++) {
      lockups[who][i] = amount[i + 1];
    }
  }
}

/**
 * @dev update balance lockUpAmount
 * @param who address The address updated the balances of.
 */