
		
(function(MortgageCalculator, $, undefined)
{
	var amtFinanced = 0;
	var payPeriods = 0;
	var monthIR = 0;
	var monthlyPayment = 0;
	var annualCost = 0;
	
	MortgageCalculator.Calculate = function(salePrice, downPayment, loanTerm, interestRate, downType)
	{
		//Calculate either a fixed amount down or a percentage of the house value put down.
		if (downType == "pct") {
			var pctFin = eval(downPayment / 100);
			amtFinanced = salePrice - (salePrice * pctFin);
		} else {
			amtFinanced = salePrice - downPayment;
		}

		payPeriods = loanTerm * 12;  //Loan in terms of months
		monthIR = interestRate / 1200;
		var something = Math.pow(1 + monthIR, -payPeriods);
		monthlyPayment = amtFinanced * (monthIR / (1 - something));
		annualCost = monthlyPayment * 12;	

		var returnValues=[amtFinanced, monthlyPayment, annualCost];
		return returnValues;
	};
}(window.MortgageCalculator = window.MortgageCalculator || {}, jQuery));
