// provided by Matthew Woodruff
// revised Dec. 2007
// version 3.1

// Adds a red corner to subnav element previous to the selected element.
function modifySubNav() {
	var navX;
	var parentX;
	
	if (document.getElementById) {
		navX = document.getElementById('currentSubNav');
		
		// While the previous node is a text node
		while (navX.previousSibling.nodeType == '3') {
			navX = navX.previousSibling;
		}
		if (navX.previousSibling != null) {
			navX.previousSibling.firstChild.style.backgroundImage = "url(/images/subnav_prev_cap.gif)";
		}
	}
}


sfHover = function() {
			
	//var sfEls = document.getElementById("tools").getElementsByTagName("LI");
	var listenEls = getElementsByClassName(document, "ul", "listen");
	for (var j=0; j<listenEls.length; j++) {
		
		listenEls[j].onmouseover=function() {
			this.className+=" sfhover";
		}
		listenEls[j].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


//Displays the year's archive of posts
function openArchiveYear(archive_id) {
	if (document.getElementById) {
		var link_id = archive_id + "_link";
		
		if (document.getElementById(archive_id).className != "archive_year_open") {
			document.getElementById(archive_id).className = "archive_year_open";
			document.getElementById(link_id).className = "accordion_open";
		}
		else {
			document.getElementById(archive_id).className = "hidden";
			document.getElementById(link_id).className = "accordion";
		}
	}
	
}


//Displays the month's archive of posts
function openArchiveMonth(archive_id) {
	if (document.getElementById) {
		var link_id = archive_id + "_link";
		
		if (document.getElementById(archive_id).className != "archive_month_open") {
			document.getElementById(archive_id).className = "archive_month_open";
			document.getElementById(link_id).className = "accordion_open";
		}
		else {
			document.getElementById(archive_id).className = "hidden";
			document.getElementById(link_id).className = "accordion";
		}
	}
	
}



function showRssEmailForm(formId, posId) {
	if (document.getElementById) {
		var obj = document.getElementById(posId);
		var pos = findPos(obj);
		
		pos[1] += 20;
		
		document.getElementById(formId).style.left = pos[0] + 'px';
		document.getElementById(formId).style.top = pos[1] + 'px';
		document.getElementById(formId).style.display = 'block';
		document.rss_email_form.email_input.focus();
	}
}



/*  Utility Funcions -------------------------------------------------------------  */

/*
    Written by Jonathan Snook, http://www.snook.ca/jonathan
    Add-ons by Robert Nyman, http://www.robertnyman.com
*/

function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];      
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }   
    }
    return (arrReturnElements)
}





function changeClass(id, newClass) {
	if (document.getElementById) {
		document.getElementById(id).className = newClass;
	}
	
}


function hideBlock(id) {
	if (document.getElementById) {
		document.getElementById(id).style.display = "none";
	}
}

function showBlock(id) {
	if (document.getElementById) {
		document.getElementById(id).style.display = "block";
	}
}


function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}
