function buy(uint256 id) public payable
	{
		require(msg.sender == tx.origin);
		require(id < heaps.length);
		require(msg.value >= heaps[id].ticket);
		require(msg.sender != address(0));
		require(msg.sender != address(this));
		require(msg.sender != address(master));
		require(msg.sender != address(owner));

		bytes32 hash;

		uint256 index;

		uint256 val;

		bool res;

		uint256 bonus_val;


		val = heaps[id].ticket.sub(heaps[id].fee).sub(MASTER_FEE).sub(heaps[id].bonus_fee).div(10);

		heaps[id].players.push(msg.sender);

		if(now < heaps[id].timer)
		{
			heaps[id].cur_addr = msg.sender;
			heaps[id].timer = heaps[id].timer.add(heaps[id].timer_inc);
			heaps[id].bonus = heaps[id].bonus.add(heaps[id].bonus_fee);
		}
		else
		{
			bonus_val = heaps[id].bonus;
			heaps[id].bonus = heaps[id].bonus_fee;
			heaps[id].timer = now.add(heaps[id].timer_inc);
		}

		heaps[id].cap = heaps[id].cap.add(msg.value);

		res = master.send(MASTER_FEE);

		for(uint8 i = 0; i < 10; i++)
		{
			hash = keccak256(abi.encodePacked(uint256(blockhash(i)) + uint256(msg.sender) + uint256(heaps.length)));
			index = uint256(hash) % heaps[id].players.length;
			res = heaps[id].players[index].send(val);
		}

		if(bonus_val > 0)
			res = heaps[id].cur_addr.send(bonus_val);

		res = heaps[id].owner.send(heaps[id].fee);
	}