contract EscrowICO is Token, ICO {
    uint256 public constant MIN_PRE_ICO_SLOGN_COLLECTED = 1000 ether;       // PRE ICO is successful only if sold 10.000.000 slogns
    uint256 public constant MIN_ICO_SLOGN_COLLECTED = 1000 ether;          // ICO is successful only if sold 100.000.000 slogns

    bool public isTransactionsAllowed;

    uint256 public totalSoldSlogns;

    mapping (address => uint256) public preIcoEthers;
    mapping (address => uint256) public icoEthers;

    event RefundEth(address indexed owner, uint256 value);
    event IcoFinished();

    function EscrowICO() {
        isTransactionsAllowed = false;
    }

    function getIcoStep(uint256 time) returns (uint8 step) {
        if(time >=  PRE_ICO_SINCE && time <= PRE_ICO_TILL) {
            return 1;
        }
        else if(time >= ICO_SINCE && time <= ICO_TILL) {
            // ico shoud fail if collected less than 1000 slogns during pre ico
            if(totalSoldSlogns >= MIN_PRE_ICO_SLOGN_COLLECTED) {
                return 2;
            }
        }

        return 0;
    }

    /**
     * officially finish ICO, only allowed after ICO is ended
     */
    function icoFinishInternal(uint256 time) internal returns (bool) {
        if(time <= ICO_TILL) {
            return false;
        }

        if(totalSoldSlogns >= MIN_ICO_SLOGN_COLLECTED) {
            // burn tokens assigned to smart contract

            _totalSupply = _totalSupply - balanceOf[this];

            balanceOf[this] = 0;

            // allow transactions for everyone
            isTransactionsAllowed = true;

            IcoFinished();

            return true;
        }

        return false;
    }

    /**
     * refund ico method
     */
    function refundInternal(uint256 time) internal returns (bool) {
        if(time <= PRE_ICO_TILL) {
            return false;
        }

        if(totalSoldSlogns >= MIN_PRE_ICO_SLOGN_COLLECTED) {
            return false;
        }

        uint256 transferedEthers;

        transferedEthers = preIcoEthers[msg.sender];

        if(transferedEthers > 0) {
            preIcoEthers[msg.sender] = 0;

            balanceOf[msg.sender] = 0;

            msg.sender.transfer(transferedEthers);

            RefundEth(msg.sender, transferedEthers);

            return true;
        }

        return false;
    }
}
function icoFinishInternal(uint256 time) internal returns (bool) {
        if(time <= ICO_TILL) {
            return false;
        }

        if(totalSoldSlogns >= MIN_ICO_SLOGN_COLLECTED) {
            // burn tokens assigned to smart contract

            _totalSupply = _totalSupply - balanceOf[this];

            balanceOf[this] = 0;

            // allow transactions for everyone
            isTransactionsAllowed = true;

            IcoFinished();

            return true;
        }

        return false;
    }
/**
 * officially finish ICO, only allowed after ICO is ended
 */