var currentNav = null; //tracks which nav item is selected
var opacityMin = 20;
var opacityMax = 100;
fadeSpeed = 30;
fadeStep = 10;
var isInitialized = null;
isScrolling = null; //var is set in scroll_Page script
//browser detection
var ie5 = (document.getElementById && document.all) ? true : false;
var ns6 = (document.getElementById && !document.all) ? true: false;

//object constructor for thumbnails
function makeThumb(obj) {
	this.fadeNavUp = obj_fadeUp;
	this.fadeNavDown = obj_fadeDown;
	this.fadeNavOff = obj_fadeOff;
	this.fadeLevel = opacityMin;
	this.timerFadeUp = null;
	this.timerFadeDown = null;
	this.timerLoop = null;
	this.obj = obj + "Object"
    eval(this.obj + "= this")
	return this
}

function fadeUp(index) {
	if (isInitialized && !isScrolling) {
		eval("thumb"+index+".fadeNavUp("+index+")");
	}
}
function obj_fadeUp(index) {
	clearTimeout(this.timerFadeDown);
	this.timerFadeDown = null;
	if (this.fadeLevel < opacityMax) {
		this.fadeLevel += fadeStep;
		if(ie5) document.getElementById("nav"+index).filters.alpha.opacity = this.fadeLevel;
		if(ns6) document.getElementById("nav"+index).style.MozOpacity = this.fadeLevel / 101;
		this.timerFadeUp = setTimeout(this.obj+".fadeNavUp("+index+")",fadeSpeed);
	}
	else {
		//this.fadeLevel = opacityMax;
		clearTimeout(this.timerFadeUp);
		this.timerFadeUp = null;
	}
}

function fadeDown(index) {
	if (isInitialized && index!=currentNav) {
		eval("thumb"+index+".fadeNavDown("+index+")");
	}
}
function obj_fadeDown(index) {
	clearTimeout(this.timerLoop);
	this.timerLoop = null;
	if (!this.timerFadeUp) {
		if (this.fadeLevel > opacityMin) {
			this.fadeLevel -= fadeStep;
			if(ie5) document.getElementById("nav"+index).filters.alpha.opacity = this.fadeLevel;
			if(ns6) document.getElementById("nav"+index).style.MozOpacity = this.fadeLevel / 101;
			this.timerFadeDown = setTimeout(this.obj+".fadeNavDown("+index+")",fadeSpeed);
		}
		else {
			//this.fadeLevel = opacityMin;
			clearTimeout(this.timerFadeDown);
			this.timerFadeDown = null;
		}
	}
	else { this.timerLoop = setTimeout(this.obj+".fadeNavDown("+index+")",fadeSpeed); }
}

function fadeClick(index) {
	if(isInitialized && index!=currentNav) {
		unselected = currentNav;
		fadeOff(unselected);
		currentNav = index;
		if (!eval("thumb"+index+".fadeLevel>opacityMin")) { fadeUp(index); }
	}
}
function fadeOff(index) {
	if (isInitialized) {
		eval("thumb"+index+".fadeNavOff("+index+")");
	}
}
function obj_fadeOff(index) {
	if (this.fadeLevel > opacityMin) {
		this.fadeLevel -= fadeStep;
		if(ie5) document.getElementById("nav"+index).filters.alpha.opacity = this.fadeLevel;
		if(ns6) document.getElementById("nav"+index).style.MozOpacity = this.fadeLevel / 100;
		this.timerFadeDown = setTimeout(this.obj+".fadeNavOff("+index+")",fadeSpeed);
	}
	else {
		this.fadeLevel = opacityMin;
		clearTimeout(this.timerFadeDown);
		this.timerFadeDown = null;
	}
}

//initialize
function initNavFade(index) {
	if (ie5 || ns6) {
		thumb0 = new makeThumb('nav0');
		thumb1 = new makeThumb('nav1');
		thumb2 = new makeThumb('nav2');
		thumb3 = new makeThumb('nav3');
		thumb4 = new makeThumb('nav4');
		thumb5 = new makeThumb('nav5');
		thumb6 = new makeThumb('nav6');
		thumb7 = new makeThumb('nav7');
		thumb8 = new makeThumb('nav8');
		thumb9 = new makeThumb('nav9');
		thumb10 = new makeThumb('nav10');
		isInitialized = true;
	}
	currentNav = (index) ? index : 0;
	fadeUp(currentNav);
}