// other.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();
	$('#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);
		getFilter(tempMoFilter);
		thisYear = "2009";
		showMe();
		//showMonth();	/**********************************************************************************DIFF********************/
		//getFilter(moFilter);
		setActiveLink();		
	});
	/*$('#news2012').click(function() {
		dsShell.setInternalDataSet(ds2012, true);
		getMoFilter();
		var tempMoFilter = ("2012-" + moFilter);
		getFilter(tempMoFilter);
		thisYear = "2012";
		showMe();
	}); */
	$('#news2011').click(function() {
		dsShell.setInternalDataSet(ds2011, true);
		getMoFilter();
		var tempMoFilter = ("2011-" + moFilter);
		thisYear = "2011";
		getFilter(tempMoFilter);
		showMe();
		//showMonth();
		getFilter(moFilter);
		setActiveLink();
		
	});
	
	
});


//This writes the year that is being shown by datassetShell into  <h1 id="mainHeading">News releases </h1>  
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() { 
	for (i = 0; i < 12; i++) {		
		$("#nrindex a").each(function() {
			$(this).removeClass('noshow');			
		});
	}
}

/* Sets the activeLink style to the nrindex month
	- removes all other instances of 'activeLink' class
	- adds 'activeLink' class 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');
         }
	 });
}


/* show the month name as H2 */
function setActive () { 
		$('#monthS').html(thisMonth);

}

/* Shows the month name as H2 in  <h2 id="monthS"></h2> */  
function showMonth() {
	if (currMo < monthNum) {
		//hideMe();
		moFilter = monthFilters[currMo];
		myFilter = filters[currMo];	
		$('#monthS').html(month[currMo]);
	}
	if (currMo == monthNum) {
		$('#monthS').html(month[currMo]);
	}	
		
}


/* 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];			
	}		
}


