//NEWS ARCHIVE
$(document).ready(function(){
	genNav(document.getElementById("ulIRNews").getElementsByTagName('li')[0].className);
	var old; var num;
});

function genNav(mry) {
	//Create Navigation with past 6 years, find most recent year, then create a list with the other 6 years
	var yearList = new Array;
	num = 6;//# years to display in year-tab navigation, including the current year.
	for(i=0; i<num;i++) {
		yearList[i] = parseInt(mry, 10)-i;
	}
	var output = "";
	for (i=0; i<yearList.length;i++)
	{
		output+= "<li class='"+yearList[i]+"'><a onClick='javascript: selectYear("+yearList[i]+"); return false;'>" + yearList[i] + "</a></li>";
	}
	old = "old";
	output += "<li class='old'><a onClick='javascript: selectYear("+old+"); return false;'>Older Archives</a></li>";
	document.getElementById("selYearNav").innerHTML = output;
	selectYear(mry);
}


function selectYear(mry) {
	//Hide all news releases that are not from the selected year; then make sure the releases from the current year are visible
	$("#ulIRNews li").addClass("hide");
	var yearList = new Array;
	if (mry == "old") {
		$("#ulIRNews li").removeClass("hide");
			for(i=0; i<num;i++) {
				yearList[i] = parseInt(document.getElementById("ulIRNews").getElementsByTagName('li')[0].className, 10)-i;
				$("#ulIRNews ."+yearList[i]).addClass("hide");
		}
	}
	var mry = parseInt(mry, 10);
	$("#ulIRNews ."+mry).removeClass("hide");
	//select currently displaying tab
	$("#selYearNav li a").removeClass("selected");
	$("."+mry+" a").addClass("selected");
	if(!$("#selYearNav")[0].innerHTML.match(mry)){
		$(".old a").addClass("selected");
	}
}

