// Javascript for Buildings in Focus

function showit(building,caption,credit) {
//alert('in showit');
  if (document.controls.toggleNotes.value == "Show Photos") // ensure photo is shown
    showNotes();
	// alert("test");
	//alert(document.controls.getElementById("toggleNotes").value);
  document.getElementById("iii").src="BiF/img/" + building + ".jpg";
  document.getElementById("caption").innerHTML = "<b>" + caption + "</b>";
  document.getElementById("credit").innerHTML = "<em>Photograph: " + credit + "</em>";
}

function showNotes() {
//alert('in showNotes'); 
  toggleElementVisibility("bif_text");
  toggleElementVisibility("bif_picture");

  if (document.controls.toggleNotes.value == "Show Photos") 
     document.controls.toggleNotes.value = "Show Notes";
  else
     document.controls.toggleNotes.value = "Show Photos";
}

function showThumbs() {
	//alert('in showthumbs');
  var thumbList = new Array();
  thumbList = getElementsByClass('thumb',document,'*');
  alert("found " + thumbList.length + " thumbs");
  
  for ( i=0;i<thumbList.length;i++ ) {
	  alert(i + " " + thumbList[i]);
  // toggleElementVisibility(thumbList[i].id); //DOESN'T WORK!
  }
  
 // toggleElementVisibility('StAndrews');
 // toggleElementVisibility('StAnnes');

  if (document.controls.toggleThumbs.value == "Show Thumbs") 
     document.controls.toggleThumbs.value = "Hide Thumbs";
  else
     document.controls.toggleThumbs.value = "Show Thumbs";
}

function toggleElementVisibility( element )
{
  var elem, vis;
  if( document.getElementById ) // modern browsers
    elem = document.getElementById( element );
  else if( document.all ) // old MSIE versions
      elem = document.all[element];
  else if( document.layers ) // NN4
    elem = document.layers[element];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}

function getElementsByClass( searchClass, domNode, tagName) {
	alert(searchClass);
	if (domNode == null) domNode = document;
	if (tagName == null) tagName = '*';
	var el = new Array();
	var tags = domNode.getElementsByTagName(tagName);
	var tcl = " "+searchClass+" ";
	for(i=0,j=0; i<tags.length; i++) {
		var test = " " + tags[i].className + " ";
		if (test.indexOf(tcl) != -1)
			el[j++] = tags[i];
	}
	return el;
}

function getElementsByClassName(classname, node)  {
    if(!node) node = document.getElementsByTagName("body")[0];
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = node.getElementsByTagName("*");
    for(var i=0,j=els.length; i<j; i++)
        if(re.test(els[i].className))a.push(els[i]);
    return a;
}