// JavaScript Document
/* This script and many more are available free online at
The JavaScript Source :: http://javascript.internet.com
Created by: Alf Magne Kalleland :: http://www.dhtmlgoodies.com/ */

/************************************************************************************************************
	(C) www.dhtmlgoodies.com, September 2005
	Terms of use: You are free to use this script as long as the copyright message is kept intact. However,
 you may not redistribute, sell or repost it without our permission.

	Alf Magne Kalleland
************************************************************************************************************/		
	
var initHeight = 0;
var slidedown_direction = 1;
var slidedownContentBox = false;
var slidedownContent = false;
var slidedownActive = false;
var contentHeight = false;
var slidedownSpeed = 6; 	// Higher value = faster script
var slidedownTimer = 7;		// Lower value = faster script
var slidedownIndex = -1;	// keep track of which info box is currently open

function slidedown_showHide_start() {

	if(!slidedownActive)
		return;
	initHeight = initHeight/1 + slidedown_direction;
	
	if(initHeight <= 0) {
		slidedownActive = false; 
		slidedownContentBox.style.visibility='hidden';
		initHeight = 0;
	}
	
	if(initHeight>contentHeight) {
		slidedownActive = false; 
	}
	
	slidedownContentBox.style.height = initHeight + 'px';
	slidedownContent.style.top = initHeight - contentHeight + 'px';
	setTimeout('slidedown_showHide_start()',slidedownTimer); // Choose a lower value than 10 to make the script move faster
}//slidedown_showHide_start()



function slidedown_showHide(index) {
	var ctntBx = 'infoBox_contentBox' + index;
	var ctnt   = 'infoBox_content' + index;
	var ntImg  = 'infoNoteImg' + index;

	//reset
	//slidedownContentBox = false;
	slidedownContentBox = document.getElementById(ctntBx);
	slidedownContent = document.getElementById(ctnt);
	
	//if clicking on same info button as before, or if no info boxes are open
	if ((index == slidedownIndex) ||
		 (slidedownIndex == -1)) {
		//then, if the contentBox is already visible, hide it
		if(slidedownContentBox.style.visibility == 'visible') {
			document.getElementById(ntImg).src="http://bcd.tamhsc.edu/library/img/web/misc/info-note+.gif";
			document.getElementById(ntImg).title="Show info";
			contentHeight = document.getElementById(ctnt).offsetHeight;
			slidedown_direction = slidedownSpeed*-1;
			slidedownActive = true;
			slidedownIndex = -1;
			slidedown_showHide_start();
		}
		//otherwise, open the indicated contentBox
		else {
			document.getElementById(ntImg).src="http://bcd.tamhsc.edu/library/img/web/misc/info-note-.gif";
			document.getElementById(ntImg).title="Hide info";
			contentHeight = document.getElementById(ctnt).offsetHeight;
			slidedown_direction=slidedownSpeed;
			slidedownContentBox.style.visibility='visible';
			slidedownActive = true;
			slidedownIndex = index;
			slidedown_showHide_start();
		}
	}

	//else, an info box is already open and they are clicking on another one
	//close the open one first, then open the new one
	else {
			var PntImg = 'infoNoteImg' + slidedownIndex;
			var PctntBx = 'infoBox_contentBox' + slidedownIndex;
			var Pctnt = 'infoBox_content' + slidedownIndex;
			
		//first close the previously opened info box
		slidedownContentBox = document.getElementById(PctntBx);
		slidedownContent = document.getElementById(Pctnt);
		document.getElementById(PntImg).src="http://bcd.tamhsc.edu/library/img/web/misc/info-note+.gif";
		document.getElementById(PntImg).title="Show info";
		slidedownContentBox.style.visibility='hidden';
		initHeight=0;
		
		//now open the new info box
		slidedownContentBox = document.getElementById(ctntBx);
		slidedownContent = document.getElementById(ctnt);
		document.getElementById(ntImg).src="http://bcd.tamhsc.edu/library/img/web/misc/info-note-.gif";
		document.getElementById(ntImg).title="Hide info";
		contentHeight = document.getElementById(ctnt).offsetHeight;
		slidedown_direction=slidedownSpeed;
		slidedownContentBox.style.visibility='visible';
		slidedownActive = true;
		slidedownIndex = index;
		slidedown_showHide_start();
	}

//	if(initHeight==0) {
//		slidedown_direction=slidedownSpeed;
//		document.getElementById(ntImg).src="http://bcd.tamhsc.edu/library/img/web/misc/info-note-.gif";
//	}
//	else {
//		slidedown_direction = slidedownSpeed*-1;
//		document.getElementById(ntImg).src="http://bcd.tamhsc.edu/library/img/web/misc/info-note+.gif";
//	}
	//  if(!slidedownContentBox) {
//		slidedownContentBox = document.getElementById(ctntBx);
//		slidedownContent = document.getElementById(ctnt);
//		contentHeight = document.getElementById(ctnt).offsetHeight;
	//  }
//	slidedownContentBox.style.visibility='visible';
//	slidedownActive = true;
//	slidedown_showHide_start();
}//slidedown_showHide()



function slidedown_showHide_EJMenu() {
	if(initHeight==0) {
		slidedown_direction=slidedownSpeed;
	}
	else {
 		slidedown_direction = slidedownSpeed*-1;
	}
	if(!slidedownContentBox) {
		slidedownContentBox = document.getElementById('infoBox_contentBox_EJMenu');
		slidedownContent = document.getElementById('infoBox_content_EJMenu');
		contentHeight = document.getElementById('infoBox_content_EJMenu').offsetHeight;
	}
	slidedownContentBox.style.visibility='visible';
	slidedownActive = true;
	slidedown_showHide_start();
}//slidedown_showHide_EJMenu()



function showHide_Ebooks(index) {
		var elId = 'infoNote' + index;
		var cBoxId = 'infoBox_contentBox' + index;
		var contId = 'infoBox_content' + index;
		
	//reset
	//slidedownContentBox = false;
	slidedownContentBox = document.getElementById(cBoxId);
	slidedownContent = document.getElementById(contId);
	
	//if clicking on same info button as before, or if no info boxes are open
	if ((index == slidedownIndex) ||
		 (slidedownIndex == -1)) {
		//then, if the contentBox is already visible, hide it
		if(slidedownContentBox.style.visibility == 'visible') {
			slidedownContentBox.style.visibility='hidden';
			document.getElementById(elId).src="http://bcd.tamhsc.edu/library/img/web/misc/info-more.gif";
			document.getElementById(elId).title="More info";
			slidedownIndex = -1;
		}
		//otherwise, open the indicated contentBox
		else {
			slidedownContentBox.style.visibility='visible';
			document.getElementById(elId).src="http://bcd.tamhsc.edu/library/img/web/misc/info-less.gif";
			document.getElementById(elId).title="Less info";
			slidedownIndex = index;
		}
	}
	
	//else, an info box is already open and they are clicking on another one
	//close the open one first, then open the new one
	else {
			var PelId = 'infoNote' + slidedownIndex;
			var PcBoxId = 'infoBox_contentBox' + slidedownIndex;
			var PcontId = 'infoBox_content' + slidedownIndex;
			
		PslidedownContentBox = document.getElementById(PcBoxId);
		PslidedownContent = document.getElementById(PcontId);
		
		//first close the previously opened info box
		PslidedownContentBox.style.visibility='hidden';
		document.getElementById(PelId).src="http://bcd.tamhsc.edu/library/img/web/misc/info-more.gif";
		document.getElementById(PelId).title="More info";
		
		//now open the new info box
		slidedownContentBox.style.visibility='visible';
		document.getElementById(elId).src="http://bcd.tamhsc.edu/library/img/web/misc/info-less.gif";
		document.getElementById(elId).title="Less info";
		slidedownIndex = index;
	}
}//showHide_Ebooks()


//************************************************************************************************
// showHide_DBs
//   This function makes the div with id="id" visible (display: ''), 
//      and all other divs with class="name" are hidden (display:'none')
//	It also changes the class name of the row with the "i" being clicked
//		and changes back to default (TableRow) for all others
//
//************************************************************************************************
function showHide_DBs(id, name){
	//grab the digit off the end of the passed ID
	idNum = (id.slice(7));
//alert(idNum);
	rowId = 'resultRow' + idNum;
	imgId = 'infoNote' + idNum;

	//if the row infoBox is already displayed, then hide it
	if (document.getElementById(id).style.display=="") {
	   document.getElementById(id).style.display = "none";
	   //also change the class for the associated row in the table
	   document.getElementById(rowId).className='TableRow';
	   document.getElementById(imgId).src='http://bcd.tamhsc.edu/library/img/web/misc/info-more.gif';
	   document.getElementById(imgId).title='Show info';
	   return;
  	}
	
	//set all other rows to default values
	subs_array = document.getElementsByTagName('div');
	for (i=0;i<subs_array.length;i++) {
		if (subs_array[i].className == name) {
			subs_array[i].style.display = "none";
			subIdNum = (subs_array[i].id.slice(7));
//alert(subIdNum);
			subRow = 'resultRow' + subIdNum;
			subImg = 'infoNote' + subIdNum;
			document.getElementById(subRow).className='TableRow';
	   		document.getElementById(subImg).src='http://bcd.tamhsc.edu/library/img/web/misc/info-more.gif';
			document.getElementById(subImg).title='Show info';
		}
	}

	document.getElementById(id).style.display = "";
	document.getElementById(rowId).className='TableRow-info';
    document.getElementById(imgId).src='http://bcd.tamhsc.edu/library/img/web/misc/info-less.gif';
	document.getElementById(imgId).title='Hide info';
	return;
}//showHide_DBs()



//************************************************************************************************
// showHideList
//   This function makes the elements with id="id" visible (display: ''), 
//      and all other divs with class="name" are hidden (display:'none')
//	It also changes the class name of the row with the "i" being clicked
//		and changes back to default (TableRow) for all others
//  Primarily used on Consumer Health & Subject Guide pages, and by SubjGd
//      menu on left of all pages.
//
//************************************************************************************************
function showHideList(id) {
		var imgId = id + 'Img';
	if (document.getElementById(id).style.display==""){				//is displayed, so hide it and change icon to +
		document.getElementById(id).style.display = "none";
		document.getElementById(imgId).src = "http://bcd.tamhsc.edu/library/img/web/misc/green-show.gif";
		document.getElementById(imgId).alt = "Show List";
		document.getElementById(imgId).title = "Show List";
	}
	else if (document.getElementById(id).style.display=="none"){	//is hidden, so dispaly it and change icon to -
		document.getElementById(id).style.display = "";
		document.getElementById(imgId).src = "http://bcd.tamhsc.edu/library/img/web/misc/green-hide.gif";
		document.getElementById(imgId).alt = "Hide List";
		document.getElementById(imgId).title = "Hide List";
	}
}

