jQuery( function() {
    homes = [{"bathrooms":"4","prop_sqft":"2,580","officename":"Fonville Morisey&Barefoot/Brighton Forest","state":"NC","tracking_id":"908847","details_url":"http://www.homefinder.com/NC/Fuquay-Varina/53554296d_2825_Oakley_Woods_Ln","image_thumbnail":"196070752_thm.jpg","city":"Fuquay-Varina","agentname":"Betty Taylor","image_carousel":"196070752_car.jpg","price":"329,968","bedrooms":"4"},{"bathrooms":"3","prop_sqft":"1,910","officename":"FMBMG Chruch St","state":"NC","tracking_id":"908848","details_url":"http://www.homefinder.com/NC/Morrisville/55298396d_1200_Checkerberry_Drive","image_thumbnail":"239995549_thm.jpg","city":"Morrisville","agentname":"Erica Turner","image_carousel":"239995549_car.jpg","price":"244,670","bedrooms":"3"},{"bathrooms":"3","prop_sqft":"1,371","officename":"Fonville Morisey&Barefoot/Governors Lake Townes","state":"NC","tracking_id":"908849","details_url":"http://www.homefinder.com/NC/Chapel_Hill/53784582d_1063_Perdue_Dr","image_thumbnail":"240002149_thm.jpg","city":"Chapel Hill","agentname":"Jonathan Stallings","image_carousel":"240002149_car.jpg","price":"213,570","bedrooms":"2"},{"bathrooms":"3","prop_sqft":"3,182","officename":"FMBMG Glen Lake South","state":"NC","tracking_id":"908850","details_url":"http://www.homefinder.com/NC/Raleigh/54281666d_8310_Bandford_Way","image_thumbnail":"1802748-1_thm.jpg","city":"Raleigh","agentname":"Premiere Homes","image_carousel":"1802748-1_car.jpg","price":"674,000","bedrooms":"3"},{"bathrooms":"4","prop_sqft":"3,706","officename":"Fonville Morisey&Barefoot/Abbington","state":"NC","tracking_id":"908851","details_url":"http://www.homefinder.com/NC/Apex/54345774d_2581_Bryant_Pond_Ln","image_thumbnail":"200558652_thm.jpg","city":"Apex","agentname":"Martha Nelson","image_carousel":"200558652_car.jpg","price":"579,900","bedrooms":"4"},{"bathrooms":"3","prop_sqft":"2,417","officename":"FMBMG Churchill","state":"NC","tracking_id":"908852","details_url":"http://www.homefinder.com/NC/Knightdale/56117078d_2129_Old_Rosebud_Drive","image_thumbnail":"238690671_thm.jpg","city":"Knightdale","agentname":"Adair Preston","image_carousel":"238690671_car.jpg","price":"215,965","bedrooms":"3"}];
    homes.sort(randOrd);

    top_homes_cnt = Math.min( 3, homes.length );

    for ( i = 0; i < top_homes_cnt; i++ ) {
	if ( i != 0 ) {
	    jQuery('#top-homes-content').append(
		  '<tr class="divider">'
		+   '<td colspan="2"><hr width="80%" size="1" /></td>'
		+ '</tr>'
	    );
	}
	jQuery('#top-homes-content').append(
	      '<tr>'
	    +   '<td class="top-home-image" onclick="window.location=\'' + homes[i].details_url + '\'"><img src="http://media.triangle.com/images/real_estate/' + homes[i].image_thumbnail + '" /></td>'
	    +   '<td class="top-home-info" onclick="window.location=\'' + homes[i].details_url + '\'">'
	    +     '<p><a href="' + homes[i].details_url + '">' + homes[i].city + ', ' + homes[i].state + '</a></p>'
	    +     '<p>' + homes[i].bedrooms + ' Bedrooms, ' + homes[i].bathrooms + ' Bathrooms</p>'
	    +     '<p>' + homes[i].prop_sqft + ' Square Feet</p>'
	    +     '<p>$' + homes[i].price + '</p>'
	    +   '</td>'
	    + '</tr>'
	);
    }

	jQuery('.top-home-image').mouseover(function() {
		jQuery(this).addClass('highlight');
		jQuery(this).next().addClass('highlight');
	}).mouseout(function() {
		jQuery(this).removeClass('highlight');
		jQuery(this).next().removeClass('highlight');
	});

	jQuery('.top-home-info').mouseover(function() {
		jQuery(this).addClass('highlight');
		jQuery(this).prev().addClass('highlight');
	}).mouseout(function() {
		jQuery(this).removeClass('highlight');
		jQuery(this).prev().removeClass('highlight');
	});

    /* custom functions */
    function randOrd() { return ( Math.round( Math.random() ) - 0.5 ); }
});
