
function track(url) {
    firstTracker._trackPageview(url);
    secondTracker._trackPageview(url);
}




jQuery(document).ready(function($){
	// HOVER
	$("#nav a").hover( 
		// over
		function(){

			var theImg = $(this).find('img:first');
			// store the original image src
			theImg.data( "originalsrc" , theImg.attr("src") );
			
			// add -over to the image unless it is already -over
			if (!theImg.attr("src").match(/-over/) ) {
				theImg.attr( "src", theImg.attr("src").replace(/\./, "-over.") );
			}
			
		},
		
		// out
		function(){
			var theImg = $(this).find('img:first');
			// replace the original src
			theImg.attr("src", theImg.data("originalsrc")).data("originalsrc", null);
		}
	);
	
	// auto complete
	$(".findHomeContainer #subdivision").autocomplete('/cgi-bin/listings_v2/subdivision_autocomplete.cgi');
	$(".findLandContainer #subdivision").autocomplete('/cgi-bin/listings_land_v2/subdivision_autocomplete.cgi');
	$(".findHomeContainer #city").autocomplete('/cgi-bin/listings_v2/city_autocomplete.cgi');
	$(".findLandContainer #city").autocomplete('/cgi-bin/listings_land_v2/city_autocomplete.cgi');
	$(".findHomeContainer #address").autocomplete('/cgi-bin/listings_v2/address_autocomplete.cgi');
	$(".findLandContainer #address").autocomplete('/cgi-bin/listings_land_v2/address_autocomplete.cgi');
	$(".findHomeContainer #school").autocomplete('/cgi-bin/listings_v2/school_autocomplete.cgi');
	$(".findLandContainer #school").autocomplete('/cgi-bin/listings_land_v2/school_autocomplete.cgi');

	// featured projects
	$("#featuredProjectsLink").click(function(e){
		e.preventDefault;
		$("#featuredProjects").stop(true, true).slideDown();
		return false;
	});
		
	$("#featuredProjects").mouseleave(function(){
		$("#featuredProjects").stop(true, true).slideUp();
	});
	
	
	$("#multipleAreas").click(function(e){
		e.preventDefault;
		$("select[name=area]").slideUp().attr("multiple", "multiple").slideDown();
		$(this).replaceWith("<small>control-click to select multiple</small>");
	});
	
	
	// clear text fields
	$(".fancyField").each(function(){
		var field = $(this);
		field.data('originalValue', field.attr('value'));
		
		field.bind('focus', function(){
			if (field.attr('value') == field.data('originalValue')) {
				field.attr('value', '');
			}
		});
		
		field.bind('blur', function(){
			if (field.attr('value') == '' ) {
				field.attr('value', field.data('originalValue'));
			}
		});
		
	});
	
	// must use jQuery 1.4.0 with this for now!
	$('.tip').qtip({ 
		style: { 
			background: '#E2E0D0',
			border: {
        		width: 1,
         		color: '#114828'
      		},
			color: '#000000',
			name: 'green',
			tip: true
		} 
	});
	
	
});

window.onload = function() {
		// preload
		$("#nav a img").each(
			function() {
				if (!$(this).attr("src").match(/-over/) && !$(this).attr("src").match(/-active/) ) {
					$("<img>").attr( "src", $(this).attr("src").replace(/\./, "-over.") );
				}
			}
		);
}
