
jQuery(document).ready(function($){
/**
 * Disabled this functionality due to colorbox compatibility problem
 * for external links, open in new window
  $('a[href^=http]').click( function() {
    window.open(this.href);
    return false;	    
  });
 *
 */
}); 
;
jQuery(document).ready(function() {
	var sidebar = jQuery("body.front #sidebar-first");
	var col = "collapsed";
	var speed = 1000;
	var clickTo = "<p id='clickTo'>Click here to</p>";
	
	var downArrow = jQuery("#find-home-click-toggle img").attr('src');
	var rightArrow = downArrow;
	if (rightArrow != null) {
		var rightArrow = rightArrow.replace('arrow.png', 'arrow_right.png');
	}
	
	var origH = sidebar.height();
	var origW = sidebar.width();
	
	var setToH = jQuery("body.front #block-block-19").height();
	setToH = (setToH + 25);
	var setToW = jQuery("body.front div#block-block-19 .block-inner").width();
	setToW = (setToW + 0);
	
	// Because browsers can't measure width accurately:
	setToW = 280;
	
	sidebar.height(setToH);
	sidebar.width(setToW);
	sidebar.addClass(col);
	jQuery("#find-home-click-toggle img").attr('src', rightArrow);
	jQuery("#find-home-click-toggle").append(clickTo);
	
	jQuery("body.front #find-home-click-toggle").click(function() {
		if (sidebar.hasClass(col)) {
			sidebar.animate({
				height: (origH + "px"),
				width: (origW + "px")
			}, speed, function() {
				sidebar.removeClass(col);
				jQuery("#find-home-click-toggle img").attr('src', downArrow);
				jQuery("#find-home-click-toggle #clickTo").remove();
			});
		}
		else {
			sidebar.animate({
				height: (setToH + "px"),
				width: (setToW + "px")
			}, speed, function() {
				sidebar.addClass(col);
				jQuery("#find-home-click-toggle img").attr('src', rightArrow);
				jQuery("#find-home-click-toggle").append(clickTo);
			});
		}
	});
});
;
jQuery(document).ready(function() {
	jQuery("#aa_button").click(function() {
		jQuery("#content").toggleClass('bigText');
	});
	jQuery("#print_button").click(function() {
		print();
	});
});
;
jQuery(document).ready(function() {
	jQuery("#webform-client-form-408 #edit-submit").hide();
	jQuery("#webform-client-form-408 #calc-button").click(function() {
		calcPaym(0);
		return false;
	});
});

var irate, mi, cmi, years, tprinc, princ, paym, cpaym, osp,v,downp,downr,comp;
function calcPaym(cdn){
   tprinc = jQuery("input[name$='[tprinc]']").val();
	 console.log (tprinc);
   tprinc = cleanIt(tprinc);
   if (tprinc == false) {
   	return false;
   }
	 console.log (tprinc);
   tprinc = round2d(parseFloat(tprinc));
   
   downp = jQuery("input[name$='[downp]']").val();
   downp = cleanIt(downp);
   if (downp == false) {
   	return false;
   }
   downp = .01*parseFloat(downp);
   
   downr = ceil2d(downp*tprinc);
   princ = tprinc-downr;
   
   jQuery("input[name$='[princ]']").val(fmt2d(princ,0));
   jQuery("input[name$='[downr]']").val(fmt2d(downr,0));
   
   if(cdn)comp="Canadian"; else comp="U.S";
   jQuery("input[name$='[comp]']").val(comp);
   
   irate = jQuery("input[name$='[percent]']").val();
   irate = cleanIt(irate);
   if (irate == false) {
   	return false;
   }
   irate = .01*parseFloat(irate);
   
   years = jQuery("input[name$='[term]']").val();
   years = cleanIt(years);
   if (years == false) {
   	return false;
   }
   years = parseFloat(years);
   
   term = jQuery("input[name$='[term]']").val();
   term = cleanIt(term);
   if (term == false) {
   	return false;
   }
   term = parseFloat(term);
  
   if(term > years)term=years;
   
   if (term==0 || years==0||irate<.0001||princ<1)
   {alert("values must be numeric");}
   else 
   {
       if(cdn)mi = Math.pow(1+ irate/2,1/6) 
       else   mi = 1+(irate/12);
       v = 1/mi;
       paym = ceil2d(princ*(mi-1)/(1-Math.pow(mi,-(years*12))));
       osp = (princ-(v*paym*(1-Math.pow(v,12*term)))/(1-v))/Math.pow(v,12*term);
       if(osp<0)osp = 0;
       
       jQuery("input[name$='[paym]']").val(fmt2d(paym,0));
       //jQuery("input[name$='[owed]']").val(fmt2d(osp,0));
   }
   return false;
}
function round2d(n){return(.01* Math.round(100*n));}
function floor2d(n){return(.01* Math.floor(100*n));}
function ceil2d(n){return(.01* Math.ceil(100*n));}
// format number n as string width w with 2 decimal places
function fmt2d(n,w)
{
   var work,dp,sl,dl;
   
   work = ""+floor2d(n); // force only 2 decimals
   sl=work.length;
   
   if(-1 == (dp = work.indexOf(".")))work=work+".00";
   else if(3 > sl-dp)work = work+".00".substring(sl-dp,3);
   sl = work.length;
   if(0 != w && w !=sl)
      if(w<sl){work = "*";for(sl=1;sl<w;sl++)work=work+"*";}
      else for(;sl<w;sl++)work=" "+work; 
   return work;
}
function cleanIt(input) {
	if(input != null){
		input = input.replace(",","");
		input = parseFloat(input);
	}
	if (typeof(input) == "number") {
		console.log((input + " is a number"));
		return input;
	}
	else if (typeof(input) == "string") {
		alert((input + " is not a valid number."));
		return false;
	}
}
;
jQuery(document).ready(function() {
	dirFunc();
});

function dirFunc() {
	(function($){
		var dirList = $("#direction").children();
		var direction = new Array();
		if ((dirList.length > 0)) {
			for (var x = 0; x < dirList.length; x += 2)
			{
			 	var y = x/2;
				direction[y] = dirList[x];
				direction[y]["direction"] = dirList[x+1];
			}
		
			$("#dirMenu").html('<select id="startLoc">');
			$("#direction").html(direction[0]["direction"]);
		
			for (var x = 0; x < direction.length; x++)
			{
				var option = $("<option>").attr('title', x).append(direction[x].textContent);
				if ($.browser.msie) {
					var option = $("<option>").attr('title', x).append(direction[x].innerText);
				}
				$("#startLoc").append(option);
			}
			$("#startLoc").change(function(option){
				var lctnNum = $("#startLoc option:selected").attr('title');
				$("#direction").html(direction[lctnNum]["direction"]);
			}); 
		}
	})(jQuery);
};
jQuery(document).ready(function() {
	jQuery(".comm-container.has-both .plan").hide();
	jQuery(".comm-container.has-both .mv-button").addClass("activeButton");
	
	jQuery(".comm-container.has-both .hd-button").click(function() {
		var parent = jQuery(this).parent();
		parent.find(".mv-button").removeClass("activeButton");
		jQuery(this).addClass("activeButton");
		parent.parent().find(".spec_home").hide();
		parent.parent().find(".plan").show();
		return false;
	});
	jQuery(".comm-container.has-both .mv-button").click(function() {
		var parent = jQuery(this).parent();
		parent.find(".hd-button").removeClass("activeButton");
		jQuery(this).addClass("activeButton");
		parent.parent().find(".plan").hide();
		parent.parent().find(".spec_home").show();
		return false;
	});
	
	jQuery(".pager-table").hide();
	jQuery(".pager-table-0").show();
	
	jQuery(".pager-controls ul li a").click(function() {
		var num = (jQuery(this).text() - 1);
		num = (".pager-table-" + num);
		jQuery(this).parents(".homes-container").find(".pager-table").hide();
		jQuery(this).parents(".homes-container").find(num).show();
		return false;
	});
});
;

