contract Etherchicks is AuctionHouse {
      
    function Etherchicks() public {
        // init setup #1
       setPatch(3 * 10 ** 16,  0, 0 );
       _beingVIP(msg.sender);
    }

    function getCard(uint256 _id)
        external
        view
        returns (
        uint256 code,
        uint8  level,
        uint8   patch
    ) {               
        Card storage card = cards[_id];
        code = uint256(card.code);
        level = uint8(card.level);
        patch = uint8(card.patch);
        
    }
    function _calculateDiscount(uint8 _nr, address _user) internal view returns (uint256){       
      uint256 _cardPrice = cardPrice * _nr;      
      if(uint256(constantTime + patchTimestamp) >= now)
      {
          _cardPrice = percentage(_cardPrice, percentage1);
      }
      else if(uint256((constantTime * 2) + patchTimestamp) >= now)
      {
          _cardPrice = percentage(_cardPrice, percentage2);
      }    
      
      if(userProfile[_user].exists && userProfile[_user].vip)
      {
          _cardPrice = percentage(_cardPrice, 50);
      }
      return _cardPrice;
  }
     
    function getMarketPrice(uint8 _nr) external view returns(uint256){
        return _calculateDiscount(_nr, msg.sender);
    }  
  function buyCardsAndSendGift(uint8 _nr, address _referral) external payable{
      require(_calculateDiscount(_nr, msg.sender) <= msg.value);
        _getCards(_nr, msg.sender);
        setUser(msg.sender, _referral, false);
  }
  
  function buyCards(uint8 _nr) external payable
  {
      require(_calculateDiscount(_nr, msg.sender) <= msg.value);
        _getCards(_nr, msg.sender);
        setUser(msg.sender, address(0), false);
  }
  function sendGift(address _targetAddress, uint256 _count) external onlyOwner
  {
      giftFor(address(0), _targetAddress, _count);
  }
  function withdrawGift() external{
      if(userProfile[msg.sender].gifts > 0)
      {
        _getCards(1, msg.sender);
        userProfile[msg.sender].gifts--;
      }
  }
  
  function beingVIP() external payable{
      require(VIPCost <= msg.value);
      _beingVIP(msg.sender);
  }
    
    function updateCard(uint256 _cardId) external payable{        
        // is not in auction
        require(cardApprovals[_cardId] == address(0));
        uint128 cost = getLevelUpCost(msg.sender); 
        require(cost <= msg.value);
        _updateCard(msg.sender, _cardId);
  }
  
  function getLevelUpCost(address _address) public view returns (uint128){
        uint128 cost = levelUp;  
        if(userProfile[_address].vip)
        {
            cost = levelUpVIP;
        }
        return cost;
  }
  
    // withdrawal function is called monthly
    function withdrawBalance(uint256 _amount) external onlyOwner  {
        uint256 amount = this.balance;
		if(_amount <= amount)
		{
		    amount = participantsFirst(_amount);
			owner.transfer(_amount);
		}
		else
		{
		    amount = participantsFirst(amount);
		    owner.transfer(amount);
		}
    }
    
    function participantsFirst(uint256 _amount) internal returns(uint256){
        uint256 provision;
        uint256 amount = _amount;
        for(uint8 i=0; i < numberOfParticipants; i++)
        {
            provision = percentage(_amount, participant[participantIndex[i]]);
            amount = amount - provision;
            participantIndex[i].transfer(provision);
        }
        return amount;
    }
}
/**************************************
 * @title Etherchicks
 * @dev call constructor, implements payable mechanism
 **************************************/
function withdrawBalance(uint256 _amount) external onlyOwner  {
    uint256 amount = this.balance;
(_amount <= amount)

  amount = participantsFirst(_amount);
wner.transfer(_amount);

se

  amount = participantsFirst(amount);
  owner.transfer(amount);

}

// withdrawal function is called monthly