var cont_open = false;
var cont_current;
//  newRow2.appendChild(newCell2);

function toggleResource(li, cont) {
	if (cont_open && cont_current == li) {
      closeResource();
	} else if (cont_open) {
	  closeResource();
      cont_open = true;
  	  var div = document.getElementById('cont-'+cont);
  	  div.style.display = "block";
  	  cont_current = li;
  	  li.className = "on";
      li.appendChild(div);
	} else {
      cont_open = true;
  	  var div = document.getElementById('cont-'+cont);
  	  div.style.display = "block";
  	  cont_current = li;
  	  li.className = "on";
      li.appendChild(div);
	}
    

	return;
}

function closeResource() {
	cont_current.lastChild.style.display="none";
	//cont_current.removeChild(cont_current.lastChild);
	cont_current.className='';
	cont_current = '';
	cont_open = false;
	return;
}



var imgDir = "images";
var lgPrefix = "large_prop_";
var suffix = ".jpg";
var imgName = "largeImg";

// Function to swap a large image based on the thumbnail clicked.
// idx = Index for image to load
function swapImg(idx) {
	if(document.images) {
		var imgSource = imgDir + "/" + lgPrefix + idx + suffix;
		document.images[imgName].src = imgSource;
	}
}


// ---- Functions for properties ---------------------------------------------------------------------------------------------- //
// ---------------------------------------------------------------------------------------------------------------------------- //

var contentSections = new Array();

/* Set content sections */
function setContent() {
  for(i=0; i<arguments.length; i++) {
	  contentSections.push("content-"+arguments[i]);
  }
  return;
}

function showContent(x) {
	var contentName = "content-"+x;
	for(i=0; i<contentSections.length; i++) {
		document.getElementById(contentSections[i]).style.display = (contentSections[i] == contentName) ? "block" : "none";
		document.getElementById("li-"+contentSections[i].split('-')[1]).className = " ";
	}
	document.getElementById("li-"+x).className = "on";
	return;
}

function viewPlan(x) {
	document.getElementById('gra-plan').src = "images/"+x;
	var navList = document.getElementById("nav-plans");
	for (i=0; i<navList.childNodes.length; i++) {
      node = navList.childNodes[i];
	  if (node.nodeName=="LI") {
		  node.className = (node.id == x) ? "on" : " ";
	  }
	}
	return;
}

/* Preload Images */
function loadImages(n) {
	if (document.images) {
	    for (i=1; i<=n; i++) {
		  eval('pic'+i+'= new Image();');
		  var num = (i<10) ? "0"+i : i ;
		  eval('pic'+i+'.src = "images/pho-lg'+num+'.jpg"');
	    }
	}
}

function prevPhoto() {
  var pho_view = document.getElementById('pho-view');
  var pho_limit = (document.getElementById('pho-sm16')) ? 16 : 10;
  var tempstring = pho_view.src.split('/').pop();
  var pho_num = parseInt(tempstring.substring(6));
  var pho_new = (pho_num == 1) ? pho_limit : pho_num-1;
  selectPhoto(pho_new);
  return;
}

function nextPhoto() {
  var pho_view = document.getElementById('pho-view');
  var pho_limit = (document.getElementById('pho-sm16')) ? 16 : 10;
  var tempstring = pho_view.src.split('/').pop();
  var pho_num = parseInt(tempstring.substring(6));
  var pho_new = (pho_num == pho_limit) ? 1 : pho_num+1;
  selectPhoto(pho_new);
  return;
}

function selectPhoto(n) {
  var pho_view = document.getElementById('pho-view');
  var pho_limit = (document.getElementById('pho-sm16')) ? 16 : 10;
  for(i=1; i<=pho_limit; i++) {
	  document.getElementById('pho-sm'+i).className = (i == n) ? "on" : " ";
  }
  pho_view.src = "images/pho-lg"+n+".jpg";
  return;
}

/* 2 thumb rows */

function prevPhotoTwoRow() {
  var pho_view = document.getElementById('pho-view');
  var pho_limit = (document.getElementById('pho-sm32')) ? 32 : 10;
  var tempstring = pho_view.src.split('/').pop();
  var pho_num = parseInt(tempstring.substring(6));
  var pho_new = (pho_num == 1) ? pho_limit : pho_num-1;
  selectPhotoTwoRow(pho_new);
  return;
}

function nextPhotoTwoRow() {
  var pho_view = document.getElementById('pho-view');
  var pho_limit = (document.getElementById('pho-sm32')) ? 32 : 10;
  var tempstring = pho_view.src.split('/').pop();
  var pho_num = parseInt(tempstring.substring(6));
  var pho_new = (pho_num == pho_limit) ? 1 : pho_num+1;
  selectPhotoTwoRow(pho_new);
  return;
}

function selectPhotoTwoRow(n) {
  var pho_view = document.getElementById('pho-view');
  var pho_limit = (document.getElementById('pho-sm32')) ? 32 : 10;
  for(i=1; i<=pho_limit; i++) {
	  document.getElementById('pho-sm'+i).className = (i == n) ? "on" : " ";
  }
  pho_view.src = "images/pho-lg"+n+".jpg";
  return;
}

/* Team page (depends on prototype.js) */

var hoverShowing = false; 

function showHover(number) {
  if (hoverShowing) return; 
  
  var hoverBox = $("hover_" + number);
  hoverBox.style.display = ''
  
  hoverBox.observe("mouseover", hoverMouseover); 
  hoverBox.observe("mouseout", hoverMouseout); 
}

function hoverMouseover(event) {
  hoverShowing = true; 
  var hoverBox = event.findElement("div.hover")
  hoverBox.show();
}

function hoverMouseout(event) {
  var hoverBox = event.findElement("div.hover")
  if (!Position.within(hoverBox, event.pointerX(), event.pointerY())) {
    hoverShowing = false; 
    hoverBox.hide();
  }
}

function hideHover(number) {
  var hoverBox = document.getElementById("hover_" + number);
  hoverBox.style.display = 'none'
}