// initial page state - used to determine whether to hide the default page text/assets 
var mini_details_restore = "Select a unit to view floor plan";

var oMap = oMiniDetails = oFloorDetails = oBaseContent = oTxtResidences = oTxtSqFt = oTxtBedrooms = oBathrooms = oFloorPlan = null;
var oLastActive = null;

var bBaseView = true;

// lists of matching units per type
var unit_types = new Array();
	unit_types['-1'] = [''];
	unit_types['A1'] = ['101, 202, 303, 354, 356, 403, 454, 456, 503, 554, 556']; // updated
	unit_types['A1a'] = ['204, 307, 407, 507']; // updated
	unit_types['B1'] = ['309, 359, 409, 459']; //updated
	unit_types['B1a'] = ['401, 451']; //updated
	unit_types['B2'] = ['201, 251, 301, 351']; //updated
	unit_types['B3'] = ['151, 152, 252, 253, 306, 353, 357, 406, 453, 457, 506, 553, 557']; // updated
	unit_types['B4'] = ['203, 305, 405, 505'];//updated
	unit_types['B4a'] = ['102'];//updated
	unit_types['B5'] = ['153, 254']; //updated
	unit_types['C1'] = ['308, 358, 408, 458']; //udpated
	unit_types['C1a'] = ['402, 452']; //udpated
	unit_types['C2'] = ['302, 352']; //udpated
	unit_types['C3'] = ['304, 404, 504']; //updated
	unit_types['C4'] = ['355, 455, 555']; // updated
	unit_types['D1'] = ['509, 559']; //updated.
	unit_types['D1a'] = ['501, 551']; //updated.
	unit_types['E1'] = ['508, 558']; //updated
	unit_types['E1a'] = ['502, 552']; //updated

// unit specific details
var unit_details = new Array();
	// square feet, bedrooms, bathrooms
	unit_details['-1'] = ['', '', '', ''];
	unit_details['A1'] = ['961', '2', '2', 'Savor the cold, wintry evenings in front of your cozy fire. In warmer weather, the deck adjacent to your living room extends your entertaining space.'];
	unit_details['A1a'] = ['945', '2', '2', 'Savor the cold, wintry evenings in front of your cozy fire. In warmer weather, the deck adjacent to your living room extends your entertaining space.'];
	unit_details['B1'] = ['1135', '2', '2', 'Awash with light, this lovely home is the perfect retreat at the end of a day of skiing. Two decks, one accessible from the master bedroom, the other from both the dining area and second bedroom, offer additional warm-weather living space.'];
	unit_details['B1a'] = ['1142', '2', '2', 'Awash with light, this lovely home is the perfect retreat at the end of a day of skiing. Two decks, one accessible from the master bedroom, the other from both the dining area and second bedroom, offer additional warm-weather living space.'];
	unit_details['B2'] = ['1145', '2', '2.5', 'A generous entertaining space with a cozy fireplace makes this a wonderful home to share with family and friends. The master bedroom has its own deck and a second deck is accessible from the living room.'];
	unit_details['B3'] = ['1217', '2', '2', 'With a fireplace in both the master bedroom and generously proportioned living room and dining area, this home is a particularly comfortable oasis after a day on the slopes. When the weather warms up, step out on your private deck and enjoy the fresh mountain air.'];
	unit_details['B4'] = ['1196', '2', '2', 'Dramatic angles and two decks that are accessible from either end of the living/dining room make this a truly unique mountain home and a gracious setting for year-round entertaining.'];
	unit_details['B4a'] = ['1205', '2', '2', 'Dramatic angles and two decks that are accessible from either end of the living/dining room make this a truly unique mountain home and a gracious setting for year-round entertaining.'];
	unit_details['B5'] = ['1541', '2', '2', 'Versatile and spacious, this two-bedroom home features a den that can double as a third bedroom. Two decks, a fireplace, panoramic views, a generously proportioned master bedroom and extra closet space make this home as comfortable as it is appealing.'];
	unit_details['C1'] = ['1375', '3', '2.5', 'Here\'s an amply proportioned home with plenty of room for family and friends. A large deck off the dining area and master bedroom offers additional entertaining space. A second deck off another bedroom provides a quiet retreat.'];
	unit_details['C1a'] = ['1385', '3', '2.5', 'Here\'s an amply proportioned home with plenty of room for family and friends. A large deck off the dining area and master bedroom offers additional entertaining space. A second deck off another bedroom provides a quiet retreat.'];
	unit_details['C2'] = ['1385', '3', '3', 'Ample common spaces, two decks, generous closet space, and three full bathrooms make this a very comfortable second home to enjoy with family and friends. Gather round the fire in the evening, kick back and watch a movie, or savor the sight of moonlight on new-fallen powder.'];
	unit_details['C3'] = ['1604', '3', '3', 'This spacious home boasts both roomy common spaces and a particularly luxurious master bedroom with a private deck, fireplace and generous closet area. Three full bathrooms, light-infused interiors and another deck off the living room make this a very comfortable retreat for the whole family.'];
	unit_details['C4'] = ['1455', '2', '2', 'Just imagine returning to this spacious home after a day of the region\'s finest powder skiing! Take in the spectacular view, or just curl up in front of the fire. Three bedrooms and three bathrooms offer plenty of room for family and friends. Two decks and a second fireplace in the master bedroom are included.'];
	unit_details['D1'] = ['1508', '3+Loft', '3', 'This three-bedroom, three-bathroom home features a versatile loft that can accommodate additional guests or expand your entertaining space. With two decks accessible from the bedrooms and a fireplace in the living room, this home has loads of light, warmth and views.'];
	unit_details['D1a'] = ['1527', '3+Loft', '3', 'This three-bedroom, three-bathroom home features a versatile loft that can accommodate additional guests or expand your entertaining space. With two decks accessible from the bedrooms and a fireplace in the living room, this home has loads of light, warmth and views.'];
	unit_details['E1'] = ['1822', '4+Loft', '3.5', 'With four bedrooms, three and one half bathrooms and a loft that can double as a bedroom, this home is the largest available at Thunder Mountain Lodge.  With two decks, fabulous vistas, a fireplace and an ample living/dining room, this is a place your family and friends will enjoy, year after year.'];
	unit_details['E1a'] = ['1843', '4+Loft', '3.5', 'With four bedrooms, three and one half bathrooms and a loft that can double as a bedroom, this home is the largest available at Thunder Mountain Lodge.  With two decks, fabulous vistas, a fireplace and an ample living/dining room, this is a place your family and friends will enjoy, year after year.'];

function highlightUnit(id) {
	//var sSrc = '../images/dia_' + flr + '_' + id + '.gif';
	//oMap.src = sSrc;
	oMiniDetails.innerHTML = rollover_data[id][0];
}

function highlightNonResidence(id) {
	var sSrc = '../images/dia_' + flr + '_' + id + '.gif';
	oMap.src = sSrc;
	oMiniDetails.innerHTML = rollover_data[id][0];
}

function restore() {
	if(oLastActive != null) {
		oMap.src = '../images/dia_' + flr + '_' + oLastActive + '.gif';
	}
	oMiniDetails.innerHTML = mini_details_restore;
}

function showUnitDetails(id) {
	if(bBaseView) {
		oBaseContent.style.display = 'none';
		oFloorDetails.style.display = 'block';
		oDownloadPlansContainer.style.display = 'block';
		oDownloadElevationsContainer.style.display = 'none';
		oDownloadSitePlanContainer.style.display = "none";
		bBaseView = false;
	}

	oLastActive = id;
	
	var sSrc = '../images/dia_' + flr + '_' + id + '.gif';

	oMap.src = sSrc;

	// retrieve unit type
	var unit = rollover_data[id][1];
	
	// string is used to describe square feet but should not be displayed 
	// when the unit being hovered over is a lobby, driveway or other non-residence
	var sApprox = ' approximately';
	if(unit == '-1') { 
		sApprox = '';
		oDownloadUnitPlanContainer.style.display = 'none';
		bBaseView = true;
	}

	oTxtResidences.innerHTML = unit_types[unit];
	oTxtSqFt.innerHTML = unit_details[unit][0] + sApprox;
	oTxtBedrooms.innerHTML = unit_details[unit][1];
	oTxtBathrooms.innerHTML = unit_details[unit][2];
	oUnitDescription.innerHTML = unit_details[unit][3];
	
	oUnitPlanLink.href = 'unit_plans/TML_UnitPlans_' + rollover_data[id][1] + '.pdf';
	
	if(unit != '-1') {
		// if this is a sub type (eg, B4a), remove "a" because unit graphics are shared between major and sub types
		oFloorPlan.src = '../images/floorplan_' + unit + '.gif';
	} else {
		oFloorPlan.src = '../images/floorplan_placeholder.gif';
	}
}

function init_diagram() {

	// initialize objects
	oMap = document.getElementById('diagram');
	oMiniDetails = document.getElementById('mini-details');
	oBaseContent = document.getElementById('base-content');
	oFloorDetails = document.getElementById('floor-details');
	oTxtResidences = document.getElementById('txt-residences');
	oTxtSqFt = document.getElementById('txt-sqft');
	oTxtBedrooms = document.getElementById('txt-bedrooms');
	oTxtBathrooms = document.getElementById('txt-bathrooms');
	oFloorPlan = document.getElementById('floor-plan');
	oUnitPlanLink = document.getElementById('unit-plan');
	
	oDownloadPlansContainer = document.getElementById('download-plans');
	oDownloadElevationsContainer = document.getElementById('download-elevations');
	oDownloadSitePlanContainer = document.getElementById('download-site-plan');
	
	oUnitDescription = document.getElementById('unit-description');
	// attach mouse events
	oAreas = document.getElementsByTagName('AREA');
	for(var i=0; i<oAreas.length; i++) {
		oAreas[i].onmouseover = function() { highlightNonResidence(this.id) }
		oAreas[i].onmouseout = function() { restore() }
		if(!isNaN(oAreas[i].id.substring(-3))) {
			oAreas[i].onclick = function() { showUnitDetails(this.id); return false; }
		} else {
			//oAreas[i].onmouseover = function() { highlightNonResidence(this.id) }
		}
		oAreas[i].onfocus = function() { this.blur() }
	}
	
	// preload diagrams
	preloadImages();
}

function preloadImages() {
	var over, out;
	var sBasePath = '../images/';
	for(var i=0; i<diagram_images.length; i++) {
		out = new Image();
		out.src = sBasePath + 'smnu_' + diagram_images[i] + '.gif';
		window[diagram_images[i]] = out;

		over = new Image();
		over.src = sBasePath + 'smnu_' + diagram_images[i] + '_h.gif';
		window[diagram_images[i] + '_h'] = over;
	}
}	


addEvent(window, "load", init_diagram);