// JavaScript Document

$(document).ready(function () {
	function showIt(div) {
		defaults = '';
		if(div.indexOf("&") > 0)
		{
			defaults = div.substring(div.indexOf("&"));
			div = div.replace(defaults, '');
		}
		
		$("#column_holder").hide();
		// hide others
		$("div#floorplans div").hide();
		$("ul#floorplan_nav li a").removeClass("currentPage");
		
		// show new one
		html = $(div).html();
		$(div).html('').show();
		$(div).html(html);
		$(div + " div").not(div + " div.tourWrapper").show();
		$(div + " iframe.fpm").attr('src', $(div + " iframe").attr('src') + defaults);
		$("li a." + div.replace(/#/, '')).addClass("currentPage");
		$("a.tour").fancyZoom({directory: "images/fancyzoom", width:800, height:556});
	}

	// Hide elements which were visible for non-javascript users
	$("div#floorplans div").hide();
	
	// Check if linking to current floorplan
	url = window.location.href;
	
	if(url.indexOf("#") > 0)
	{
		url = url.substring(url.indexOf("#"));
		showIt(url);	
	}
	
	// activate unit links
	$("ul#floorplan_nav li a").add("div.preview a").click(function () {
		var div = $(this).attr('href');
		
		showIt(div);
		
		// take outline focus off of clicked link
		$(this).blur();
		
		// disable default functionality
		return false;
	});
	
	// Start off by clicking in unit a
	// $("ul#floorplan_nav li a:first").click();
});

