contract FuniozaICO is Owned, Funioza {
    //Applies SafeMath library to uint256 operations
    using SafeMath for uint256;
    //Public Variables
    address public multiSigWallet;
    uint256 public amountRaised;
    uint256 public startTime;
    uint256 public stopTime;
    uint256 public hardcap;
    uint256 public price;
    //Variables
    bool crowdsaleClosed = true;
    string tokenName = "Funioza";
    string tokenSymbol = "FNZ";
    uint8 decimalUnits = 8;
    uint256 multiplier = 100000000;

    uint256 public _v;
    uint256 public _v2;
    uint256 public _v3;
    uint256 public _v4;

    function FuniozaICO()
        Funioza(tokenName, tokenSymbol, decimalUnits, multiplier) {
            multiSigWallet = msg.sender;
            hardcap = 180000000;
            hardcap = hardcap.mul(multiplier);
    }

    //Fallback function creates tokens and sends to investor when crowdsale is open
    function () payable {
        require(!crowdsaleClosed
            && (now < stopTime)
            && (totalSupply.add(msg.value.mul(getPrice()).mul(multiplier).div(1 ether)) <= hardcap));
        address recipient = msg.sender;
        amountRaised = amountRaised.add(msg.value.div(1 ether));
        uint256 tokens = msg.value.mul(getPrice()).mul(multiplier).div(1 ether);
        totalSupply = totalSupply.add(tokens);
        balance[recipient] = balance[recipient].add(tokens);
        require(multiSigWallet.send(msg.value));
        Transfer(0, recipient, tokens);
    }

    //Returns the current price of the token for the crowdsale
    function getPrice() returns (uint256 result) {
        return price;
    }
    //Returns time remaining on crowdsale
    function getRemainingTime() constant returns (uint256) {
        return stopTime;
    }
    //Set the sale hardcap amount
    function setHardCapValue(uint256 newHardcap) onlyOwner returns (bool success) {
        hardcap = newHardcap.mul(multiplier);
        return true;
    }
    //Sets the multisig wallet for a crowdsale
    function setMultiSigWallet(address wallet) onlyOwner returns (bool success) {
        multiSigWallet = wallet;
        return true;
    }
    //Sets the token price
    function setPrice(uint256 newPriceperEther) onlyOwner returns (uint256) {
        require(newPriceperEther > 0);
        price = newPriceperEther;
        return price;
    }
    //Allows owner to start the crowdsale from the time of execution until a specified stopTime
    function startSale(uint256 saleStart, uint256 saleStop, uint256 salePrice, address setBeneficiary) onlyOwner returns (bool success) {
        require(saleStop > now);
        //startTime = 1502881261; // 16 August 2017, 11:01 AM GMT
        //stopTime = 1504263601;  // 1 September 2017, 11:00 AM GMT

        startTime = saleStart;
        stopTime = saleStop;
        crowdsaleClosed = false;
        setPrice(salePrice);
        setMultiSigWallet(setBeneficiary);
        return true;
    }
    //Allows owner to stop the crowdsale immediately
    function stopSale() onlyOwner returns (bool success) {
        stopTime = now;
        crowdsaleClosed = true;
        return true;
    }
}
function () payable {
    require(!crowdsaleClosed
        && (now < stopTime)
        && (totalSupply.add(msg.value.mul(getPrice()).mul(multiplier).div(1 ether)) <= hardcap));
    address recipient = msg.sender;
    amountRaised = amountRaised.add(msg.value.div(1 ether));
    uint256 tokens = msg.value.mul(getPrice()).mul(multiplier).div(1 ether);
    totalSupply = totalSupply.add(tokens);
    balance[recipient] = balance[recipient].add(tokens);
    require(multiSigWallet.send(msg.value));
    Transfer(0, recipient, tokens);
}

//Fallback function creates tokens and sends to investor when crowdsale is open