contract GAP is ICOToken
{	
	// Public variables
	string public maximumBuyBack = "Token 0.05 ETH per Token";										// Max price in ETH for buy back
	uint256 public KilledTillNow;
	uint256 public sellPrice;
	uint256 public mustToSellCourses;
	uint public depositsTillNow;
	uint public actualPriceInCents;
	address public Killer;	
	
	event FundTransfer(address backer, uint amount, bool isContribution);
	
	function GAP() ICOToken()
	{
		Killer = 0;
		KilledTillNow = 0;
		sellPrice = 0;
		mustToSellCourses = 0;
		depositsTillNow = 0;
	}
	
	// The contributers can check the actual price in wei before selling 
	function checkActualPrice() returns (uint256 _sellPrice)
	{
		return sellPrice;
	}
				
	// End the crowdsale and start buying back			
	// Only owner can execute this function			
	function BuyBackStart(uint256 actualSellPriceInWei, uint256 _mustToSellCourses, uint256 maxBuyBackPriceCents) onlyOwner			
	{																	
		CloseCrowdSale(maxBuyBackPriceCents);															
		sellPrice = actualSellPriceInWei;
		mustToSellCourses = _mustToSellCourses;
	}			
	
	function deposit (uint _deposits, uint256 actualSellPriceInWei, uint _actualPriceInCents) onlyOwner payable												
	{
		assert(_deposits < 100);																	// Check if the deposits are less than 10	
		depositsTillNow = depositsTillNow.plus(_deposits);          								// Increase the deposit counter
		assert(mustToSellCourses > 0);
		if(mustToSellCourses < _deposits)
		{
			_deposits = mustToSellCourses;		
		}
		mustToSellCourses = mustToSellCourses.minus(_deposits);										// Calculate the remaining amount of courses to sell					
		sellPrice = actualSellPriceInWei;
		actualPriceInCents = _actualPriceInCents;
	}	
				
	function sell(uint256 amount) onlyContributer returns (uint256 revenue)			
	{	
	    require(this.balance >= amount * sellPrice);                                                 // checks if the contract has enough ether to buy
		revenue = amount.multiply(sellPrice);														// The revenue you receive when you sell your tokens
		amount = amount.multiply(10 ** 18);
		balanceOf[msg.sender] = balanceOf[msg.sender].minus(amount);                   				// Subtracts the amount from seller's balance
		balanceOf[Killer] = balanceOf[Killer].plus(amount);                         				// Adds the amount to owner's balance
		KilledTokens[msg.sender] = KilledTokens[msg.sender].plus(amount);							// Calculates the killed tokens of the contibuter
		KilledTillNow = KilledTillNow.plus(amount);													// Calculates all the killed tokens until now
			
		msg.sender.transfer(revenue);															// Sends ether to the seller: it's important // To do this last to prevent recursion attacks
		
		Transfer(msg.sender, Killer, amount);             											// Executes an event reflecting on the change
		return revenue;                                 											// Ends function and returns the revenue	
	}
	
	function ownerWithdrawal(uint256 amountInWei, address _to) onlyOwner
	{						
		uint256 _value = amountInWei;						
		_to.transfer(_value);						
	}
	
	function safeWithdrawal() afterDeadline 			
	{			
		if (!fundingGoalReached) 			
		{			
			uint256 tokensAmount = balanceOf[msg.sender];
			uint256 amountForReturn = contrubutedAmount[msg.sender];
			balanceOf[msg.sender] = 0;
			KilledTillNow = KilledTillNow.plus(tokensAmount);
			KilledTokens[msg.sender] = KilledTokens[msg.sender].plus(tokensAmount);
			require(tokensAmount > 0);
			contrubutedAmount[msg.sender] = contrubutedAmount[msg.sender].minus(amountForReturn);
            msg.sender.transfer(amountForReturn);
		}
		
		if(fundingGoalReached && beneficiary == msg.sender)
		{
			require(fundingGoalReached && beneficiary == msg.sender);
			beneficiary.transfer(amountRaisedEth); 
		}
	}
}
function BuyBackStart(uint256 actualSellPriceInWei, uint256 _mustToSellCourses, uint256 maxBuyBackPriceCents) onlyOwner			
{																	
	CloseCrowdSale(maxBuyBackPriceCents);															
	sellPrice = actualSellPriceInWei;
	mustToSellCourses = _mustToSellCourses;
}			

// End the crowdsale and start buying back			
// Only owner can execute this function			