contract PibbleMain is Crowdsale, Ownable {

  uint256 public minValue;
//  uint256 public maxValue;
  
  bool public paused = false;


  event Pause();
  event Unpause();

  /**
   * @dev Modifier to make a function callable only when the contract is not paused.
   */
  modifier whenNotPaused() {
    require(!paused);
    _;
  }

  /**
   * @dev Modifier to make a function callable only when the contract is paused.
   */
  modifier whenPaused() {
    require(paused);
    _;
  }

/**
 * rate 200,000 PIB per 1 eth  
 */
  function PibbleMain(uint256 _openingTime, uint256 _closingTime, uint256 _rate, address _wallet, uint256 _cap, MintableToken _token, uint256 _minValue) public
    Crowdsale(_rate, _wallet, _token, _cap, _openingTime, _closingTime)
    {
        require(_minValue >= 0);
        minValue =_minValue;
//        maxValue =_maxValue;
    }


  /**
   * @dev Allows the "TOKEN owner" to transfer control of the contract to a newOwner.
   * @param newOwner The address to transfer ownership to.
   */
  function transferTokenOwnership(address newOwner) public onlyOwner {
    require(newOwner != address(0));
    OwnershipTransferred(owner, newOwner);
    MintableToken(token).transferOwnership(newOwner);
  }

  function buyTokens(address _beneficiary) public payable whenNotPaused {

    require( minValue <= msg.value );
//    require( ( minValue <= msg.value && msg.value <= maxValue) );
//    require(msg.value <= maxValue);
    super.buyTokens(_beneficiary);
    
  }

/**
  function _forwardFunds() internal whenNotPaused {
    super._forwardFunds();
  }
**/

  function _forwardFundsWei(uint256 txAmount) internal whenNotPaused {
    super._forwardFundsWei(txAmount);
  }

  function _deliverTokens(address _beneficiary, uint256 _tokenAmount) internal whenNotPaused {
//    do nothing at thistime.
//    super._deliverTokens(_beneficiary, _tokenAmount) 

  }

  function _setContributor(address _beneficiary, uint256 _tokenAmount) internal whenNotPaused {

    super._setContributor(_beneficiary,_tokenAmount);

  }

  function mintContributors(address[] contributors) public onlyOwner {

    address contributor ;
    uint tokenCount = 0;

    for (uint i = 0; i < contributors.length; i++) {
        contributor = contributors[i];
        tokenCount = contributorList[contributor];
        
        //require(tokenCount > 0);
        
        MintableToken(token).mint(contributor, tokenCount);
       
       // reset data
       delete contributorList[contributor];
    }      
      
  }

  /**
   * @dev called by the owner to pause, triggers stopped state
   */
  function pause() onlyOwner whenNotPaused public {
    paused = true;
    Pause();
  }

  /**
   * @dev called by the owner to unpause, returns to normal state
   */
  function unpause() onlyOwner whenPaused public {
    paused = false;
    Unpause();
  }

  function saleEnded() public view returns (bool) {
    return (weiRaised >= cap || now > closingTime);
  }
 
  function saleStatus() public view returns (uint, uint) {
    return (cap, weiRaised);
  } 
  
}
/**
 * @title Pibble2ndPresale
 * @dev This is an example of a fully fledged crowdsale.
 * The way to add new features to a base crowdsale is by multiple inheritance.
 * In this example we are providing following extensions:
 * CappedCrowdsale - sets a max boundary for raised funds
 * RefundableCrowdsale - set a min goal to be reached and returns funds if it's not met
 *
 * After adding multiple features it's good practice to run integration tests
 * to ensure that subcontracts works together as intended.
 */
function PibbleMain(uint256 _openingTime, uint256 _closingTime, uint256 _rate, address _wallet, uint256 _cap, MintableToken _token, uint256 _minValue) public
  Crowdsale(_rate, _wallet, _token, _cap, _openingTime, _closingTime)
  {
      require(_minValue >= 0);
      minValue =_minValue;
        maxValue =_maxValue;
  }

/**
 * rate 200,000 PIB per 1 eth  
 */