<!-- hide from non-JS capable browsers
// Created by: Cameron Mura, May 2003.
// Last touched by: CM, 06/07/2003.

var img_captions = new Array();
var bio_group = new Array();
var comp_group = new Array();		// If you want a new sorting scheme in addition to 'bio' and 'comp' types, then add it here...
//var current_sort_method = 'bio'; 	// set this variable to default sort method 

function Group(gallery_nums,section_heading)	// Group constructor function
{ this.entries = gallery_nums;
  this.heading = section_heading;  }

/*********************************************************************************************************/
/****** THIS SECTION TESTS DOM-CONFORMANCE because some browsers (such as IE) are bad about this... ******/
var whats_we_got = '';
var features = new Array();	// This is kinda redundant because certain features imply others;
				// e.g., html 2.0 implies core.
features[0] = "'html','1.0'";
features[1] = "'xml','1.0'";
features[2] = "'core','2.0'";
features[3] = "'html','2.0'";
features[4] = "'xml','2.0'";
features[5] = "'views','2.0'";
features[6] = "'stylesheets','2.0'";
features[7] = "'CSS','2.0'";
features[8] = "'CSS2','2.0'";
features[9] = "'Events','2.0'";
features[10] = "'UIEvents','2.0'";
features[11] = "'MouseEvents','2.0'";
features[12] = "'HTMLEvents','2.0'";
features[13] = "'MutationEvents','2.0'";
features[14] = "'Range','2.0'";
features[15] = "'Traversal','2.0'";

if (!window.Node) {             // if there's no Node object...
//        alert("No \"window.Node\" interface!\nWill create one...");
        var Node = {
                ELEMENT_NODE: 1,
                ATTRIBUTE_NODE: 2,
                TEXT_NODE: 3,
                COMMENT_NODE: 8,
                DOCUMENT_NODE: 9,
                DOCUMENT_FRAGMENT_NODE: 11
        }
}

for (var i = 0; i < features.length; i++)
{ var verdict = eval("document.implementation.hasFeature("+features[i]+")");
  var whats_we_got = whats_we_got+features[i]+" = "+verdict+"\n";
}
if (!eval("document.implementation.hasFeature("+features[3]+")")) { var DOMverdict = "NO"; } 
else { var DOMverdict = "YES"; }
/*********************************************************************************************************/



function reformatPage_DOM(query_method)
{
// don't bother going on if query_method matches current_sort_method
 if (query_method == current_sort_method && query_method == "bio") { alert("Already sorted by \"biological systems\""); return false; } 
 else if (query_method == current_sort_method && query_method == "comp") { alert("Already sorted by \"computational methods\""); return false; }

// alert("'current_sort_method' = "+current_sort_method+"\nNew sort method = "+query_method);			// ...for debugging...
 var central_table = document.getElementById("main_table");
// var rows = central_table.getElementsByTagName("tr"); // assume all the rows in the table are of 'current_sort_method' type...if not, 
 							// another approach would be to do a "document.getElementsByName(current_sort_method);"
 							// line, instead of the central_table bit...

// deleteNodes_nDown(central_table);   			// do it this way if you wanna delete entire 'main_table' table node,
// document.body.removeChild(central_table); 		// ...or this way to delete 'main_table'...
// for (var x = 0; x < rows.length; x++)		// ...but this way to systematically delete individual rows...
// { deleteNodes_nDown(rows[x]);
// } 

 var newtable = document.createElement("table");
 newtable.setAttribute("id","main_table");
 newtable.setAttribute("border","0px");
 newtable.setAttribute("cellspacing","10");
 newtable.setAttribute("cellpadding","5");
 newtable.innerHTML = makeNewTableContents(query_method);
 central_table.parentNode.replaceChild(newtable,central_table);
 return true;
}


function reformatPage_noDOM(query_method)
{
// don't bother going on if query_method matches current_sort_method
  if (query_method == current_sort_method && query_method == "bio") { alert("Already sorted by \"biological systems\""); return false; }
  else if (query_method == current_sort_method && query_method == "comp") { alert("Already sorted by \"computational methods\""); return false; }
  else	{ alert("Note that your browser is NOT Level-2 DOM/HTML Conformant!\n\nHow DOM-conformant is your browser?\n\n"+whats_we_got);
  	  self.location.replace("index_"+query_method+".html");
	}
  return false;
}



function makeNewTableContents(sort_method) 	// this was adapted from the 'addThumbnailsToTable' function defined below...
{
	var table_content_string = '';

 	for (var group_num = 0; group_num < eval(sort_method+"_group.length"); group_num++)
  	{
	   var current_group = sort_method+"_group["+group_num+"]";
	   var img_num = 0;
	   var entries_array = new Array();

	   // include next line b/c we don't wanna break-out w/ return-- we may wanna include some heading <tr> for example, w/o thumbnails... 
	   if (eval(current_group+".entries.split(\",\")") != '') { var entries_array = eval(current_group+".entries.split(\",\")"); }
	   // this takes care of the group/section headings:
	   var table_content_string = table_content_string + "<tr name = '"+sort_method+"'><td class='heading' colspan='2'>"+eval(current_group+".heading")+"</td></tr>";
	   // now loop through the group/section entries:
	   for (var entry_num = 0; entry_num < entries_array.length; entry_num++)
		{
		 var basename = entries_array[entry_num];
		 var thumbnail = basename + ".t.gif";
		 var img_num = entry_num+1;
		 // next 4 lines take care of table row & cell formatting:
	  	 if (img_num % 2 == 1 && img_num != entries_array.length)      { var first_part = "<tr name='"+sort_method+"'>"; var last_part = ""; }
		 else if (img_num % 2 == 1 && img_num == entries_array.length) { var first_part = "<tr name='"+sort_method+"'>"; var last_part = "</tr>"; }
		 else if (img_num % 2 == 0 || img_num == entries_array.length) { var first_part = ""; var last_part = "</tr>"; }
		 else { var first_part = ""; var last_part = ""; }

		 var table_content_string = table_content_string+first_part+"<td>";
		 var table_content_string = table_content_string+"<a href='"+basename+".html' target='"+basename+"'><img class='thumbnail' src='"+thumbnail+"' alt='"+thumbnail+"' /><br />";
		 var table_content_string = table_content_string+"<span class='img_caption'>"+img_captions[basename]+"</span>";
		 var table_content_string = table_content_string+"</a></td>"+last_part;
		}
  	}
	current_sort_method = sort_method;
	return table_content_string;
}


/********************************************************************************************************
 HERE'S THE 'deleteNodes_nDown' FUNCTION, FROM THE FIRST ATTEMPT OF MAKING THESE PAGES SORTABLE...
 It recursively deletes ALL the descendents of the input node 'n'...
 Its input is a particular node reference, e.g. 'n' = 'central_table', where 
 'central_table' was defined earlier as 'var central_table = document.getElementById("main_table");'  
*********************************************************************************************************/

/*
function deleteNodes_nDown(n)	// recursively deletes all childnodes of given node 'n'...
{				// Note that the line corresponding to the recursive function 
				// call isn't necessary if descendants of 'n' go only 2 layers deep (including 'n')...
//   var kids = n.childNodes;
//   var numkids = kids.length;
//   for (var i = numkids-1; i >= 0; i--)
//	{ deleteNodes_nDown(kids[i]);
//	  n.removeChild(kids[i]);
//      //n.replaceChild(chingi,kids[i]);	// if there was a 1:1 match between table/row structure of 
//	}					// 'bio'- and 'comp'-style sorts, then could maybe invoke
      					   	// a node replacement method rather than delete all rows 
						// and then append new nodes?...

   for (var m = n.firstChild; m != null; m = n.lastChild)	// more elegant way to do all of the above
	{ deleteNodes_nDown(m);
    	  n.removeChild(m); }

return false;
}
*/


/********************************************************************************************************
 HERE'S THE 'addThumbnailsToTable' FUNCTION, FROM THE FIRST ATTEMPT OF MAKING THESE PAGES SORTABLE...
 Its input is a particular group of galleries, e.g. 'some_group = 'bio_group[1]'...
*********************************************************************************************************/
/*
function addThumbnailsToTable(some_group)
{
 var img_num = 0;
 var entries_array = new Array();
 var type_of_sort = '';

 if (eval(some_group+".entries.split(\",\")") != '') { var entries_array = eval(some_group+".entries.split(\",\")"); } //don't wanna breakout w/ 'return', b/c
 if (some_group.search(/^bio_/i) >= 0 ) { var type_of_sort = 'bio'; } else { var type_of_sort = 'comp';}               //may still wanna write some tr heading

 window.document.writeln('<tr name="'+type_of_sort+'"><td class="heading" colspan="2">'+eval(some_group+".heading")+'</td></tr>');

 for (var index = 0; index < entries_array.length; index++)
  {
   var basename = entries_array[index];
   var thumbnail = basename+".t.gif";
   var img_num = index+1;
   if (img_num % 2 == 1 && img_num != entries_array.length)      { var first_part = "<tr name=\""+type_of_sort+"\">"; var last_part = ""; }
   else if (img_num % 2 == 1 && img_num == entries_array.length) { var first_part = "<tr name=\""+type_of_sort+"\">"; var last_part = "</tr>"; }
   else if (img_num % 2 == 0 || img_num == entries_array.length) { var first_part = ""; var last_part = "</tr>"; }
   else  { var first_part = ""; var last_part = ""; }

   window.document.write(first_part+"<td>");
   window.document.write("<a href='"+basename+".html'><img class='thumbnail' src='"+thumbnail+"' alt='"+thumbnail+"' /><br />");
   window.document.write("<span class='img_caption'>"+img_captions[basename]+"</span>");
   window.document.write("</a></td>"+last_part);
  }

 current_sort_method = type_of_sort;   // set global 'current_sort_method' variable to current type_of_sort
 return false;
}
*/


// end hide -->
