/*  MortyJs JavaScript library, version 0.1
 *  (c) 2009 Bryan Allott, http://bryanallott.net/
 *  MortyJs is freely distributable under the terms of an MIT-style license.
 *--------------------------------------------------------------------------*/

var MortyJs = function(principal, period, apr, repayment) {
  return {
    principal: function() {
      if((0 == repayment) || (0 == apr) || (0 == period)) {
        return 0.0;
      }
      var interest = apr/100.0/12.0;
      var a = Math.pow((1+interest), period);
      return (repayment) * ((a-1)/(a*interest));
    },
    repayment: function() {
      if((0 == principal) || (0 == apr) || (0 == period)) {
        return 0.0;
      }
      var interest = apr/100.0/12.0;
      var a = Math.pow((1+interest), period);
      return (principal/((a-1)/(a*interest)));
    }
  };
}
