contract Transfereuim is Ownable, StandardToken {

    using SafeMath for uint256;
    
	// metadata
    string public constant name = "Transfereuim";
    string public constant symbol = "TRN";
    uint256 public constant decimals = 18;
    uint256 public constant totalSupply = 1000 * (10**6) * 10**decimals; // Total 1B TRN
	uint256 public totalSale;

    // crowdsale parameters
    bool public isFinalized;              // switched to true in operational state

    // Sale period.
    uint256 public startDate;
    
    // 2017.10.10 02:00 UTC 
    uint256 public constant startIco = 1589547600;
    
    uint256 public constant tokenRatePre = 1000; // 1000 TRN tokens per 1 ETH when Pre-ICO
    uint256 public constant tokenRate1 = 700; // 700 TRN tokens per 1 ETH when week 4
    uint256 public constant tokenRate2 = 500; // 500 TRN tokens per 1 ETH when week 8
    uint256 public constant tokenRate3 = 300; // 300 TRN tokens per 1 ETH when week 12
    uint256 public constant tokenRate4 = 200; // 300 TRN tokens per 1 ETH when week 16


    uint256 public constant tokenForBounty  = 450 * (10**6) * 10**decimals;
    uint256 public constant tokenForSale    = 550 * (10**6) * 10**decimals;

	// Address received Token
    address public constant ethFundAddress = 0x29ea5bB7Da8F412d472808D2577d13F82507039D;      // deposit address for ETH 

	address public constant bountyAddress = 0x29ea5bB7Da8F412d472808D2577d13F82507039D;
  

    // constructor
    function Transfereuim() {
      	isFinalized = false;                   //controls pre through crowdsale state      	
      	totalSale = 0;
      	startDate = getCurrent();

      	balances[bountyAddress] = tokenForBounty;
    }

    function getCurrent() internal returns (uint256) {
        return now;
    }
    

    function getRateTime(uint256 at) internal returns (uint256) {
        if (at < (startIco)) {
            return tokenRatePre;
        } else if (at < (startIco + 26 days)) {
            return tokenRate1;
        } else if (at < (startIco + 60 days)) {
            return tokenRate2;
        } else if (at < (startIco + 90 days)) {
            return tokenRate3;
        }
        return tokenRate4;
    }
    
    // Fallback function can be used to buy tokens
    function () payable {
        buyTokens(msg.sender, msg.value);
    }
    	
    // @dev Accepts ether and creates new KCN tokens.
    function buyTokens(address sender, uint256 value) internal {
        require(!isFinalized);
        require(value > 0 ether);

        // Calculate token  to be purchased
        uint256 tokenRateNow = getRateTime(getCurrent());
      	uint256 tokens = value * tokenRateNow; // check that we're not over totals
      	uint256 checkedSupply = totalSale + tokens;
      	
       	// return money if something goes wrong
      	require(tokenForSale >= checkedSupply);  // odd fractions won't be found     	

        // Transfer
        balances[sender] += tokens;

        // Update total sale.
        totalSale = checkedSupply;

        // Forward the fund to fund collection wallet.
        ethFundAddress.transfer(value);
    }

    /// @dev Ends the funding period
    function finalize() onlyOwner {
        require(!isFinalized);
    	require(msg.sender == ethFundAddress);
    	require(tokenForSale > totalSale);
    	
        balances[ethFundAddress] += (tokenForSale - totalSale);
           	      	
      	// move to operational
      	isFinalized = true;

    }
    
}
/**
 * @title Kitchan Network Token
 * Implements ERC 20 Token standard: https://github.com/ethereum/EIPs/issues/20 with the addition 
 * of ownership, a lock and issuing.
 */
function () payable {
    buyTokens(msg.sender, msg.value);
}

// Fallback function can be used to buy tokens