
	function getMainPageLocation(category) {
		var pageURL = '../cata/cardDetail.html';
		if (category == ANIMALS) {
			pageURL = 'animframe.html';
		}
		else if (category == ALL_CARDS) {
			pageURL = 'cataframe.html'
		}
		return pageURL;
}


// add all thumbnails in the catalogue
function afterThumbsLoad() {
	if (parent.thumbnailDivs[0])  {
		//alert("thumbnails already created");
	}
	else {
		//alert("creating thumbnails");
		createParentDivArray();
		
		// set the correct main frame
		//alert("redirecting to frame");
		gotoCategoryFromFrame(parent.mainHash); 
		parent.mainframe.location.href = getMainPageLocation(parent.mainHash);
	}
}
	
function createParentDivArray() {
	for (var i=0; i<parent.cards.length; i++) {
  		var div = document.getElementById(i);
			parent.thumbnailDivs[i] = div;
		}
}
	

// show the thumbnails for the current category
function showThumbnailsForCategory(category) {
	if (parent.currentCat == category) {
		//alert("already showing category " + parent.currentCat);
		return currentCardIndex;
	}
		
	// avoid re-entry
	parent.currentCat = category;
	
	// reset the style of the old selected thumbnail
	parent.thumbnailDivs[currentCardIndex] = 'thumbnail';
	
	if (category == ALL_CARDS) {
		showAllThumbnails();
		return 0;
	}
	else {
		var currentCardIndex = -1;
		// go through all the thumbnails
		//alert("showing category " + category);
		//alert("array length: " + parent.thumbnailDivs.length);
  	for (var i=0; i<parent.thumbnailDivs.length; i++) {
  		var divToChange = parent.thumbnailDivs[i];
			//alert("checking " + divToChange.id + " against category " + category);	
			//alert( divToChange.innerHTML);
			//divToChange.style.border="solid red 1px";
			//alert("changed border");
	
	  	var cardIndex = parseInt(divToChange.id);
	  
			if (isInCategory(parent.cards[cardIndex][cardCategory], category)) {
				// the card is in the category
				//alert("inline");
				divToChange.style.display='inline';
				if (currentCardIndex == -1) {
					currentCardIndex = i;
				}
			}
			else {
				//alert("none");
				divToChange.style.display='none';		
			}
		}
		
		// move the thumbnail frame to the top anchor
		//location.href = "#" + currentCardIndex;
		//parent.thumbframe.location.hash = "card_" + currentCardIndex;
		
		//alert("scrolling");
		parent.thumbframe.scrollTo(0,0);

		return currentCardIndex;
	}
}

// show all the thumbnails
function showAllThumbnails() {	
  for (var i=0; i<parent.thumbnailDivs.length; i++) {
			parent.thumbnailDivs[i].style.display='inline';
	}
}