﻿var sectionArray = new Array(6); // array of divs - navtop(0), navbottom(1), bodyleft(2), bodyrighttop(3), bodyrightbottom(4), footer(5), infobox(6)var viewArray = new Array(); // array of page views as viewClassesvar debugMode = false;var pageInitialized = false;var classRef = 'class';// Slideshow variablesvar nextImage = 1;var maxImage = 8;var backImage;var foreImage;var imageBase = 'media/millwood';// Image viewer variablesvar currentImage = 1;function pageInitialization(){	// Called from body(onload) - initializes variables and loads first page view	try{		if(!pageInitialized){			sectionArray[0]=document.getElementById('navigationtop');			sectionArray[1]=document.getElementById('navigationbottom');			sectionArray[2]=document.getElementById('bodyleft');			sectionArray[3]=document.getElementById('bodyrighttop');			sectionArray[4]=document.getElementById('bodyrightbottom');			sectionArray[5]=document.getElementById('footer');			sectionArray[6]=document.getElementById('infobox');			objectDetector();			viewArrayLoad();			eventInitialization()			backImage = document.getElementById('hrBackImage');			foreImage = document.getElementById('hrForeImage');			foreImage.style.opacity = 1;			pageInitialized = true;		}//PageDetails();		var viewChoice = 0;		var subviewChoice = 0;		if(document.location.search.indexOf('v=') > 0){			viewChoice = 1 * (document.location.search.charAt(document.location.search.indexOf('v=') + 2));		}		if(document.location.search.indexOf('sv=') > 0){			subviewChoice = 1 * (document.location.search.charAt(document.location.search.indexOf('sv=') + 3));		}		//alert('View, subview: ' + viewChoice + ', ' + subviewChoice);		viewChange(viewChoice);		if(subviewChoice > 0){			itemChange(viewChoice, subviewChoice);		}		var nextTime = setTimeout('headerSlideshow(1)',5000);	}	catch(caughtError){		if(debugMode){			alert('JavaScript error in pageInitialization:' + caughtError.message);		}	}}function PageDetails(){	alert('Location: ' + document.location); // full url, including http and search arguments	alert('Host: ' + document.location.host); // nothing for local file	alert('Hostname: ' + document.location.hostname); // nothing for local file	alert('Href: ' + document.location.href); // full url, including http and search arguments	alert('Pathname: ' + document.location.pathname); // full url, without http and without search arguments	alert('Search: ' + document.location.search); // full search string starting with '?'	alert('Referrer: ' + document.referrer);	//port	//protocol	alert('Last modified: ' + document.lastModified);}function objectDetector(){	classRef = 'class';	try{		var testArray = sectionArray[0].getElementsByTagName('SPAN');		var testResult = testArray[0].getAttribute('class');		if(testResult == null){			var testResult = testArray[0].getAttribute('className');					if(testResult != null){				classRef = 'className';					}		}	}	catch(caughtError){		if(debugMode){			alert('JavaScript error in objectDetector:' + caughtError.message);		}	}	//alert('classRef set to ' + classRef);}function subViewClass(inDiv){	try{		this.viewTitle='';		this.viewContent='';		for(var subViewNode=0;subViewNode<inDiv.childNodes.length;subViewNode++){			if(inDiv.childNodes[subViewNode].nodeName == 'H4'){				this.viewTitle = inDiv.childNodes[subViewNode];			}			else if(inDiv.childNodes[subViewNode].nodeName == 'DIV'){				this.viewContent=inDiv.childNodes[subViewNode];			}		}	}	catch(caughtError){		if(debugMode){			alert('JavaScript error in subViewClass:' + caughtError.message);		}	}}function viewClass(inDiv){	try{		this.viewTitle='';		this.viewContent='';		this.subViews=new Array();		for(var viewNode=0;viewNode<inDiv.childNodes.length;viewNode++){			var currentViewNode=inDiv.childNodes[viewNode];			if(currentViewNode.nodeName == 'H3'){				this.viewTitle = currentViewNode;			}			else if(currentViewNode.nodeName == 'DIV'){				if(this.viewContent==''){					this.viewContent=currentViewNode;				}				else{					for(var subViewNode=0;subViewNode<currentViewNode.childNodes.length;subViewNode++){						if(currentViewNode.childNodes[subViewNode].nodeName == 'DIV'){							try{								this.subViews.push(new subViewClass(currentViewNode.childNodes[subViewNode]));							}							catch(pushError){								// IE 5.0 does not recognize push (5.5+ does), so this is a workaround								//alert('Caught a push error - trying to overcome');								try{									this.subViews[this.subViews.length] = new subViewClass(currentViewNode.childNodes[subViewNode]);								}								catch(alternatePushError){									//alert('Apparently that did not work either');								}							}						}					}				}				}		}	}	catch(caughtError){		if(debugMode){			alert('JavaScript error in viewClass:' + caughtError.message);		}	}}function viewArrayLoad(){	try{		var contentDiv = document.getElementById('pagecontent');		var viewIndex = 0;			for(var contentNode=0;contentNode<contentDiv.childNodes.length;contentNode++){			if(contentDiv.childNodes[contentNode].nodeName == 'DIV'){				viewArray[viewIndex] = new viewClass(contentDiv.childNodes[contentNode]);				viewIndex++;			}		}	}	catch(caughtError){		if(debugMode){			alert('JavaScript error in viewArrayLoad:' + caughtError.message);		}	}}function eventInitialization(){	var infoElements = '';		try{		for (var headingNum=5;headingNum<7;headingNum++){			infoElements = document.getElementsByTagName('H' + headingNum);			for (var infoIndex=0;infoIndex<infoElements.length;infoIndex++){				if(infoElements[infoIndex].getAttribute(classRef)=='hasInfo'){					infoElements[infoIndex].onmouseover = infoboxShow;					infoElements[infoIndex].onmouseout = infoboxHide;				}			}		}	}	catch(caughtError){		if(debugMode){			alert('JavaScript error in eventInitialization:' + caughtError.message);		}	}}function viewChange(inView){	try{		// alert('viewChange(' + inView + ')');		for(var sectionIndex=2;sectionIndex<=4;sectionIndex++){			sectionClear(sectionArray[sectionIndex]);		}			var spanCount = 0;		for(var sectionChild=0;sectionChild<sectionArray[1].childNodes.length;sectionChild++){			if(sectionArray[1].childNodes[sectionChild].nodeName == 'SPAN'){				if(spanCount == inView){					sectionArray[1].childNodes[sectionChild].setAttribute(classRef,'navbottomitemselected');				}				else{					sectionArray[1].childNodes[sectionChild].setAttribute(classRef,'navbottomitem');				}				spanCount++;			}		}				sectionArray[3].appendChild(viewArray[inView].viewContent.cloneNode(true));		for(var subViewIndex=0;subViewIndex<viewArray[inView].subViews.length;subViewIndex++){			sectionArray[2].appendChild(viewArray[inView].subViews[subViewIndex].viewTitle);		}				itemChange(inView,0);	}	catch(caughtError){		if(debugMode){			alert('JavaScript error in viewChange(' + inView + '):' + caughtError.message);		}	}}function itemChange(inView,inItem){	try{		sectionClear(sectionArray[4]);		sectionArray[4].appendChild(viewArray[inView].subViews[inItem].viewContent);		for(var listIndex=0;listIndex<sectionArray[2].childNodes.length;listIndex++){			if(listIndex == inItem){				sectionArray[2].childNodes[listIndex].setAttribute(classRef,'itemtitleselected');			}			else{				sectionArray[2].childNodes[listIndex].setAttribute(classRef,'itemtitle');			}		}	}	catch(caughtError){		if(debugMode){			alert('JavaScript error in itemChange(' + inView + ',' + inItem + '):' + caughtError.message);		}	}}function sectionClear(inDiv){	try{		if(inDiv.hasChildNodes()){			for(var sectionChild=inDiv.childNodes.length -1;sectionChild>=0;sectionChild--){				inDiv.removeChild(inDiv.childNodes[sectionChild]);			}		}	}	catch(caughtError){		if(debugMode){			alert('JavaScript error in sectionClear:' + caughtError.message);		}	}}function infoboxShow(inEvent){	if(!inEvent){		var inEvent = window.event;	}		try{		var infoDiv = this.parentNode.getElementsByTagName('DIV');		sectionClear(sectionArray[6]); // Clear existing contents		sectionArray[6].appendChild(infoDiv[0].cloneNode(true)); // Update contents		sectionArray[6].childNodes[0].setAttribute(classRef,'onscreen');		// Move infobox to appropriate location		// Set infobox dimensions based on available space		// Determine location		// Determine window dimensions		// Choose side of inParent (top, bottom, left, right) to display infobox based on which side has the most space		var infoX = elementX(this);		var infoY = elementY(this);		var infoHeight = 150;		var infoWidth = 200;		infoX += 20;		infoY -= (infoHeight + 20);		sectionArray[6].style.height = infoHeight + 'px';		sectionArray[6].style.width = infoWidth + 'px';				sectionArray[6].style.top = infoY + 'px';		sectionArray[6].style.left = infoX + 'px';		sectionArray[6].style.visibility = 'visible';	}	catch(caughtError){		if(debugMode){			alert('JavaScript error in infoboxShow:' + caughtError.message);		}	}}function infoboxHide(inEvent){	if(!inEvent){		var inEvent = window.event;	}		try{		sectionArray[6].style.visibility = 'hidden';		sectionClear(sectionArray[6]); // Clear existing contents		sectionArray[6].style.height = '0px'; 		sectionArray[6].style.width = '0px'; 	}	catch(caughtError){		if(debugMode){			alert('JavaScript error in infoboxHide:' + caughtError.message);		}	}}function elementX(inElement){	var xCalc = 0;		try{		if (inElement.offsetParent){			while (inElement.offsetParent){				xCalc += inElement.offsetLeft;				inElement = inElement.offsetParent;			}		}	}	catch(caughtError){		if(debugMode){			alert('JavaScript error in elementX:' + caughtError.message);		}	}	return xCalc;}function elementY(inElement){	var yCalc = 0;		try{		if (inElement.offsetParent){			while (inElement.offsetParent){				yCalc += inElement.offsetTop;				inElement = inElement.offsetParent;			}		}	}	catch(caughtError){		if(debugMode){			alert('JavaScript error in elementY:' + caughtError.message);		}	}	return yCalc;}function addressAdd(inKey){	var siteAddress = 'millwoodestates.info';	var managementAddress = 'cmgmt.com';	var feedbackCategory = inKey.substring(inKey.indexOf('(') + 1,inKey.indexOf(')'));	var addressCalc = 'spam@millwoodestates.info';		try{		if(feedbackCategory == 'Web'){			addressCalc = feedbackCategory + '.feedback@' + siteAddress;		}		else{			addressCalc = 'j.whitney@' + managementAddress;		}	}	catch(caughtError){		if(debugMode){			alert('JavaScript error in addressAdd(' + inKey + '):' + caughtError.message);		}	}		return addressCalc;}function headerSlideshow(inMode){	try{//alert(inMode + ', ' + foreImage.style.opacity);		if(inMode == 0 || inMode == 1){			nextImage += 1;			if(nextImage > maxImage){				nextImage = 1;			}			if(inMode == 0){				foreImage.src = imageBase + nextImage + 't.jpg';							var nextTime = setTimeout('headerSlideshow(2)',3000);			}			else{				backImage.src = imageBase + nextImage + 't.jpg';							var nextTime = setTimeout('headerSlideshow(3)',3000);			}		}		else if(inMode == 2){			if(foreImage.style.opacity < 0.9){				foreImage.style.opacity = (1 * foreImage.style.opacity) + 0.1;				var nextTime = setTimeout('headerSlideshow(2)',80);			}			else{				foreImage.style.opacity =1;				var nextTime = setTimeout('headerSlideshow(1)',3000);			}		}		else{			if(foreImage.style.opacity > 0.1){				foreImage.style.opacity -= 0.1;				var nextTime = setTimeout('headerSlideshow(3)',80);			}			else{				foreImage.style.opacity = 0;				var nextTime = setTimeout('headerSlideshow(0)',3000);			}		}	}	catch(caughtError){		if(debugMode){			alert('JavaScript error in headerSlideshow:' + caughtError.message);		}	}}function ViewImage(inImageNumber){	var viewerDiv = document.getElementById('imageviewer');	var viewerImage = document.getElementById('fullimage');	try{		if(inImageNumber > 0){			//viewerDiv.width = 160;			//viewerDiv.height = 160;			// set coordinates to match thumbnail			viewerImage.src = imageBase + inImageNumber + '.jpg';			currentImage = inImageNumber;			viewerImage.style.width = '480px';			viewerImage.style.height = '360px';			viewerDiv.style.opacity = 0;			viewerDiv.style.visibility = 'visible';			// expand to final dimensions			var nextTime = setTimeout('ViewImage(-1)',80);		}		else if(viewerDiv.style.opacity < 0.9){			viewerDiv.style.opacity = (1 * viewerDiv.style.opacity) + 0.1;			var nextTime = setTimeout('ViewImage(-1)',80);		}		else{			viewerDiv.style.opacity =1;		}	}	catch(caughtError){		if(debugMode){			alert('JavaScript error in ViewImage(' + inImageNumber + '):' + caughtError.message);		}	}}function HideImage(){	var viewerDiv = document.getElementById('imageviewer');	try{		viewerDiv.style.opacity = 0;		viewerDiv.style.visibility = 'hidden';	}	catch(caughtError){		if(debugMode){			alert('JavaScript error in HideImage:' + caughtError.message);		}	}}function ChangeImage(inAmount){	var viewerDiv = document.getElementById('imageviewer');	var viewerImage = document.getElementById('fullimage');	var nextIndex = 1;		try{		nextIndex = currentImage + (1 * inAmount);		if(nextIndex < 1){			nextIndex = maxImage;		}		else if(nextIndex > maxImage){			nextIndex = 1;		}		viewerImage.src = imageBase + nextIndex + '.jpg';		currentImage = nextIndex;	}	catch(caughtError){		if(debugMode){			alert('JavaScript error in ChangeImage(' + inAmount + '):' + caughtError.message);		}	}}