selectedCategories = 0;

function highlightLink(categoryNumber) {

	categoryLink = document.getElementById('link_'+categoryNumber);
	categoryLink.style.textDecoration = 'underline';
	categoryLink.style.cursor = 'pointer';
	
	for( i=0; i<categoryArticles[categoryNumber].length; i++ ) {
		articleLink = document.getElementById('anchor_'+categoryArticles[categoryNumber][i]);
		articleLink.style.color = '#f15b74';
	}

}



function unhighlightLink(categoryNumber) {
	
	categoryLink = document.getElementById('link_'+categoryNumber);
	categoryLink.style.textDecoration = 'none';
	categoryLink.style.cursor = 'default';
	
	for( i=0; i<categoryArticles[categoryNumber].length; i++ ) {
		articleLink = document.getElementById('anchor_'+categoryArticles[categoryNumber][i]);
		articleLink.style.color = '#b11b34';
	}
	
}


function toggleCategory(categoryNumber) {
	
	// Update set of visible categories
	
	if ( selectedCategories == 0 ) {
		for( catNum in categoryVisible ) {
			categoryVisible[catNum] = false;
		}
		categoryVisible[categoryNumber] = true;
		selectedCategories++;
	}
	else if ( selectedCategories == 1 && categoryVisible[categoryNumber] ) {
		for( catNum in categoryVisible ) {
			categoryVisible[catNum] = true;
		}
		selectedCategories--;
	}
	else if ( categoryVisible[categoryNumber] ) {
		categoryVisible[categoryNumber] = false;
		selectedCategories--;
	}
	else {
		categoryVisible[categoryNumber] = true;
		selectedCategories++;
	}
	
	for ( catNum in categoryVisible ) {
		categoryLink = document.getElementById('link_'+catNum);
		if ( selectedCategories == 0 ) {
			categoryLink.style.color = '#777777';
		}
		else {
			if ( categoryVisible[catNum] ) {
				categoryLink.style.color = '#b11b34';
			}
			else {
				categoryLink.style.color = '#777777';
			}
		}
	}
	
	articleVisible = new Array();
	for( i=0; i<allArticles.length; i++ ) {
		articleVisible[allArticles[i]] = true;
	}
		
	if ( selectedCategories > 0 )  { // Articles visible by category
		
		for ( catNum in categoryVisible ) {
			if ( categoryVisible[catNum] ) {
				// Make articles not in category invisible
				for( i=0; i<allArticles.length; i++ ) {
					searchingForArticle = allArticles[i];
					foundArticle = false;
					for( j=0; j<categoryArticles[catNum].length; j++ ) {
						if ( categoryArticles[catNum][j] == searchingForArticle) {
							foundArticle = true;
							break;
						}
					}
					if ( !foundArticle ) {
						articleVisible[searchingForArticle] = false;
					}
				}
			}
		}
		
	}
	
	// Display visible articles
	
	for( artIndex=0; artIndex<allArticles.length; artIndex++ ) {
		articleLink = document.getElementById('article_'+allArticles[artIndex]);
		if ( articleVisible[allArticles[artIndex]] ) {
			articleLink.style.display = 'list-item';
		}
		else {
			articleLink.style.display = 'none';
		}
	}
	
	// Display visible months
	
	for( monthName in monthArticles ) {
		displayMonth = false;
		for( i=0; i<monthArticles[monthName].length; i++ ) {
			if ( articleVisible[monthArticles[monthName][i]] ) {
				displayMonth = true;
				break;
			}
		}
		monthList 		= document.getElementById('list_'+monthName);
		monthHeading	= document.getElementById('heading_'+monthName);
		if ( displayMonth ) {
			monthList.style.display		= 'block';
			monthHeading.style.display	= 'block';
		}
		else {
			monthList.style.display 	= 'none';
			monthHeading.style.display	= 'none';
		}
	} 
	
}