/*
JSTarget function by Roger Johansson, www.456bereastreet.com

open new window for non-html pages. Replaces deprecated target _blank
*/
var JSTarget = {
	init: function(att,val,warning) {
		if (document.getElementById && document.createElement && document.appendChild) {
			var strAtt = ((typeof att == 'undefined') || (att == null)) ? 'class' : att;
			var strVal = ((typeof val == 'undefined') || (val == null)) ? 'non-html' : val;
			var strWarning = ((typeof warning == 'undefined') || (warning == null)) ? ' ' : warning;
			var oWarning;
			var arrLinks = document.getElementsByTagName('a');
			var oLink;
			var oRegExp = new RegExp("(^|\\s)" + strVal + "(\\s|$)");
			for (var i = 0; i < arrLinks.length; i++) {
				oLink = arrLinks[i];
				if ((strAtt == 'class') && (oRegExp.test(oLink.className)) || (oRegExp.test(oLink.getAttribute(strAtt)))) {
					oWarning = document.createElement("em");
					oWarning.appendChild(document.createTextNode(strWarning));
					oLink.appendChild(oWarning);
					oLink.onclick = JSTarget.openWin;
				}
			}
			oWarning = null;
		}
	},
	openWin: function(e) {
		var event = (!e) ? window.event : e;
		if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) return true;
		else {
		    var oWin = window.open(this.getAttribute('href'), '_blank');
			if (oWin) {
				if (oWin.focus) oWin.focus();
				return false;
			}
			oWin = null;
			return true;
		}
	},
	/*
	addEvent function from http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html
	*/
	addEvent: function(obj, type, fn) {
		if (obj.addEventListener)
			obj.addEventListener(type, fn, false);
		else if (obj.attachEvent) {
			obj["e"+type+fn] = fn;
			obj[type+fn] = function() {obj["e"+type+fn]( window.event );}
			obj.attachEvent("on"+type, obj[type+fn]);
		}
	}
};
JSTarget.addEvent(window, 'load', function(){JSTarget.init();});
JSTarget.addEvent(window, 'load', function(){JSTarget.init("rel","external"," (external website, opens in a new window)");});


/**************************************************************************
 *                                                                        *
 *  JAVASCRIPT MENU HIGHLIGHTER v.1.5 (080929)                            *
 * --------------------------------------------                           *
 * ©2005 Media Division (www.MediaDivision.com)                           *
 *                                                                        *
 * Written by Marius Smarandoiu & Armand Niculescu                        *
 *                                                                        *
 * You are free to use, modify and distribute this file, but please keep  *
 * this header and credits                                                *
 *                                                                        *
 * Usage:                                                                 *
 * - the script will apply the .current class to the <a> and its parent   *
 *   <li> that is contained in the element with id="primarynav" and points*
 *   to the current URL                                                   *
 * - works in IE6, Firefox and Opera                                      *
 **************************************************************************/
function extractPageName(hrefString)
{
	var arr = hrefString.split('/');
	return  (arr.length<2) ? hrefString : arr[arr.length-2].toLowerCase() + arr[arr.length-1].toLowerCase(); 
	
	
}

function setActiveMenu(arr, crtPage)
{
	for (var i=0; i<arr.length; i++)
	{
		if(extractPageName(arr[i].href) == crtPage)
		{
			if (arr[i].parentNode.tagName != "DIV")
			{
				arr[i].className = "current";
				arr[i].parentNode.className = "current";
			}
		}
	}
}

function setPage()
{
	
	
	hrefString = document.location.href ? document.location.href : document.location;
	
/* var filePath = "http://www.caryinstitute.org/" ; */

var filePath = "http://" + document.location.hostname + "/";
	
	if (hrefString == filePath + "chp_background.html" || hrefString == filePath + "chp_objectives.html" || hrefString == filePath + "chp_team.html"  ) {
		hrefString = filePath + "chp.html";
	}
	
	else if (hrefString == filePath + "chp_readings_student.html" || hrefString == filePath + "chp_datasets_student.html" || hrefString == filePath + "chp_river_visuals_student.html" ) {
		hrefString = filePath + "chp_student_corner.html";
	}
	
	
	else if (hrefString == filePath + "chp_curriculum.html" || hrefString == filePath + "chp_background_readings.html" || hrefString == filePath + "chp_teacher_corner_workshop.html" || hrefString == filePath + "chp_readings.html" || hrefString == filePath + "chp_datasets.html" || hrefString == filePath + "chp_river_visuals.html" || hrefString == filePath + "chp_powerpoints.html" || hrefString == filePath + "chp_extreme_weather.html" || hrefString == filePath + "chp_invasive_species_lessons.html" || hrefString == filePath + "chp_pollution_and_the_Hudson.html" || hrefString == filePath + "chp_land_use.html" || hrefString == filePath + "chp_intro_to_hudson.html" || hrefString == filePath + "chp_what_is_an_ecosystem.html" || hrefString == filePath + "chp_measurement_tools.html" || hrefString == filePath + "chp_measurement_tools_advanced.html") {
		hrefString = filePath + "chp_teacher_corner.html";
	}
	
	else {
		hrefString = document.location.href ? document.location.href : document.location;
	}
	


	if (document.getElementById("menuHorizSub")!=null)
		setActiveMenu(document.getElementById("menuHorizSub").getElementsByTagName("a"), extractPageName(hrefString));
}



