contract PretherICO is Owned, TokenWithMint {
    //Applies SafeMath library to uint256 operations 
    using SafeMath for uint256;

    //Public Variables
    address public multiSigWallet;                  
    bool crowdsaleClosed = true;                    //initializes as true, requires owner to turn on crowdsale
    string tokenName = "Prether"; 
    string tokenSymbol = "PTH"; 
    uint256 public amountRaised; 
    uint256 public deadline; 
    uint256 multiplier = 1; 
    uint256 public price;                           
    uint8 decimalUnits = 0;   
    

   	//Initializes the token
	function PretherICO() 
    	TokenWithMint(tokenName, tokenSymbol, decimalUnits, multiplier) {  
            multiSigWallet = msg.sender;          
    }

    //Fallback function creates tokens and sends to investor when crowdsale is open
    function () payable {
        require(!crowdsaleClosed && (now < deadline)); 
        address recipient = msg.sender; 
        amountRaised = amountRaised + msg.value; 
        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 deadline; 
    }

    //Returns the current status of the crowdsale
    function getSaleStatus() constant returns (bool) {
        bool status = false; 
        if (crowdsaleClosed == false) {
            status = true; 
        }
        return status; 
    }

    //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) {
        if (newPriceperEther <= 0) throw;  //checks for valid inputs
        price = newPriceperEther; 
        return price; 
    }

    //Allows owner to start the crowdsale from the time of execution until a specified deadline
    function startSale(uint256 price, uint256 hoursToEnd) onlyOwner returns (bool success) {
        if ((hoursToEnd < 1 )) throw;     //checks for valid inputs 
        price = setPrice(price); 
        deadline = now + hoursToEnd * 1 hours; 
        crowdsaleClosed = false; 
        return true; 
    }

    //Allows owner to start an unlimited crowdsale with no deadline or funding goal
    function startUnlimitedSale(uint256 price) onlyOwner returns (bool success) {
        price = setPrice(price); 
        deadline = 9999999999;
        crowdsaleClosed = false; 
        return true; 
    }

    //Allows owner to stop the crowdsale immediately
    function stopSale() onlyOwner returns (bool success) {
        deadline = now; 
        crowdsaleClosed = true;
        return true; 
    }

}
function getSaleStatus() constant returns (bool) {
    bool status = false; 
    if (crowdsaleClosed == false) {
        status = true; 
    }
    return status; 
}

//Returns the current status of the crowdsale