// other_d.js JavaScript Document -- all jquery stuff

$(function() {
	$('#nrindex a').click(function() {
		$('#nrindex a').removeClass('activeLink'); 
		$(this).addClass('activeLink');
		var temp = $(this).attr('title');
		myFilter = ("show" + temp.substr(0,3));
		$('#monthS').html(temp);
	});
	setActive();
	setActiveLink();
	showMe();
	/*$('#news2008').click(function() {
		dsShell.setInternalDataSet(ds2008, true);
		getMoFilter();
		var tempMoFilter = ("2008-" + moFilter);
		getFilter(tempMoFilter);
		thisYear = "2008";
		showMe();
	});
	$('#news2010').click(function() {
		dsShell.setInternalDataSet(ds2010, true);
		getMoFilter();
		var tempMoFilter = ("2010-" + moFilter);
		getFilter(tempMoFilter);
		thisYear = "2010";
		showMe();
	}); */
	$('#news2009').click(function() {
		dsShell.setInternalDataSet(ds2009, true);
		getMoFilter();
		var tempMoFilter = ("2009-" + moFilter);
		thisYear = "2009";
		
		getFilter(tempMoFilter);
		showMe();
		showMonth();
		getFilter(moFilter);
		setActiveLink();		
	});
	
	
});


function showMe() {
	var currThisYear;
	if (thisYear != theYear) { 
		unhideMe();
		currThisYear = 'News releases ' + thisYear;
	 }
	 else {
		hideMe();
	 	currThisYear = 'News releases ' + theYear;
	  }
	$('#mainHeading').html(currThisYear);
}

/* add class 'noshow' to future months to make look disabled - light grey*/
function hideMe() { 
	var currMo = Date.today().getMonth();
	for (i = currMo+1; i < 12; i++) {
		var tempM = month[i];
		$("#nrindex a").each(function() {
			var myID = $(this).attr("id");
			if (myID == tempM) {
                $(this).addClass('noshow');
         }
		});
	}
}

/* to show all #nrindex list for previous years*/
/*remove class 'noshow' on all #nrindex a */
function unhideMe() { 
	//var currMo = Date.today().getMonth();
	for (i = 0; i < 12; i++) {		
		$("#nrindex a").each(function() {
			$(this).removeClass('noshow');			
		});
	}
}

/* remove all 'activeLink' class, add 'activeLink' to selected month */
function setActiveLink() {
	$('#nrindex a').removeClass('activeLink'); 
	var activeMo = thisMonth;
   $("#nrindex a").each(function() {
        var myID = $(this).attr("id");
        if (myID == activeMo) {
                $(this).addClass('activeLink');
         }
	 });
}

/* set the month name as H2 */
function showMonth() {
	if (currMo < monthNum) {
		//hideMe();
		moFilter = monthFilters[currMo];
		myFilter = filters[currMo];	
		$('#monthS').html(month[currMo]);
	}
	if (currMo == monthNum) {
		$('#monthS').html(month[currMo]);
	}	
		
}

/* hide the rightside year list*/
function hideYearList () {
	if (thisYear == 2009) { 
		$('#yearList').hide();
	 }
}
/* get the filter to apply from the clicked #nrindex a */
/* compare it to set moFilter, monthNum, and thisMonth */ 
function getMoFilter () {
	if (myFilter == "showJan") {
		moFilter = "01";
		monthNum = 0;
		thisMonth = month[0];
	}
	if (myFilter == "ShowFeb") {
		moFilter = "02";
		monthNum = 1;
		thisMonth = month[1];
	}
	if (myFilter == "showMar") {
		moFilter = "03";
		monthNum = 2;
		thisMonth = month[2];
	}
	if (myFilter == "showApr") {
		moFilter = "04";
		monthNum = 3;
		thisMonth = month[3];
	}
	if (myFilter == "showMay") {
		moFilter = "05";
		monthNum = 4;
		thisMonth = month[4];
	}
	if (myFilter == "showJun") {
		moFilter = "06";
		monthNum = 5;
		thisMonth = month[5];
	}
	if (myFilter == "showJul") {
		moFilter = "07";
		monthNum = 6;
		thisMonth = month[6];
	}
	if (myFilter == "showAug") {
		moFilter = "08";
		monthNum = 7;
		thisMonth = month[7];
	}
	if (myFilter == "showSep") {
		moFilter = "09";
		monthNum = 8;
		thisMonth = month[8];	
	}
	if (myFilter == "showOct") {
		moFilter = "10";
		monthNum = 9;
		thisMonth = month[9];			
	}
	if (myFilter == "showNov") {
		moFilter = "11";
		monthNum = 10;
		thisMonth = month[10];	
	}
	if (myFilter == "showDec") {
		moFilter = "12";
		monthNum = 11;
		thisMonth = month[11];			
	}		
}

/* show the month name as H2 */
function setActive () { 
		$('#monthS').html(thisMonth);

}


/*function showMe() {
	var currThisYear;
	var theYear = Date.today().getFullYear(); 
	if (thisYear == theYear) { 
		hideMe();
		currThisYear = 'News releases 2009';
		//hideYearList();
	 }
	 if (thisYear == 2010) { 
	 	unhideMe();
		currThisYear = 'News releases 2010';
	 }
	 if (thisYear == 2008) { 
	 	unhideMe();
		currThisYear = 'News releases 2008';
	 }
	$('#mainHeading').html(currThisYear);
}*/