/* Script is being used here with the main nav across the top and nav li on the left:
http://claricesmithcenter.umd.edu/2010/c/about/ */


$(function(){
	var urlArray = window.location.pathname.split('/');/*pathname is /2010/c/about/ everything before and after the / has a key number 0-"1=2010"-"2=c"-"3=about"-4 */
	var urlKey = 3;/*we are referencing key 3 or about*/
	
	$('#page_navigation a').each(function(){  /* the .each says only to use this div reference */
		var urlCheck = $(this).attr('href').split('/'); /* checks that the url href and slits it by /  */
		if (urlArray[urlKey] == urlCheck[urlKey]) { /* says if the pathname split matchs the url name split then make class active */
			$(this).addClass('active');
		}
	})
	
	$('.nav li a').each(function(){
		var urlCheck = $(this).attr('href').split('/');
		if (urlArray[urlKey] == urlCheck[urlKey] && urlArray[urlKey + 1] == urlCheck[urlKey + 1]) { /* do same but match the extra name in the path also /2010/c/about/???? */
			$(this).css('color', '#980000');
		}
	})

	$('.menu .fbnav li a').each(function(){
		var urlKey = 4;
		var urlCheck = $(this).attr('href').split('/');
		if (urlArray[urlKey] == urlCheck[urlKey] && urlArray[urlKey + 1] == urlCheck[urlKey + 1]) { /* do same but match the extra name in the path also /2010/c/about/???? */
			$(this).css('color', '#fbf2d9');
			$(this).css('background-image', 'url(/images/fortunes-bones/menubg.jpg)');
			$(this).css('padding-bottom', '8px');
		}
	})
})

/* Original Script that is java not jquery and puts an active class on every link that is current and matchs the full path name.  
Works great but could not get it to make the active class stay active on sub pages also. It would only stay active as long as you were on that page. */

/*
function scriptInit() {
if (!document.getElementById) {
	return;
	}
}
function addEvent(elm, evType, fn, useCapture) {
	if (elm.addEventListener) {
	elm.addEventListener(evType, fn, useCapture);
	return true;
	} else if (elm.attachEvent) {
	var r = elm.attachEvent('on' + evType, fn);
	return r;
	} else {
	elm['on' + evType] = fn;
	}
}
function checkActive() {
	var a = document.getElementsByTagName("a");
	if (window.location.href.substr(location.href.length -1, 2) == '/') {
		var loc = window.location.href; 
	}
	else {
		var loc = window.location.href;
	}
	for(var i=0; i < a.length; i++) {
		if (a[i].href == loc) {
			a[i].setAttribute("class", "active");
			a[i].setAttribute("className", "active");
		}
	}
}
addEvent(window, 'load', checkActive, false);
*/

