var SlideList = new Class({
	initialize: function(menu, options) {
		this.setOptions(this.getOptions(), options);
		
		this.menu = $(menu), this.current = this.menu.getElement('li.home');
		
		this.menu.getElements('li').each(function(item){
			item.addEvent('mouseover', function(){ this.moveBg(item); }.bind(this));
			item.addEvent('mouseout', function(){ this.moveBg(this.current); }.bind(this));
			item.addEvent('click', function(event){ this.clickItem(event, item); }.bind(this));
		}.bind(this));
				
		this.back = new Element('li').addClass('background').adopt(new Element('div').addClass('left')).injectInside(this.menu);
		this.back.fx = this.back.effects(this.options);
		if(this.current) this.setCurrent(this.current);
	},
	
	setCurrent: function(el, effect){
		this.back.setStyles({left: (el.offsetLeft)+'px', width: (el.offsetWidth)+'px'});
		(effect) ? this.back.effect('opacity').set(0).start(1) : this.back.setOpacity(1);
		this.current = el;
	},
	
	getOptions: function(){
		return {
			transition: Fx.Transitions.sineInOut,
			duration: 500, wait: false,
			onClick: Class.empty
		};
	},

	clickItem: function(event, item) {
		if(!this.current) this.setCurrent(item, true);
		this.current = item;
		this.options.onClick(new Event(event), item);
	},

	moveBg: function(to) {
		if(!this.current) return;
		this.back.fx.custom({
			left: [this.back.offsetLeft, to.offsetLeft],
			width: [this.back.offsetWidth, to.offsetWidth]
		});
	}
});

SlideList.implement(new Options);

window.addEvent('domready', function() {
	new SlideList($E('ul', 'nav'), {transition: Fx.Transitions.backOut, duration: 700});
});
window.addEvent('domready', function() {
var list = $$('#pronav li');
list.each(function(element) {
	var fx = new Fx.Styles(element, {duration:200, wait:false});
	element.addEvent('mouseenter', function(){
		fx.start({
			'margin-left': 5,
			'background-color': '#565656'
				
		});
	});
	element.addEvent('mouseleave', function(){
		fx.start({
			'margin-left': 0,
			'background-color': '#151515'
			
		});
	});
 
});
})
function valNumericStr(strFieldName, strValue, intBlankFlag, intMsgFlag){
	if (strValue.length < 1){
		if (intBlankFlag == 0){
			if (intMsgFlag == 1)
				alert("Please enter a value for " + strFieldName + ".");
			return false;
		}
	}else{
		var decPtAt = 0;
		for (var i = 0; i < strValue.length; i++){
			var localChar = strValue.charAt(i);
			if (localChar < "0" || localChar > "9"){
				if (localChar == "." && decPtAt == 0){
					decPtAt = i + 1;
				}else{
					if (intMsgFlag == 1)
						alert("Please remove the '" + localChar + "' character from " + strFieldName + ".");
					return false;
				}
			}
		}
	}
	return true;
}
function formatFloat (expr, decplaces){
	var str = "" + Math.round( eval(expr) * Math.pow(10, decplaces) );
	while (str.length <= decplaces){
		str = "0" + str;
	}
	var decpoint = str.length - decplaces;
	return str.substring(0, decpoint) + "." + str.substring(decpoint, str.length);
}
function periodizeRate(annualRate, compoundPerYear, decimalFlag){
  if (decimalFlag == 1) periodicRate = annualRate/(compoundPerYear * 100);
  else periodicRate = annualRate/compoundPerYear;
  return periodicRate;
}
function switchFunction()
{
	var curPayment, intTerm, answer;
	var pctARate, pctPRate, curBalance;

	curBalance = document.calculator.balance.value;
	if (valNumericStr("balance", curBalance, 0, 1) == false) curBalance = 0.00;
	else curBalance = parseFloat(curBalance); 
	pctARate = document.calculator.arate.value;
	if (valNumericStr("interest rate", pctARate, 0, 1) == false) pctARate = 0.00;
	else pctARate = parseFloat(pctARate);  
	pctPRate = periodizeRate(pctARate, 12, 1);
	curPayment = document.calculator.payment.value;
	intTerm = document.calculator.term.value;
	
	if (curPayment == "see below" && valNumericStr("months until balance is paid", intTerm, 0, 1) == true)
	{ 
		answer = calcPayments(curBalance, intTerm, pctPRate);
		document.calculator.answer.value = "$" + formatFloat(answer, 2) + " every month";
	}
	else if(intTerm == "see below" && valNumericStr("payment per month", curPayment, 0, 1) == true)
	{ 
		answer = calcTerm(curBalance, curPayment, pctPRate);
		document.calculator.answer.value = answer + " months";
	}
	else
	{
		return;
	}
}
function calcTerm(balance, payment, pRate){
	var interest, paymentCount;
	
	paymentCount = 0;
	while (balance > 0.00){
		interest = parseInt(balance) * pRate;
		if (parseInt(interest,10) > payment)
		{ 
			alert("Your payments are not enough to cover the accumulated interest.  Try increasing the payments.");
			return "infinite";	
		}
		balance = parseInt(balance, 10) + parseInt(interest, 10) - parseInt(payment, 10);
		paymentCount = paymentCount + 1;
	}
	return paymentCount;
}
function calcPayments(balance, term, pRate){
	var temp1, paymentValue;

	temp1 = Math.pow((pRate + 1), term);
	paymentValue = ( balance / ( (1/pRate) - ( 1/(pRate * temp1)) ) );
	return parseFloat(paymentValue);
}