﻿// JavaScript Document
// floorplan.js
// Andy Rova
// andy@rovaconsulting.com
// last revised Nov. 7, 2007
//-----------------------------------------------------------------------------
var flashCallNumber = new String();
var curNumber = new String();

$(document).ready(function(){
	//alert($(this).first);
	$("#floorplanToggleButton").hide(); // button not visible to start
	$("#residenceInfo").load("residenceList.html #emptyResInfo");	// hide the "Javascript required..." message
	// set the onclick() function for each of the residence types:
	$("#typeList li a").each(
		 function() {
			 $(this).click(
				 function() { // executes on residence-type link click:
						document['flash'].call2Flash($(this).parent().attr("id"));
						$("#typeList li").removeClass("current");  // remove any other link highlights
						// show the Flash model and hide the floorplan button and residence list div:
						showFlashModel();
						$("#residenceList").hide();
						$("#floorplanToggleButton").hide();
						$("#residenceInfo").load("residenceList.html #emptyResInfo");	// reset the residence info
						$(this).parent().toggleClass("current");  // highlight the current link
						// prepare AJAX call:
						var loadStr = "residenceList.html #" + $(this).parent().attr("id").toString();
						$("#residenceList").load(loadStr,  // replace div content with loaded HTML...
											function() { // and when it finishes...
												// set the links' IDs:
												$("#residenceList a").attr("id", function() {
													return "res" + $(this).text();
													});
												// ...and onclick() functions:
												$("#residenceList a").click(showResInfo);
											}
						).show();
						// finally, show the residenceList div
						return false;
				 }); // end click() anonymous function
		 }); // end each() anonymous function
	$("#floorplanToggleButton").click(toggleFloorplanView); // setup button onclick() handler
}); // end ready() anonymous function

//-----------------------------------------------------------------------------

function showResInfo() {
	// Called when a residence number from the list is clicked
	// "this" is the link object
	
	var floorPlanImgSuffix = '.gif';
	
	showFlashModel();				// hide the floorplan overlay
	//*****************************************************
	// added to deal with late unit number changes: Flash is expecting extra zeros, e.g. unit 11 must call SWF as 101
		curNumber = $(this).attr("id").substring(3);
		// also translate these unit numbers:
		if(curNumber == '53') {
			flashCallNumber = '502';
		}
		else if(curNumber == '54') {
			flashCallNumber = '503';
		}
		else if(curNumber == '63') {
			flashCallNumber = '602';
		}
		else if(curNumber == '64') {
			flashCallNumber = '603';
		}
		else {
			flashCallNumber = curNumber.charAt(0) + '0' + curNumber.charAt(1);
		}
		document['flash'].callFlash(flashCallNumber);
	//*****************************************************
	
	$("#residenceList a").removeClass("current"); // get rid of any highlights on the residence number links
	resetFloorplanToggleButton(); 	// make button display "VIEW FLOORPLAN"
	$(this).addClass("current");	// highlight the current residence number link
	$("#residenceInfo").load("residenceList.html #" + $(this).attr("id") + "Info"); // load the residence info
	$("#floorplanToggleButton").show(); // show the button
	showFlashModel();				// hide the floorplan overlay
	
	$('#downloadPDFLink').attr('href', getPDFPath(curNumber));// set up the "Download PDF" link
} // end showResInfo()

//-----------------------------------------------------------------------------

function toggleFloorplanView() {
	// Called when the "VIEW FLOORPLAN" or "VIEW 3D MODEL" buttons are clicked
	if($("#floorplanOverlay").is(':visible')) {
		resetFloorplanToggleButton(); // make button display "VIEW FLOORPLAN"
		showFlashModel();
	}
	else {
		// if we are in the process of making the floorplan overlay visible,
		// then make the button show "VIEW 3D MODEL":
		$("#floorplanToggleButton").css("background-position", "0px -23px"); 
		hideFlashModel();
	}
	return false;
} // end toggleFloorplanView()

//-----------------------------------------------------------------------------

function resetFloorplanToggleButton() {
	// Sets floorplanToggleButton's image background to "VIEW FLOORPLAN"
	$("#floorplanToggleButton").css("background-position", "0px 0px");
}

//-----------------------------------------------------------------------------

function showFlashModel() {
	// Hides the floorplan overlay, allowing the Flash model below to display
	$("#flashModelContainer").css("visibility", "visible");
	$("#floorplanOverlay").css("visibility", "hidden");
	$('#floorplanOverlay #img' + curNumber).css('display', 'none');
}

//-----------------------------------------------------------------------------

function hideFlashModel() {
	$("#flashModelContainer").css("visibility", "hidden");
	$("#floorplanOverlay").css('visibility', 'visible');
	$('#floorplanOverlay #img' + curNumber).css('display', 'block');
}

//-----------------------------------------------------------------------------

function getPDFPath(curNumber) {
	var downloadPath = 'floorplans/Danielle_';
	switch(curNumber) {
		case 'sdf20':
		case '30':
		case '40':
		case '50':
		case '60':
			downloadPath += '20.30.40.PH50.PH60.pdf';
			break;
		case '21':
		case '31':
		case '41':
			downloadPath += '21.31.41.pdf';	
			break;
		case '22':
		case '32':
		case '42':
			downloadPath += '22.32.42.pdf';
			break;
		case '23':
		case '33':
		case '43':
		case '53':
		case '63':
			downloadPath += '23.33.43.53.63.pdf';
			break;
		case '34':
		case '44':
		case '54':
		case '64':
			downloadPath += '34.44.54.64.pdf';
			break;
		case '35':
		case '45':
		case '55':
		case '65':
			downloadPath += '35.45.55.65.pdf';
			break;
		case '51':
			downloadPath += 'PH51.pdf';
			break;
		case '61':
			downloadPath += 'PH61.pdf';
			break;
		default:
			downloadPath = downloadPath + curNumber + '.pdf';
			break;
	}
	return downloadPath;
}