// Initializes stuff, depending on the browser 
var is = new Is();
var currentPage;

function Is() {
    var agent = navigator.userAgent.toLowerCase();
    this.NN  = ((agent.indexOf('mozilla')!=-1) && ((agent.indexOf('spoofer')==-1) && (agent.indexOf('compatible') == -1)));
    this.IE   = (agent.indexOf("msie") != -1);
}

//main page initialization
function mInitialize() {
    idImages = new Array("stories", "tribal", "society", "earth", "research", "gis_grants", "grants", "news", "help");
	onImages = new ImageArray("graphics/stories_main_on.gif", "graphics/tribal_main_on.gif", "graphics/society_main_on.gif", "graphics/earth_main_on.gif", "graphics/research_main_on.gif", "graphics/gis_grants_main_on.gif", "graphics/grants_main_on.gif", "graphics/news_main_on.gif", "graphics/help_main_on.gif");
	offImages = new ImageArray("graphics/stories_main_off.gif", "graphics/tribal_main_off.gif", "graphics/society_main_off.gif", "graphics/earth_main_off.gif", "graphics/research_main_off.gif", "graphics/gis_grants_main_off.gif", "graphics/grants_main_off.gif", "graphics/news_main_off.gif", "graphics/help_main_off.gif");
	descImages = new ImageArray("graphics/stories_desc.gif", "graphics/tribal_desc.gif", "graphics/society_desc.gif", "graphics/earth_desc.gif", "graphics/research_desc.gif", "graphics/gis_grants_desc.gif", "graphics/grants_desc.gif", "graphics/news_desc.gif", "graphics/white_stretch.gif");
	mOptions = new Array(idImages, onImages, offImages, descImages);
}


//sub page initialization
function Initialize() {
	iconImages = new ImageArray("graphics/stories_icon_bar.gif", "graphics/society_icon_bar.gif", "graphics/earth_icon_bar.gif", "graphics/research_icon_bar.gif", "graphics/grants_icon_bar.gif", "graphics/news_icon_bar.gif", "graphics/help_icon_bar.gif", "graphics/none_icon_bar.gif");
	textImages = new ImageArray("graphics/stories_text_bar.gif", "graphics/society_text_bar.gif", "graphics/earth_text_bar.gif", "graphics/research_text_bar.gif", "graphics/grants_text_bar.gif", "graphics/news_text_bar.gif", "graphics/help_text_bar.gif", "graphics/white_stretch.gif");
	sOptions = new Array(iconImages, textImages);
}

//sets current page - used for rollovers
function setPage(num) {
	currentPage = num
}

// preloads images and aranges them in an array for later access  
function ImageArray() {			
	var imageFiles = ImageArray.arguments
	this.length = imageFiles.length;
	for (var i=0; i<=imageFiles.length ; i++) {
			this[i] = new Image();
			this[i].src = imageFiles[i];
	}
	return this;
}

// Gets image object reference (called by mShow and mHide)
function getImage(imagename) {
	if (is.NN) {
		daImage = document.images[imagename];
	} else if (is.IE) {
		daImage = document[imagename];
	}
	return daImage;
}


// THESE FUNCTIONS CONTROL THE SUB PAGES 

function mShow(topic) {
	getImage('iconBar').src = sOptions[0][topic].src;
	getImage('textBar').src = sOptions[1][topic].src;
}

function mHide() {
	getImage('iconBar').src = sOptions[0][7].src;
    getImage('textBar').src = sOptions[1][7].src;

}

function mReturn() {
	getImage('iconBar').src = sOptions[0][currentPage].src;
	getImage('textBar').src = sOptions[1][currentPage].src;

}