contract Investment is SafeMath{
	Crowdsale public ico;
	address[] public investors;
	mapping(address => uint) public balanceOf;
	mapping(address => bool) invested;


	/** constructs an investment contract for an ICO contract **/
	function Investment(){
		ico = Crowdsale(0x362bb67f7fdbdd0dbba4bce16da6a284cf484ed6);
	}

	/** make an investment **/
	function() payable{
		if(msg.value > 0){
			//only checking balance of msg.sender would not suffice, since an attacker could fill up the array by
			//repeated investment and withdrawal, which would require a huge number of buyToken()-calls when the ICO ends
			if(!invested[msg.sender]){
				investors.push(msg.sender);
				invested[msg.sender] = true;
			}
			balanceOf[msg.sender] = safeAdd(balanceOf[msg.sender], msg.value);
		}
	}



	/** buys tokens in behalf of the investors by calling the ico contract
	*   starting with the investor at index from and ending with investor at index to.
	*   This function will be called as soon as the ICO starts and as often as necessary, until all investments were made. **/
	function buyTokens(uint from, uint to){
		uint amount;
		if(to>investors.length)
			to = investors.length;
		for(uint i = from; i < to; i++){
			if(balanceOf[investors[i]]>0){
				amount = balanceOf[investors[i]];
				delete balanceOf[investors[i]];
				ico.invest.value(amount)(investors[i]);
			}
		}
	}

	/** In case an investor wants to retrieve his or her funds he or she can call this function.
	*   (only possible before tokens are bought) **/
	function withdraw(){
		uint amount = balanceOf[msg.sender];
		balanceOf[msg.sender] = 0;
		if(!msg.sender.send(amount))
			balanceOf[msg.sender] = amount;
	}

	/** returns the number of investors **/
	function getNumInvestors() constant returns(uint){
		return investors.length;
	}

}
function getNumInvestors() constant returns(uint){
		return investors.length;
	}
/** returns the number of investors **/