$(document).ready(function() {

	$('table#floor_plans a').floor_plan("floor_plans");

	var path = window.location.pathname;
	if (path.indexOf("/", 1) > -1) path = path.substr(0, path.indexOf("/", 1));
	var active = $('#nav a[href="'+path+'"]');
	if (active.length > 0) {
		active = active.addClass("active").children("img");
		active.attr("src", active.attr("src").replace(/_off/, "_on"));
	}

});

jQuery.fn.floor_plan = function(type) {
	$(this).click(function() {
		var plan = $('#floor_plan img').attr("src", $(this).attr("href")).attr("src").replace(/plans\/([a-z0-9_]+)\.jpg/i, '$1');
		
		if((plan == "L3_1") || (plan == "L3_2")) plan="L3";
		if((plan == "L4_1") || (plan == "L4_2")) plan="L4";
		
		$('#floor_plan a[@href^="pdf/"]').attr("href", "pdf/Tremont_"+plan+".pdf");
		
		$('table#'+type+' tr[class*="active"]').removeClass('active');
		$(this).parent().parent().addClass("active");
		return false;
	});
	return $(this);
};
