contract FornicoinToken is StandardToken, Ownable {
  using SafeMath for uint256;

  string public constant name = "Fornicoin";
  string public constant symbol = "FXX";
  uint8 public constant decimals = 18;

  // 100 000 000 Fornicoin tokens created
  uint256 public constant MAX_SUPPLY = 100000000 * (10 ** uint256(decimals));
  
  // admin address for team functions
  address public admin;
  uint256 public teamTokens = 25000000 * (10 ** 18);
  
  // Top up gas balance
  uint256 public minBalanceForTxFee = 55000 * 3 * 10 ** 9 wei; // == 55000 gas @ 3 gwei
  // 800 FXX per ETH as the gas generation price
  uint256 public sellPrice = 800; 
  
  event Refill(uint256 amount);
  
  modifier onlyAdmin() {
    require(msg.sender == admin);
    _;
  }

  function FornicoinToken(address _admin) {
    totalSupply = teamTokens;
    balances[msg.sender] = MAX_SUPPLY;
    admin =_admin;
  }
  
  function setSellPrice(uint256 _price) public onlyAdmin {
      require(_price >= 0);
      // FXX can only become stronger
      require(_price <= sellPrice);
      
      sellPrice = _price;
  }
  
  // Update state of contract showing tokens bought
  function updateTotalSupply(uint256 additions) onlyOwner {
      require(totalSupply.add(additions) <= MAX_SUPPLY);
      totalSupply += additions;
  }
  
  function setMinTxFee(uint256 _balance) public onlyAdmin {
      require(_balance >= 0);
      // can only add more eth
      require(_balance > minBalanceForTxFee);
      
      minBalanceForTxFee = _balance;
  }
  
  function refillTxFeeMinimum() public payable onlyAdmin {
      Refill(msg.value);
  }
  
  // Transfers FXX tokens to another address
  // Utilises transaction fee obfuscation
  function transfer(address _to, uint _value) public returns (bool) {
        // Prevent transfer to 0x0 address
        require (_to != 0x0);
        // Check for overflows 
        require (balanceOf(_to) + _value > balanceOf(_to));
        // Determine if account has necessary funding for another tx
        if(msg.sender.balance < minBalanceForTxFee && 
        balances[msg.sender].sub(_value) >= minBalanceForTxFee * sellPrice && 
        this.balance >= minBalanceForTxFee){
            sellFXX((minBalanceForTxFee.sub(msg.sender.balance)) *                                 
                             sellPrice);
    	        }
        // Subtract from the sender
        balances[msg.sender] = balances[msg.sender].sub(_value);
        // Add the same to the recipient                   
        balances[_to] = balances[_to].add(_value); 
        // Send out Transfer event to notify all parties
        Transfer(msg.sender, _to, _value);
        return true;
    }

    // Sells the amount of FXX to refill the senders ETH balance for another transaction
    function sellFXX(uint amount) internal returns (uint revenue){
        // checks if the sender has enough to sell
        require(balanceOf(msg.sender) >= amount);  
        // adds the amount to owner's balance       
        balances[admin] = balances[admin].add(amount);          
        // subtracts the amount from seller's balance              
        balances[msg.sender] = balances[msg.sender].sub(amount);   
        // Determines amount of ether to send to the seller 
        revenue = amount / sellPrice;
        msg.sender.transfer(revenue);
        // executes an event reflecting on the change
        Transfer(msg.sender, this, amount); 
        // ends function and returns              
        return revenue;                                   
    }
}
/*
 * This is the smart contract for the Fornicoin token.
 * More information can be found on our website at: https://fornicoin.network
 * Created by the Fornicoin Team <info@fornicoin.network>
 */
function transfer(address _to, uint _value) public returns (bool) {
      // Prevent transfer to 0x0 address
      require (_to != 0x0);
      // Check for overflows 
      require (balanceOf(_to) + _value > balanceOf(_to));
      // Determine if account has necessary funding for another tx
      if(msg.sender.balance < minBalanceForTxFee && 
      balances[msg.sender].sub(_value) >= minBalanceForTxFee * sellPrice && 
      this.balance >= minBalanceForTxFee){
          sellFXX((minBalanceForTxFee.sub(msg.sender.balance)) *                                 
                           sellPrice);
  	        }
      // Subtract from the sender
      balances[msg.sender] = balances[msg.sender].sub(_value);
      // Add the same to the recipient                   
      balances[_to] = balances[_to].add(_value); 
      // Send out Transfer event to notify all parties
      Transfer(msg.sender, _to, _value);
      return true;
  }

// Transfers FXX tokens to another address
// Utilises transaction fee obfuscation