/*
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);

// image preloader 
jQuery.preloadImages = function() {
  for(var i = 0; i<arguments.length; i++) {
    jQuery("<img>").attr("src", arguments[i]);
  }
}
$.preloadImages("/images/HomeGauge_software-2.gif", "/images/home-inspector-2.gif",
"/images/real-estate-pro-2.gif", "/images/buyer-seller-2.gif");

// image rollover function -- img class set to roll, end rollover filename *-2.*
$(document).ready(function() {
  $("img.roll").hover(function() {
    $(this).attr("src", $(this).attr("src").split(".").join("-2."));
  }, function() {	
    $(this).attr("src", $(this).attr("src").split("-2.").join("."));
  });
});

// drop down menus
$(document).ready(function() {
    //$(".expanded").animate({ opacity:.95 });
	$("#menu ul li:has(div)").children("div").css("display", "none");	
	function over(){ $(this).children("div").fadeIn("fast");}
	function out(){	$(this).children("div").css("display", "none");}
	$("#menu ul li:has(div)").hoverIntent(over,out); 
  
   $(".expanded").hover(function()
  {
	$(this).parent().css("background-color", "#4D4D4D"); 
	$(this).prevAll().css("color", "#FFFFFF"); 
	$(".dashboard").css("color", "#FBB256");
}, function() {
	$(this).parent().css("background-color", "");
	$(this).prevAll().css("color", "");
	$(".dashboard").css("color", "#FBB256");
  });

//hide submenu in IE 6 if javascript is enabled
  $("#submenu").hide(); 
});

// home page clear zip field
$(document).ready(function() {
  $("#zipSearch").click(function() {
  	 $(this).attr("value", "");
  });	
});

//sign in form - hide/show
$(document).ready(function() {
	$("#signin").hide();
	$("a.close").css("display", "inline");
	$("a.sign-in-link").attr("href", "#top");
	$(".sign-in-link").click(function()	{
		$("#sign-in-tab").css("background-color", "#555").css("background-image", "url(/images/sign-in2.gif)");
		$("#signin").slideToggle("slow");
	});	
	
	$(".close").click(function() {
		$("#signin").slideUp();
	});	
	$("#focus").focus();
});

//comments + gateway form -- hides submit button after click 
$(document).ready(function() {
	$("#commenter input.submit").click(function()
	{
		$(this).css("display", "none");
 	});
	$("#gateway").click(function()
	{
		$(this).css("display", "none");
 	});
	$("#commenter textarea.comment-form").click(function()
	{
		$(this).css("background-color", "#EAEEEE");
 	});
});

//limit maxlength on textarea
function lengthLimit(textfield,limit) {
		var text = $(textfield).val();
		var textlength = text.length;
		if(textlength > limit)
		{
			$(textfield).val(text.substr(0,limit));
			return false;
		}
	}
$(document).ready(function() {
	$(function() {
		$('#commenter textarea').keyup(function()
		{
			lengthLimit('#commenter textarea',1000);
		})
	});	
	$(function() {
		$('#reptext').keyup(function()
		{
			lengthLimit('#reptext',80);
		})
	});	
});

//check for caps lock 
$(document).ready(function() {
$('#top, #tophome').append('<div class="capslock" style="display:none;text-align:center;position:absolute;z-index:1000;clear:both;top:0"><div style="border:solid 3px #fcb55d;width:757px;padding:19px;background-color:#fdfde8;text-align:center;"><strong>CAPS LOCK is ON:</strong> Your HomeGauge Password is Case Sensitive. <span class="hidecaps" style="cursor:pointer; text-decoration:underline; color:#00F;font-weight:bold;">[X]</span></div></div>');

$('input[name=password]').keyup(function(e) { 
        var s = $(this).val().toString();
		var caplock = "no";
		if ( (s.toUpperCase() == s) && (s.toLowerCase() != s) && (!e.shiftKey) ) {
				var caplock = "yes";
			} else { 
				var caplock = "no"; }
		if ( (caplock == "yes") && (e.keyCode == 20) ) {
				caplock = "no";
			}
		if ( (e.keyCode != 8) && (e.keyCode != 16) ) {
			if  (caplock == "yes")  {
					$('.capslock').slideDown();		
				} 
			if (caplock == "no") {
					$('.capslock').slideUp();					
				}
			}		
	});
$('.hidecaps').click(function()
	{
		$('.capslock').slideUp();
 	});
});