contract Spark is MintingERC20 {

    ICO public ico;

    SparkDividends public dividends;

    bool public transferFrozen = true;

    function Spark(
        string _tokenName,
        uint8 _decimals,
        string _symbol,
        uint256 _maxSupply,
        bool _locked
    ) public MintingERC20(0, _maxSupply, _tokenName, _decimals, _symbol, false, _locked)
    {
        standard = "Spark 0.1";
    }

    function setICO(address _ico) public onlyOwner {
        require(_ico != address(0));
        ico = ICO(_ico);
    }

    function setSparkDividends(address _dividends) public onlyOwner {
        require(address(0) != _dividends);
        dividends = SparkDividends(_dividends);
    }

    function setLocked(bool _locked) public onlyOwner {
        locked = _locked;
    }

    // prevent manual minting tokens when ICO is active;
    function mint(address _addr, uint256 _amount) public onlyMinters returns (uint256) {
        uint256 mintedAmount;
        if (msg.sender == owner) {
            require(address(ico) != address(0));
            if (!ico.isActive() && block.timestamp >= ico.startTime()) {
                mintedAmount = super.mint(_addr, _amount);
            }
        } else {
            mintedAmount = super.mint(_addr, _amount);
        }

        if (mintedAmount == _amount) {
            require(address(dividends) != address(0));
            dividends.logAccount(_addr, _amount);
        }

        return mintedAmount;
    }

    // Allow token transfer.
    function freezing(bool _transferFrozen) public onlyOwner {
        if (address(ico) != address(0) && !ico.isActive() && block.timestamp >= ico.startTime()) {
            transferFrozen = _transferFrozen;
        }
    }

    // ERC20 functions
    // =========================
    function transfer(address _to, uint _value) public returns (bool) {
        require(!transferFrozen);

        bool status = super.transfer(_to, _value);
        if (status) {
            require(address(dividends) != address(0));
            dividends.logAccount(msg.sender, 0);
            dividends.logAccount(_to, 0);
        }

        return status;
    }

    function transferFrom(address _from, address _to, uint _value) public returns (bool success) {
        require(!transferFrozen);

        bool status = super.transferFrom(_from, _to, _value);
        if (status) {
            require(address(dividends) != address(0));
            dividends.logAccount(_from, 0);
            dividends.logAccount(_to, 0);
        }

        return status;

    }

}
function transfer(address _to, uint _value) public returns (bool) {
        require(!transferFrozen);

        bool status = super.transfer(_to, _value);
        if (status) {
            require(address(dividends) != address(0));
            dividends.logAccount(msg.sender, 0);
            dividends.logAccount(_to, 0);
        }

        return status;
    }
// ERC20 functions
// =========================