var navList = new Array(
	'gt/|greek thoughts',
	'at/|aramaic thoughts',
	'ht/|hebrew thoughts',
	'ds/|difficult sayings',
	'daily_reading.cgi|daily reading plan',
	'custom_plan.cgi|customized bible reading plan',
	'bnb/|albert barne\'s',
	'geb/|john gill',
	'gsb/|geneva study bible',
	'jfb/|commentary critical',
	'kdo/|keil & delitzsch',
	'mhm/|matthew henry complete',
	'mhn/|matthew henry concise',
	'pnt/|people\'s new testament',
	'rwp/|robertson\'s word pictures',
	'tsk/|treasury of scripture knowledge',
	'vnt/|vincent\'s word pictures',
	'wes/|wesley\'s explanatory notes',
	'ntb/|nave\'s topical bible',
	'tcr/|thompson chain reference',
	'tsk/|treasury of scripture knowledge',
	'ttt/|torrey\'s new topical testbook',
	'ats/|american tract society bible dicionary',
	'bed/|baker evangelical dictionary',
	'ebd/|easton bible dictionary',
	'fbd/|fasset bible dictionary',
	'hbd/|holman bible dictionary',
	'hbn/|hitchcock bible names dictionary',
	'kjd/|king james dictionary',
	'sbd/|smith bible dictionary',
	'web/|webster dictionary',
	'cbc/|condensed biblical cyclopedia',
	'isb/|international standard bible encyclopedia',
	'tce/|the catholic encyclopedia',
	'ara/|aramaic lexicon',
	'grk/|greek lexicon',
	'heb/|hebrew lexicon',
	'aip/|aramaic interlinear project',
	'new/|site development',
	'help/|help pages',
	'about.html|about sl',
	'contact.cgi|contact sl',
	'statementoffaith.html|statement of faith',
	'permissions.html|rights and permissions',
	'privacypolicy.html|privacy policy',
	'termsofuse.html|terms of use'
);

var navList_timerlen = 15;
var navList_slideAniLen = 150;

var navList_timerID = new Array();
var navList_startTime = new Array();
var navList_obj = new Array();
var navList_endHeight = new Array();
var navList_moving = new Array();
var navList_dir = new Array();
var navList_currentSecname = '';

var navList_scrollStep = 8;

var navList_timerLeft = '';
var navList_timerRight = '';
var navList_timerUp = '';
var navList_timerDown = '';

function navList_buildDiv(id){
	var obj = getObjectPosition('navbar');
	var mDiv = document.createElement("Div");
		mDiv.style.position = 'absolute';
		mDiv.style.overflow = 'hidden';
		mDiv.style.display = 'none';
		mDiv.style.border = '#666193 solid 1px';
		mDiv.style.font = '600 10px arial,heletica,sans-serif';
		mDiv.style.top = (obj.y + obj.z) + 'px';
		mDiv.style.left = obj.x + "px";
		mDiv.style.height = 20 + 'px';
		mDiv.style.width = obj.w + 'px';
		mDiv.style.backgroundColor = '#D6D7E7';
		mDiv.id = id;
		mDiv.style.zIndex = '100';	

	/*  Create the table to hold the header info */
	var curTbl = document.createElement("Table");
		curTbl.width = obj.w;
		curTbl.style.font = '600 10px arial,heletica,sans-serif';
		curTbl.style.textDecoration = 'none';
		curTbl.cellpadding = 0;
		curTbl.cellspacing = 0;
		curTbl.border = 0;

	/* Create table row */
	var curTR = curTbl.insertRow(0);

	/* Create "Left Arrow" cell */
	var curTD1 = curTR.insertCell(0);
		curTD1.width = 15;
		curTD1.align = 'right';
		if (ie) { 
			curTD1.style.paddingBottom = 6 + 'px'; 
		} else {
			curTD1.style.paddingBottom = 4 + 'px';
		}
		
	/* Create "Left Arrow" cell */
		var curTD1Div1 = document.createElement("Div");
			curTD1Div1.id = 'navList_left_arrow_active';
			curTD1Div1.style.display = 'block';
			
			var curTD1Div1Arrow = document.createElement("Img");
				curTD1Div1Arrow.src = '/images/arrow_left_active.gif';
				curTD1Div1Arrow.height= 10;
				curTD1Div1Arrow.width = 10;
				curTD1Div1Arrow.border = 0;
				curTD1Div1Arrow.onmouseover=function(){ div_Scroller('container','right') };
				curTD1Div1Arrow.onmouseout=function(){ div_Scroller('container','stop') };
				curTD1Div1Arrow.onclick=function(){ div_Scroller('container','begin') };
				curTD1Div1.appendChild(curTD1Div1Arrow);
			curTD1.appendChild(curTD1Div1);		
		
		var curTD1Div2 = document.createElement("Div");
			curTD1Div2.id = 'navList_left_arrow_inactive';
			curTD1Div2.style.display = 'none';
			
			var curTD1Div2Arrow = document.createElement("Img");
				curTD1Div2Arrow.src = '/images/arrow_left_inactive.gif';
				curTD1Div2Arrow.height = 10;
				curTD1Div2Arrow.width = 10;
				curTD1Div2Arrow.border = 0;
				curTD1Div2.appendChild(curTD1Div2Arrow);
			curTD1.appendChild(curTD1Div2);

	/* Create "container" cell */
	var curTD2 = curTR.insertCell(1);
		curTD2.valign = 'top';
		
		var curTD2Div1 = document.createElement("Div");
			curTD2Div1.id = 'container';
			
			var curTD2Div1Div = document.createElement("Div");
				curTD2Div1Div.id = 'navScroller';
				curTD2Div1Div.style.float = 'left';
				curTD2Div1Div.style.margin = 0;
				curTD2Div1Div.style.width = 1550 + 'px';

			curTD2Div1.appendChild(curTD2Div1Div);		
		curTD2.appendChild(curTD2Div1);		
		
	var curTD3 = curTR.insertCell(2);
		curTD3.width = 15;
		curTD3.align = 'left';
		if (ie) { 
			curTD3.style.paddingBottom = 6 + 'px'; 
		} else {
			curTD3.style.paddingBottom = 4 + 'px';
		}

		var curTD3Div1 = document.createElement("Div");
			curTD3Div1.id = 'navList_right_arrow_active';
			curTD3Div1.style.display = 'block';
			
			var curTD3Div1Arrow = document.createElement("Img");
				curTD3Div1Arrow.src = '/images/arrow_right_active.gif';
				curTD3Div1Arrow.height = 10;
				curTD3Div1Arrow.width = 10;
				curTD3Div1Arrow.border = 0;
				curTD3Div1Arrow.onmouseover=function(){ div_Scroller('container','left') };
				curTD3Div1Arrow.onmouseout=function(){ div_Scroller('container','stop') };
				curTD3Div1Arrow.onclick=function(){ div_Scroller('container','end') };
			curTD3Div1.appendChild(curTD3Div1Arrow);
		curTD3.appendChild(curTD3Div1);		
		
		var curTD3Div2 = document.createElement("Div");
			curTD3Div2.id = 'navList_right_arrow_inactive';
			curTD3Div2.style.display = 'none';
			
			var curTD3Div2Arrow = document.createElement("Img");
				curTD3Div2Arrow.src = '/images/arrow_right_inactive.gif';
				curTD3Div2Arrow.height = 10;
				curTD3Div2Arrow.width = 10;
				curTD3Div2Arrow.border = 0;
			curTD3Div2.appendChild(curTD3Div2Arrow);
		curTD3.appendChild(curTD3Div2);
		
	mDiv.appendChild(curTbl);

	var curDivLeftFade = document.createElement("Div");
		curDivLeftFade.id = 'navList_left_fade';
		curDivLeftFade.style.position = 'absolute';
		curDivLeftFade.style.display = 'none';
		curDivLeftFade.style.top = 0 + 'px';
		curDivLeftFade.style.left = 17 + "px";
		
		var curDivLeftFadeImg = document.createElement("Img");
			curDivLeftFadeImg.src = '/images/fade_left.gif';
			curDivLeftFadeImg.height = 20;
			curDivLeftFadeImg.width = 30;
			curDivLeftFadeImg.border = 0;
			curDivLeftFade.appendChild(curDivLeftFadeImg);
	mDiv.appendChild(curDivLeftFade);
		
	var curDivRightFade = document.createElement("Div");
		curDivRightFade.id = 'navList_right_fade';
		curDivRightFade.style.position = 'absolute';
		curDivRightFade.style.top = 0 + 'px';
		curDivRightFade.style.left = 923 + "px";
	
		var curDivRightFadeImg = document.createElement("Img");
			curDivRightFadeImg.src = '/images/fade_right.gif';
			curDivRightFadeImg.height = 20;
			curDivRightFadeImg.width = 30;
			curDivRightFadeImg.border = 0;
			curDivRightFade.appendChild(curDivRightFadeImg);
	mDiv.appendChild(curDivRightFade);

	document.body.appendChild(mDiv);	
}

function navList_updateList(secname){
	if(document.getElementById('navList') == null){
		navList_buildDiv('navList');
	} else {
		document.getElementById('navList_left_fade').style.display = 'none';
		document.getElementById('navList_right_fade').style.display = 'block';
	}

	var obj = document.getElementById('navScroller');
	var id = 'navList';
	if (secname == navList_currentSecname){
		div_Slider(id, 'up');
		navList_currentSecname = '';
	} else {
		var wb = 'inactive';
		var curList = new Array;
		switch (secname) {
			case 'ls':
				curList = navList.slice(0,4);
				break;
			case 'plan':
				curList = navList.slice(4,6);
				break;
			case 'par':
				break;
			case 'com':
				curList = navList.slice(6,18);
				wb = 'active'
				break;
			case 'con':
				curList = navList.slice(18,22);
				break;
			case 'dic':
				curList = navList.slice(22,31);
				wb = 'active'
				break;
			case 'enc':
				curList = navList.slice(31,34);
				break;
			case 'lex':
				curList = navList.slice(34,37);
				break;
			case 'his':
				break;
			case 'pro':
				curList = navList.slice(37,39);
				break;
			case 'info':
				curList = navList.slice(39,45);
				break;
		}

		var curUL = document.getElementById('secondary');
		if(curUL == null){
			var curUL = document.createElement("UL");
				curUL.id = 'secondary';
				obj.appendChild(curUL);
		} else {
			while (curUL.hasChildNodes()) {
				curUL.removeChild(curUL.lastChild);
			}
		}
		
		var curLI = document.createElement("LI");
				var curLI1A = document.createElement("A");
					curLI1A.href = 'http://new.studylight.org/' + secname + '/';
					var curLI1AText = document.createTextNode('main page');
						curLI1A.appendChild(curLI1AText);
					curLI.appendChild(curLI1A);
				curUL.appendChild(curLI);

		for (var i=0; i<curList.length; i++){
			var parts = curList[i].split('|');

			var curLI = document.createElement("LI");
				var curLI1A = document.createElement("A");
					curLI1A.href = 'http://new.studylight.org/' + secname + '/' + parts[0];
					var curLI1AText = document.createTextNode(parts[1]);
						curLI1A.appendChild(curLI1AText);
					curLI.appendChild(curLI1A);
				curUL.appendChild(curLI);
		}
		document.getElementById('container').scrollLeft = 0;
		document.getElementById('navList_left_arrow_active').style.display = (wb == 'active') ? 'block' : 'none';
		document.getElementById('navList_left_arrow_inactive').style.display = (wb == 'active') ? 'none' : 'block';
		document.getElementById('navList_right_arrow_active').style.display = (wb == 'active') ? 'block' : 'none';
		document.getElementById('navList_right_arrow_inactive').style.display = (wb == 'active') ? 'none' : 'block';

		if(document.getElementById(id).style.display == 'none'){
			div_Slider(id, 'down');
		}

		var A_array = obj.getElementsByTagName("A") ;
		var newlen = 0;
		for(var r=0; r<A_array.length; r++) {
			newlen += A_array[r].offsetWidth;
		}
		document.getElementById('navScroller').style.width = newlen;

		navList_currentSecname = secname;
	}
}

function div_Slider(id, dir) {
	_startslide = function(id){
		navList_obj[id] = document.getElementById(id);

		navList_endHeight[id] = parseInt(navList_obj[id].style.height);

		navList_startTime[id] = (new Date()).getTime();

		if(navList_dir[id] == "down"){
			navList_obj[id].style.height = "1px";
		}

		navList_obj[id].style.display = "block";

		navList_timerID[id] = setInterval('_slidetick(\'' + id + '\');',navList_timerlen);
	}

	_slidetick = function(id){
		var elapsed = (new Date()).getTime() - navList_startTime[id];
		if (elapsed > navList_slideAniLen){
			_endSlide(id)
		} else {
			var d = Math.round(elapsed / navList_slideAniLen * navList_endHeight[id]);
			if(navList_dir[id] == "up"){
				d = navList_endHeight[id] - d;
			}
			navList_obj[id].style.height = d + "px";
		}
		return;
	}

	_endSlide = function(id){
		clearInterval(navList_timerID[id]);

		if(navList_dir[id] == "up")
			navList_obj[id].style.display = "none";
	
		navList_obj[id].style.height = navList_endHeight[id] + "px";

		delete(navList_moving[id]);
		delete(navList_timerID[id]);
		delete(navList_startTime[id]);
		delete(navList_endHeight[id]);
		delete(navList_obj[id]);
		delete(navList_dir[id]);

		return;
	}

	switch(dir){
		case 'down':
			if(navList_moving[id])
				return;

			if(document.getElementById(id).style.display != "none")
				return; // cannot slide down something that is already visible

			navList_moving[id] = true;
			navList_dir[id] = "down";
			_startslide(id);
			break;
		case 'up':
			if(navList_moving[id])
				return;

			if(document.getElementById(id).style.display == "none")
				return; // cannot slide up something that is already hidden

			navList_moving[id] = true;
			navList_dir[id] = "up";
			_startslide(id);
			break;
	}
}

function div_Scroller(id,dir){
	switch(dir){
		case 'begin':
			document.getElementById(id).scrollLeft=0;
			break;
		case 'top':
			document.getElementById(id).scrollTop = 0;
			break;
		case 'left':
			clearTimeout(navList_timerRight);
			document.getElementById(id).scrollLeft+=navList_scrollStep;
			navList_timerRight=setTimeout("div_Scroller('"+id+"','left')",10);
			break;
		case 'up':
			clearTimeout(navList_timerDown);
			document.getElementById(id).scrollTop-=navList_scrollStep;
			navList_timerDown=setTimeout("div_Scroller('"+id+"','up')",10);
			break;
		case 'right':
			clearTimeout(navList_timerLeft);
			document.getElementById(id).scrollLeft-=navList_scrollStep;
			navList_timerLeft=setTimeout("div_Scroller('"+id+"','right')",10);
			break;
		case 'down':
			clearTimeout(navList_timerUp);
			document.getElementById(id).scrollTop+=navList_scrollStep;
			navList_timerUp=setTimeout("div_Scroller('"+id+"','down')",10);
			break;
		case 'end':
			document.getElementById(id).scrollLeft=document.getElementById(id).scrollWidth;
			break;
		case 'bottom':
			document.getElementById(id).scrollTop=document.getElementById(id).scrollHeight;
			break;
		case 'stop':
			clearTimeout(navList_timerRight); 
			clearTimeout(navList_timerLeft);
			clearTimeout(navList_timerUp);
			clearTimeout(navList_timerDown);
			break;
	}
	document.getElementById('navList_left_fade').style.display = (document.getElementById(id).scrollLeft == 0) ? 'none' : 'block';
	document.getElementById('navList_right_fade').style.display = (document.getElementById(id).scrollLeft == (document.getElementById(id).scrollWidth - 933)) ? 'none' : 'block';
}
