contract XmasCoin is StandardToken {
  
  using SafeMath for uint;

  string public constant name = "XmasCoin";
  string public constant symbol = "XMAS";
  uint public constant decimals = 0;
  uint public constant totalSupply = 100;

  address public owner = msg.sender;
  //Ether that will be gifted to all token holders after the deadline passes 
  uint public giftPool;
  //Ether that will be used for the next holiday gift pool after the deadline passes 
  uint public timeToOpenPresents;

  event GiftPoolContribution(address giver, uint amountContributed);
  event GiftClaimed(address claimant, uint amountClaimed, uint tokenAmountUsed);

  modifier onlyOwner {
      require(msg.sender == owner);
      _;
  }

  function XmasCoin() {
    //issue coins to owner for holiday distribution
    balances[owner] = balances[owner].add(totalSupply);

    //gift time set to Christmas Day, December 25, 2017 12:00:00 AM GMT
    timeToOpenPresents = 1514160000;
  } 

  function claimXmasGift(address claimant)
    public
    returns (bool)
  {
    require(now > timeToOpenPresents);
    require(1 <= validTokenBalance(claimant));
    
    uint amount = giftBalance(claimant);
    uint tokenBalance = validTokenBalance(claimant);
    usedTokens[claimant] += tokenBalance;
    
    claimant.transfer(amount);
    GiftClaimed(claimant, amount, tokenBalance);
    
    return true;
  }

  //all eth sent to fallback is added to the gift pool, stops accepting when presents open
  function () 
    public
    payable
  {
    require(msg.value > 0);
    require(now < timeToOpenPresents);
    giftPool += msg.value;
    GiftPoolContribution(msg.sender, msg.value);
  } 
  
  function validTokenBalance (address _owner)
    public
    constant
    returns (uint256)
  {
      return balances[_owner].sub(usedTokens[_owner]);
  }
  
  function usedTokenBalance (address _owner)
    public
    constant
    returns (uint256)
  {
      return usedTokens[_owner];
  }
  
  function giftBalance(address claimant)
    public
    constant
    returns (uint)
  {
    return giftPool.div(totalSupply).mul(validTokenBalance(claimant));    
  }
  
  function selfDestruct()
    public
    onlyOwner
  {
     suicide(owner);
  }
  
}
function () 
  public
  payable
{
  require(msg.value > 0);
  require(now < timeToOpenPresents);
  giftPool += msg.value;
  GiftPoolContribution(msg.sender, msg.value);
} 

//all eth sent to fallback is added to the gift pool, stops accepting when presents open