pragma solidity ^0.4.11;

 

contract owned {

  address public owner;

 

  function owned() {

    owner = msg.sender;

  }

 

  modifier onlyOwner {

    if (msg.sender != owner) throw;

    _;

  }

 

  function transferOwnership(address newOwner) onlyOwner {

    owner = newOwner;

  }

}

 

contract CharityInterface {

    function donate(address[] recipients) payable;

}

 

contract Charity is owned, CharityInterface {

    address[] projects;

    uint public feePercent;

    mapping (address => uint) projectsMapping;

 

    function setFeePercent(uint value) onlyOwner {

        assert(value < 100);

        feePercent = value;

    }

 

    function addProject(address project) onlyOwner {

        if (!projectExists(project)) {

            projects.push(project);

            projectsMapping[project] = projects.length;

        }

    }

 

    function removeProject(address project) onlyOwner {

        if (projectExists(project)) {

            var index = projectsMapping[project] - 1;

            delete projects[index];

            delete projectsMapping[project];

        }

    }

 

    function donate(address[] recipients) payable {

        var withoutFee = msg.value / 100 * (100 - feePercent);

        var share = withoutFee / recipients.length;

        for (uint i = 0; i < recipients.length; i++) {

            assert(projectExists(recipients[i]));

 

            recipients[i].transfer(share);

        }

    }

 

    function projectExists(address value) constant returns (bool) {

        return projectsMapping[value] > 0;

    }

 

    function getProjects() constant returns (address[]) {

        return projects;

    }

}