// JavaScript Document

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function catShow(showCat, showProj, showPhoto)
{
	document.getElementById('residential').className='category';
	document.getElementById('commercial').className='category';
	document.getElementById('special').className='category';
	document.getElementById(showCat).className='current_category';
	
	showProject(showProj, showCat + '_projects', showPhoto);
}

function showProject(projectID, categoryID, photo)
{
	document.getElementById('large_photo').src = photo;
	document.getElementById('selected').id = '';
	
	var imageList = document.getElementById(projectID).getElementsByTagName('img');

	var testPhoto = photo.split('/').pop();
	
	for(var image in imageList)
	{
		//alert('src = ' + imageList[image].src);
		if(imageList[image].src != null)
		{
			var imageListTest = imageList[image].src.split('/').pop();
			if(imageListTest == testPhoto)
			{
				imageList[image].id = 'selected';
				break;
			}
		}
	}
	
	var projectDivs = document.getElementById(categoryID).getElementsByTagName('div');
	var projectLink = projectID + '_link';
	//var comparison = projectID + ' != ';
	//alert(projectDivs[project].id);
	
	for(var project in projectDivs)
	{
		
		if(projectDivs[project].id == projectID)
		{
			projectDivs[project].className = 'current_project';
		}
		else if (projectDivs[project].id != '' && projectDivs[project].id != 'undefined')
		{
			projectDivs[project].className = 'project';
			//comparison += projectDivs[project].id;
		}
	}
	//alert(comparison);
	highlight(document.getElementById(projectLink));
}

function highlight(target)
{
	projectAnchors = target.parentNode.getElementsByTagName('a');
	for(var anchors in projectAnchors)
	{
		projectAnchors[anchors].className = '';
	}
	
	target.className = 'current_project_name';
}

function setSrc(thumbnail)
{
	//Break apart thumbnail source, remove the thumbnail folder, reassemble(join), and assign to the large image.  Voila! Thumbail path becomes photo path.
	//alert(thumbnail);
	var removeSegment;
	thumbPieces = thumbnail.split("/");
	for(var piece in thumbPieces)
	{
		if(thumbPieces[piece] == 'thumbnails' || thumbPieces[piece] == 'thumbnailsBW')
		{
			removeSegment = piece;
			break;
		}
	}
	
	thumbPieces.splice(removeSegment,1);
	
	document.getElementById('large_photo').src = thumbPieces.join('/');
	
	//alert(thumbPieces.join('/'));
}



function prev_photo(arrow)
{
	var found = false;
	photos = arrow.parentNode.parentNode.getElementsByTagName('img');
	
	for(var photo = 0; photo < photos.length; photo++)
	{
		if(photos[photo].id == 'selected')
		{
			//found the selected photo, now pick the next one (if available)
			if(photo < photos.length - 1 )
			{
				found = true;
				var nextPhoto = photo + 1;
				photos[photo].id = '';
				photos[photo + 1].id = 'selected';
				
				setSrc(photos[nextPhoto].src);
				return;
			}
			else
			{
				//no action to take- there's no previous image.  Uncomment return to disable "wrap-around".
				//return;
			}
			
		}
				
	}
	
	if(!found)
	{
		var firstIndex = 2;
		//No image with the selected id was found
		document.getElementById('selected').id = '';
		photos[firstIndex].id = 'selected';
		setSrc(photos[firstIndex].src);
	}
}

function next_photo(arrow)
{
	var found = false;
	photos = arrow.parentNode.parentNode.getElementsByTagName('img');
	
	for(var photo = 0; photo < photos.length; photo++)
	{
		if(photos[photo].id == 'selected')
		{
			//found the selected photo, now pick the next one (if available)
			if(photo > 2)
			{
				found = true;
				var nextPhoto = photo - 1;
				photos[photo].id = '';
				photos[nextPhoto].id = 'selected';
				
				setSrc(photos[nextPhoto].src);
				return;
			}
			else
			{
				//no action to take- there's no previous image.  Uncomment return to disable "wrap-around".
				//return;
			}
		}
	}
	
	if(!found)
	{
		var lastIndex = photos.length - 1;
		//No image with the selected id was found.  Use 3 instead of 1 because the 2 arrow images count as well.
		document.getElementById('selected').id = '';
		photos[lastIndex].id = 'selected';
		setSrc(photos[lastIndex].src);
	}
}

function prev_over(target)
{
	target.src = 'images/arrows_previous_over.gif';
}

function prev_out(target)
{
	target.src = 'images/arrows_previous_off.gif';
}

function next_over(target)
{
	target.src = 'images/arrows_next_over.gif';
}

function next_out(target)
{
	target.src = 'images/arrows_next_off.gif';
}


function loadBio(newPhoto, newSelected)
{
	document.getElementById('bio_pic').src = 'people/' + newPhoto;
	var name = newPhoto.substr(0, newPhoto.length - 4);
	loadXMLDoc('people/text/' + name + '.html');

	document.getElementById('selected').id = '';
	newSelected.childNodes[0].id = 'selected';
}

var xmlhttp;
function loadXMLDoc(url)
{
xmlhttp=null;
if (window.XMLHttpRequest)
  {// code for Firefox, Opera, IE7, etc.
  xmlhttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
if (xmlhttp!=null)
  {
  xmlhttp.onreadystatechange=state_Change;
  xmlhttp.open("GET",url,true);
  xmlhttp.send(null);
  }
else
  {
  alert("Your browser does not support XMLHTTP.");
  }
}

function state_Change()
{
if (xmlhttp.readyState==4)
  {// 4 = "loaded"
  if (xmlhttp.status==200)
    {// 200 = "OK"
    document.getElementById('bio_text').innerHTML=xmlhttp.responseText;
    }
  else
    {
    //alert("Problem retrieving data:" + xmlhttp.statusText);
	document.getElementById('bio_text').innerHTML='';
    }
  }
}