


$(document).ready(function(){
	
			// fix "external" links to open in new window									 
		$('a[rel="external"]').click(function(){
			window.open(this.href);
			return false;
		}).attr('title', 'Opens in New Window or Tab');

	
	// load slide from # (hash)
	var hashSlide = parseInt(window.location.hash.slice(1, window.location.hash.length) );
	if ( hashSlide > 0 ) {
		hashSlide--;
	} else {
		hashSlide = 0;
	}
	
	$("#home-slideshow").cycle({
		pause:1,
		speed:500,
		timeout:5000,
		after:onAfterHome,
		startingSlide:hashSlide
	});
	
	$(".top-row a").click(function(){
	});
	$(".top-row-home a").click(function(){
		var newSlide = parseInt( $(this).attr("rel") );
		$("#home-slideshow").cycle( newSlide-1 );
		return false;
	});

	// floorplan image control
	$('#floorplan-names').tabs({ 
		fxFade: true, 
		fxSpeed: 'fast', 
		fxAutoHeight: true 
	});
	
	
	// gallery slideshow
	
	$("#gallery-1").cycle({
		pause:1,
		speed:500,
		timeout:5000,
		pager:"#gallery-pager",
		prev:"#gallery-prev",
		next:"#gallery-next",
		after:onAfterGallery
	});
	$("#gallery-2 a").click(function(){
		$myListParent = $(this).parent().parent();
		var myIndex = $myListParent.parent().children().index($myListParent);
		$("#gallery-1").cycle( myIndex );
		return false;
	});
	

	$("#inquire-form").validate();
	
});

function onAfterHome(curr,next,opts) {
	var curSlide = opts.currSlide + 1;
	$(".top-row").removeClass("active");
	$("#top-row-"+curSlide).addClass("active");
}

function onAfterGallery(curr,next,opts) {
	var curSlide = opts.currSlide + 1;
	$("#gallery-2").children().removeClass("active");
	$("#gallery-2").children().eq(curSlide-1).addClass("active");
}

