// wait until the document is ready, then load stuff
$(document).ready(function(){

	// hide the submenu, then show it when someone hovers over a list item
	$("#menu li ul").hide();
	$("#menu li").hover(
		function(){
			$(this).find("ul:first").css({
				visibility: "visible"
			}).slideDown(25);
		}, function(){
			$(this).find("ul:first").css({
				visbility: "hidden"
			}).slideUp(25);
	});

	// initialize the gallery(s)
	$(".gallery").cycle({
		fx: "fade",
		speed: 1000,
		timeout: 4000
	});

	// initialize the overlay(s)
	$("a[rel]").overlay({
		closeOnClick: true,
		closeOnEsc: true,
		top: "center",
		left: "center",	
		mask: "#fff"
	});

	// initialize the scroller(s)
	$(".scrollable").scrollable({
		circular:true
	});
});

// create preloader for images
$.fn.preload = function(){
	this.each(
		function(){
			$("<img/>")[0].src = this;
	});
};

// preload hover images (so they do not flash on initial hover)
$([
// menu link images
"images/menu/btn-hover-aboutus.png",
"images/menu/btn-hover-communities.png",
"images/menu/btn-hover-homesavailablenow.png",
"images/menu/btn-hover-floorplancollection.png",
"images/menu/btn-hover-buildonyourlot.png",
"images/menu/btn-hover-designcenter.png",
// general two header links
"images/link/btn-link-hover-home.png",
"images/link/btn-link-hover-contactus.png",
// social link images
"images/social/btn-social-hover-facebook.png",
"images/social/btn-social-hover-twitter.png",
"images/social/btn-social-hover-linkedin.png",
"images/social/btn-social-hover-rss.png",
// front page images
"images/front/btn-mid-hover-viewcommunities.png",
"images/front/btn-mid-hover-homesavailablenow.png",
"images/front/btn-mid-hover-floorplancollection.png",
"images/front/btn-mid-hover-designcenter.png",
// images on pages
"images/pages/btn-hover-homesavailablenow.png",
"images/pages/btn-hover-floorplansavailable.png",
"images/pages/btn-hover-designcenter.png",
"images/pages/btn-hover-viewcommunities.png",
"images/pages/bar-hover-community.png",
"images/pages/bar-hover-floorplan.png",
"images/pages/bar-hover-virtualtour.png",
"images/pages/bar-hover-printable.png",
"images/pages/bar-hover-homes.png",
// submenu arrow for the menu
"images/facebook.png",
"images/facebook_hover.png",
"images/arrow.png"
]).preload();
