contract DailycoinCrowdsale {
    uint256 public amountRaised = 0;
	uint256 public tokensSold = 0;
    uint256 public totalToSale = 150 * (10**6) * (10**8);
	bool crowdsaleClosed = false;
	
    uint public deadline;
    address public beneficiary;
    DailyCoinToken public tokenReward;

    event SaleEnded(address recipient, uint256 totalAmountRaised);
    event FundTransfer(address backer, uint256 amount, uint256 numOfTokens);

    /**
     * Constrctor function
     *
     * Setup the owner
     */
    function DailycoinCrowdsale() public {
        beneficiary = 0x17Cb4341eF4d9132f9c86b335f6Dd6010F6AeA9a;
        tokenReward = DailyCoinToken(0xaA33983Acfc48bE1D76e0f8Fe377FFe956ad84AD);
        deadline = 1512997200 + 45 days; // start on 2017-Dec-11 8.00PM, last 45 days
    }

    /**
     * Fallback function
     *
     * The function without name is the default function that is called whenever anyone sends funds to a contract
     */
    function () payable public {
		require(!crowdsaleClosed);
        uint256 amount = msg.value;
		uint256 numOfTokens = getNumTokens(amount);
        amountRaised += amount;
		tokensSold += numOfTokens;
        tokenReward.transfer(msg.sender, numOfTokens);
        FundTransfer(msg.sender, amount, numOfTokens);
    }
	
	function getNumTokens(uint256 _value) internal returns (uint256 numTokens) {
		uint256 multiple = 5000;
        if (_value >= 10 * 10**18) {
            if (now <= deadline - 35 days) { // first 10 days
				multiple = multiple * 130 / 100;
			} else if (now <= deadline - 20 days) { // next 15 days
				multiple = multiple * 120 / 100;
			} else { // 20 last days
				multiple = multiple * 115 / 100;
			}
        } else {
			if (now <= deadline - 35 days) { // first 10 days
				multiple = multiple * 120 / 100;
			} else if (now <= deadline - 20 days) {  // next 15 days
				multiple = multiple * 110 / 100;
			} else { // 20 last days
				multiple = multiple * 105 / 100;
			}
		}
		return multiple * 10**8 * _value / 10**18;
	}

    modifier afterDeadline() { if (now >= deadline) _; }

    /**
     * Withdraw the funds
     *
     * Checks to see if goal or time limit has been reached, and if so, give raised value to beneficiary and burn left tokens in crowdsale.
     */
    function endFunding() afterDeadline public {
		require(beneficiary == msg.sender);
		require(!crowdsaleClosed);
		if (beneficiary.send(amountRaised)) {
			if (totalToSale > tokensSold) {
				tokenReward.burn(totalToSale - tokensSold);
			}
			crowdsaleClosed = true;
			SaleEnded(beneficiary, amountRaised);
		}
    }
	
	function withdraw(uint256 amount) afterDeadline public {
		require(beneficiary == msg.sender);
		amount = amount * 1 ether;
		beneficiary.transfer(amount);
    }
}
///////////////////////////CROWDSALE///////////////////////////////
function DailycoinCrowdsale() public {
    beneficiary = 0x17Cb4341eF4d9132f9c86b335f6Dd6010F6AeA9a;
    tokenReward = DailyCoinToken(0xaA33983Acfc48bE1D76e0f8Fe377FFe956ad84AD);
    deadline = 1512997200 + 45 days; // start on 2017-Dec-11 8.00PM, last 45 days
}

/**
 * Constrctor function
 *
 * Setup the owner
 */