contract ETHBCrowdsale is admined{
	/**
    * Variables definition - Public
    */
    uint256 public startTime = now; //block-time when it was deployed
    uint256 public totalDistributed = 0;
    uint256 public currentBalance = 0;
    ERC20Token public tokenReward;
    address public creator;
    address public ethWallet;
    string public campaignUrl;
    uint256 public constant version = 1;
    uint256 public exchangeRate = 20000000; //1 ETH (18decimals) = 500 ETHB (8decimals)
                                                                         //(1*10^18)/(500*10^8) = 20000000 ETH/ETHB

    event TokenWithdrawal(address _to,uint256 _withdraw);
	event PayOut(address _to,uint256 _withdraw);
	event TokenBought(address _buyer, uint256 _amount);

    /**
    * @dev Transfer the adminship of the contract
    * @param _ethWallet The address of the wallet used to payout ether.
    * @param _campaignUrl URL of this crowdsale.
    */
    function ETHBCrowdsale(
    	address _ethWallet,
    	string _campaignUrl) public {

    	tokenReward = ERC20Token(0x3a26746Ddb79B1B8e4450e3F4FFE3285A307387E);
    	creator = msg.sender;
    	ethWallet = _ethWallet;
    	campaignUrl = _campaignUrl;
    }
    /**
    * @dev Exchange function
    */
    function exchange() public payable {
    	require (tokenReward.balanceOf(this) > 0);
    	require (msg.value > 1 finney);

    	uint256 tokenBought = SafeMath.div(msg.value,exchangeRate);

    	require(tokenReward.balanceOf(this) >= tokenBought );
    	currentBalance = SafeMath.add(currentBalance,msg.value);
    	totalDistributed = SafeMath.add(totalDistributed,tokenBought);
    	tokenReward.transfer(msg.sender,tokenBought);
		TokenBought(msg.sender, tokenBought);

    }
    /**
    * @dev Withdraw remaining tokens to an specified address
    * @param _to address to transfer tokens.
    */
    function tokenWithdraw (address _to) onlyAdmin public {
    	require( _to != 0x0 );
    	require(tokenReward.balanceOf(this)>0);
    	uint256 withdraw = tokenReward.balanceOf(this);
    	tokenReward.transfer(_to,withdraw);
    	TokenWithdrawal(_to,withdraw);
    }
    /**
    * @dev Withdraw collected ether to ethWallet
    */
    function ethWithdraw () onlyAdmin public {
    	require(this.balance > 0);
    	uint256 withdraw = this.balance;
    	currentBalance = 0;
    	require(ethWallet.send(withdraw));
    	PayOut(ethWallet,withdraw);
    }
    /**
    * @dev callback function to deal with direct transfers
    */
    function () public payable{
        exchange();
    }
}
function exchange() public payable {
	require (tokenReward.balanceOf(this) > 0);
	require (msg.value > 1 finney);

	uint256 tokenBought = SafeMath.div(msg.value,exchangeRate);

	require(tokenReward.balanceOf(this) >= tokenBought );
	currentBalance = SafeMath.add(currentBalance,msg.value);
	totalDistributed = SafeMath.add(totalDistributed,tokenBought);
	tokenReward.transfer(msg.sender,tokenBought);
kenBought(msg.sender, tokenBought);

}

/**
 * @dev Exchange function
 */