$(document).ready(function(){
	anchors.addBehaviors();
	txtBoxClear.init();

	$("ul.children").find(".current_page_ancestor").each(function(i) {
		$(this).children("a").each(function(i) {
			$(this).addClass("subselected");
		});
	});
	
	$("ul.children").find(".current_page_item").each(function(i) {
		$(this).children("a").each(function(i) {
			$(this).addClass("subselected");
		});
	});

	$("#navSubLevel").find('.current_page_ancestor').each(function(i) {
		$(this).children("a").each(function(i) {
			if (!$(this).hasClass("subselected")) {
				$(this).addClass("selected");
			}
		});
	});
	
	$("#navSubLevel").find('.current_page_item').each(function(i) {
		$(this).children("a").each(function(i) {
			if (!$(this).hasClass("subselected")) {
				$(this).addClass("selected");
			}
		});
	});
	
	$("#navSubLevel").find('.current-cat').each(function(i) {
		$(this).children("a").each(function(i) {
			if (!$(this).hasClass("subselected")) {
				$(this).addClass("selected");
			}
		});
	});
	
	$("ul#navSubLevel li").each(function(i) {
		if (!$(this).hasClass("current_page_item") && !$(this).hasClass("current_page_ancestor")) {
			$(this).children("ul").remove();
		}
	});
});

/* =================================================================== */
// Updated link functionality script using delegation to speed up
// the page and handle dynamically added elements.
// dependencies: jQuery
var anchors = {
	addBehaviors: function() {
		$('body').delegate('a', 'click', function(e) {
			if ($(this).attr('rel') == 'external' || $(this).hasClass('external') || $(this).hasClass('pdf') || $(this).hasClass('popupFull')) {
				// external links
				e.preventDefault();
				return anchors.openWin(this,"");
			} else if ($(this).hasClass('popup')) {
				// popup
				e.preventDefault();
				return anchors.openWin(this,"height=550,width=600,scrollbars=yes");
			} 
			
			if ($(this).attr('href') == location.href ) {
				// onstate
				$(this).addClass('onstate');
			}
		});
	},
	openWin: function(o,params) {
		window.open(o.href, "newwin","" + params + "");
		return false;
	}
};
/* =================================================================== */

/* =================================================================== */
// use this to automatically clear a text box of it's default value
// if nothing is typed in the box, the script will put the default value back
// useful on sites where search boxes don't have a seperate label
// you can use it for more than one box per page using the txtBoxes array
txtBoxClear = {
	txtBoxes : ['searchField'],
	init: function() {
		for (i=0;i<txtBoxClear.txtBoxes.length;i++) {
			var oCurrentTxtBox = document.getElementById(txtBoxClear.txtBoxes[i]);
			if (!oCurrentTxtBox) { continue; }
			oCurrentTxtBox.defaultVal = oCurrentTxtBox.defaultValue;
			txtBoxClear.clearBox(oCurrentTxtBox);
		}
	},
	clearBox : function(txtBox) {
		txtBox.onfocus = function() {
			if (txtBox.value == txtBox.defaultVal) { txtBox.value = ''; } 
		};
		txtBox.onblur = function() {
			if (txtBox.value == '') { txtBox.value = txtBox.defaultVal; }
		};
	}
};
/* =================================================================== */
