// To allow multiple onLoad events...
var LOADER = new function() {
	var _self = this;
	this.fns = [ ];
	
	this.add = function(fn) {this.fns.push(fn);}
	this.exec = function() { var fn; while (fn = this.fns.shift()) fn(); }
	window.onload = function() {LOADER.exec();}
}

// by Paul@YellowPencil.com and Scott@YellowPencil.com
// feel free to delete all comments except for the above credit

function setTall() {
	if (document.getElementById) {
		// the divs array contains references to each column's div element.  
		// Replace 'center' 'right' and 'left' with your own.  
		// Or remove the last one entirely if you've got 2 columns.  Or add another if you've got 4!
		var divs = new Array(document.getElementById('leftcol'), document.getElementById('main'));
		
		// Let's determine the maximum height out of all columns specified
		var maxHeight = 0;
		for (var i = 0; i < divs.length; i++) {
			if (divs[i].offsetHeight > maxHeight) maxHeight = divs[i].offsetHeight;
		}
		
		// Let's set all columns to that maximum height
		for (var i = 0; i < divs.length; i++) {
			divs[i].style.height = maxHeight + 'px';

			// Now, if the browser's in standards-compliant mode, the height property
			// sets the height excluding padding, so we figure the padding out by subtracting the
			// old maxHeight from the new offsetHeight, and compensate!  So it works in Safari AND in IE 5.x
			if (divs[i].offsetHeight > maxHeight) {
				divs[i].style.height = (maxHeight - (divs[i].offsetHeight - maxHeight)) + 'px';
			}
		}
	}
}

LOADER.add(setTall);

window.onresize = function() {setTall();}


function showDiv(pass) {
var divs = document.getElementsByTagName('div');
for(i=0;i<divs.length;i++){
	if(divs[i].id.match(pass)){//if they are 'see' divs
		if (document.getElementById) // DOM3 = IE5, NS6
		divs[i].style.display="block";// show
		}
	}
}

function hideDiv(pass) {
var divs = document.getElementsByTagName('div');
for(i=0;i<divs.length;i++){
	if(divs[i].id.match(pass)){//if they are 'see' divs
		if (document.getElementById) // DOM3 = IE5, NS6
		divs[i].style.display="none";// show/hide
		}
	}
} 

function showStudents() {
 showDiv('students');
 showDiv('studentsmap');
 hideDiv('media');
 hideDiv('mediamap');
 hideDiv('educators');
 hideDiv('educatorsmap');
 setTall();
}
function showMedia() {
 hideDiv('students');
 hideDiv('studentsmap');
 showDiv('media');
 showDiv('mediamap');
 hideDiv('educators');
 hideDiv('educatorsmap');
 setTall();
}
function showEducators() {
 hideDiv('students');
 hideDiv('studentsmap');
 hideDiv('media');
 hideDiv('mediamap');
 showDiv('educators');
 showDiv('educatorsmap');
 setTall();
}



// OPEN FLICKR LINKS IN A NEW WINDOW
function flickrWindow() {
	// List domains that require a new window, separated by commas
	var Domains = "flickr.com";

	// Lowercase for comparison
	Domains = Domains.toLowerCase();

	// Make array
	var DomainArray = Domains.split(",");

	// For each link in the document
	for(var i = 0; i < document.links.length; i++) {
	   if(document.links[i].hostname.length < 1) // if there's no host name, skip
	   {continue;}
	   if(document.links[i].target.length > 0) // if there's already a target, skip
	   {continue;}
	   var OpenWindow = false; // by default, no new window
	   var testHostname = document.links[i].hostname.toLowerCase(); // lowercase for comparison
	   for(var j = 0; j < DomainArray.length; j++) {  // for each comparison domain
		if(testHostname.indexOf("." + DomainArray[j]) != -1) { // see if ".domain" exists, if not, restart
	      OpenWindow = true; // but if it does match, New Window time
	      break;
		}
	   }
	   if(OpenWindow == true)
	   { document.links[i].target = '_blank'; }
	}
}
LOADER.add(flickrWindow);
