/* This script and many more are available free online at
The JavaScript Source :: http://javascript.internet.com
Original script by Corneliu Lucian Rusu | http://www.anet.ro/zen/
Portions modified by Lee Underwood | http://javascript.internet.com/ 

function showhide(s){
 while(s.nodeType!=1 && s.nodeName.toLowerCase()!='span'){s=s.nextSibling};
 s.className=(s.className=='show2')?'hide':'show2';
 return false;
}

// Borrowed from Jeremy Keith | http://www.domscripting.com/
window.onload=getReady;
function getReady() {
 var links = document.getElementsByTagName("a");
 for (var i=0; i<links.length; i++) {
   if (links[i].className == "show") {
     links[i].onclick = function() {
     return showhide(this.nextSibling);
    }
   }
 }
}
End of the showhide function from The JavaScript Source */




//Shows chosen layer... used by every page (except main)
//Uses a script.aculo.us effect
function showLayer(layer)
{
	Effect.SlideDown(layer)
}


//Hides all other layers on the page
function hideLayers(a,b,c,d,e,f,g,h,i,j)
{
	Effect.DropOut(a)
	Effect.DropOut(b)
	Effect.DropOut(c)
	Effect.DropOut(d)
	Effect.DropOut(e)
	Effect.DropOut(f)
	Effect.DropOut(g)
	Effect.DropOut(h)
	Effect.DropOut(i)
	Effect.DropOut(j)
}

// disable vertical scrolling if text doesn't overflow the div
/*function hideScroll()

if (document.getElementById(
if ($('scrollable1').scrollHeight <= $('scrollable1').offsetHeight) {
	slider1.setDisabled();
	$('track1').hide();
}*/
		



// Create an array of pages and arrays for the divs on each page
var BackgroundDivs = new Array();
BackgroundDivs[0] = "Intro";
BackgroundDivs[1] = "Religion";
BackgroundDivs[2] = "HistoryOfTrek";
BackgroundDivs[3] = "Roddenberry";
BackgroundDivs[4] = "HistoryOfTrekReligion";
BackgroundDivs[5] = "Voyager";

var CrewDivs = new Array();
CrewDivs[0] = "Intro";
CrewDivs[1] = "Janeway";
CrewDivs[2] = "Chakotay";
CrewDivs[3] = "Tuvok";
CrewDivs[4] = "Paris";
CrewDivs[5] = "Torres";
CrewDivs[6] = "Doctor";
CrewDivs[7] = "Kim";
CrewDivs[8] = "Neelix";
CrewDivs[9] = "Seven";
CrewDivs[10] = "Kes";

var DeltaDivs = new Array();
DeltaDivs[0] = "Intro";
DeltaDivs[1] = "Caretaker";
DeltaDivs[2] = "Vidiians";
DeltaDivs[3] = "FalseProfits";
DeltaDivs[4] = "Blink";
DeltaDivs[5] = "Klingons";

var ThemeDivs = new Array();
ThemeDivs[0] = "Intro";
ThemeDivs[1] = "Death";
ThemeDivs[2] = "Redemption";
ThemeDivs[3] = "ChildhoodFaith";
ThemeDivs[4] = "Encouragement";
ThemeDivs[5] = "TooFar";
ThemeDivs[6] = "Right";


/* Function progress through pages and divs on each page, in order. Begins with 
main and progresses through to the main conclusion page.*/
function nextSelection()
{
if (window.name=="Main")
{	
	document.location.href="Background.html"
}
else if (window.name=="Background")
	{
		for (j=0;j<BackgroundDivs.length;j++)
		{
			if(document.getElementById(BackgroundDivs[j]).style.display!="none")
			{
				Effect.DropOut(BackgroundDivs[j])
				if(j==5)
				{
				document.location.href="Crew.html"
				}
					else
					{
					Effect.SlideDown(BackgroundDivs[j+1])
					}
			}//end of backgroundDivs
		}//for
	}// end of else if
else if (window.name=="Crew")
	{
		for(k=0;k<CrewDivs.length;k++)
		{
			if(document.getElementById(CrewDivs[k]).style.display!="none")
			{
				Effect.DropOut(CrewDivs[k])
				if(k==10)
				{
				document.location.href="OutsideFederation.html"
				}
					else
					{
					Effect.SlideDown(CrewDivs[k+1])
					}//end of else
				}//end of crew if/then
			}//end of "Crew" for loop
		}//end of else if ("Crew")
else if (window.name=="OutsideFederation")
	{
		for(l=0;l<DeltaDivs.length;l++)
		{
			if(document.getElementById(DeltaDivs[l]).style.display!="none")
			{
				Effect.DropOut(DeltaDivs[l])
				if(l==5)
				{
				document.location.href="Themes.html"
				}
					else
					{
					Effect.SlideDown(DeltaDivs[l+1])
					}//end of else
				}//end of Delta if/then
			}//end of "Delta" for loop
		}//end of else if ("Delta")	
else if (window.name=="Themes")
	{
		for(m=0;m<ThemeDivs.length;m++)
		{
			if(document.getElementById(ThemeDivs[m]).style.display!="none")
			{
				Effect.DropOut(ThemeDivs[m])
				if(m==6)
				{
				document.location.href="Conclusion.html"
				}
					else
					{
					Effect.SlideDown(ThemeDivs[m+1])
					}//end of else
				}//end of Theme if/then
			}//end of "Theme" for loop
		}//end of else if ("Theme")	
}//end of function

/* Function progress through pages and divs on each page, in order backwards. Begins with conclusion 
and progresses through to the main page.*/
function previousSelection()
{
if (window.name=="Conclusion")
{	
	document.location.href="Themes.html?end"
}
else if (window.name=="Themes")
	{
		for(m=6;m>=0;m--)
		{
			if(document.getElementById(ThemeDivs[m]).style.display!="none")
			{
				Effect.DropOut(ThemeDivs[m])
				if(m==0)
				{
				document.location.href="OutsideFederation.html?end"
				}
					else
					{
					Effect.SlideDown(ThemeDivs[m-1])
					}//end of else
				}//end of Theme if/then
			}//end of "Theme" for loop
		}//end of else if ("Theme")	
else if (window.name=="OutsideFederation")
	{
		for(l=10;l>=0;l--)
		{
			if(document.getElementById(DeltaDivs[l]).style.display!="none")
			{
				Effect.DropOut(DeltaDivs[l])
				if(l==0)
				{
				document.location.href="Crew.html?end"
				}
					else
					{
					Effect.SlideDown(DeltaDivs[l-1])
					}//end of else
				}//end of Delta if/then
			}//end of "Delta" for loop
		}//end of else if ("Delta")
else if (window.name=="Crew")
	{
		for(k=10;k>=0;k--)
		{
			if(document.getElementById(CrewDivs[k]).style.display!="none")
			{
				Effect.DropOut(CrewDivs[k])
				if(k==0)
				{
				document.location.href="Background.html?end"
				}
					else
					{
					Effect.SlideDown(CrewDivs[k-1])
					}//end of else
				}//end of crew if/then
			}//end of "Crew" for loop
		}//end of else if ("Crew")	
else if (window.name>="Background")
	{
		for (j=5;j>=0;j--)
		{
			if(document.getElementById(BackgroundDivs[j]).style.display!="none")
			{
				Effect.DropOut(BackgroundDivs[j])
				if(j==0)
				{
				document.location.href="Main.html"
				}
					else
					{
					Effect.SlideDown(BackgroundDivs[j-1])
					}
			}//end of backgroundDivs
		}//for
	}// end of else if
}//end of function


/* this routine creates momentary pop-ups that display mini-explanations
of words or serves as footnotes*/

var i="popUp";

//creates a new div at a location slightly above and to the right of the word in question
function popUp(span,message)
{

	newMessage = document.createElement('div');
	newMessage.innerHTML="<font size='-1'>" + message + "</font>";
	newMessage.setAttribute('id',span.id+i);
	newId=span.id+i
	
	
	nextNode = document.getElementById(span.id).parentNode;
	document.body.appendChild(newMessage);
//find position of the span the new div connects to.
	x=findPositionX(span);
	y=findPositionY(span);
	

	
	document.getElementById(newId).style.position="absolute";
	document.getElementById(newId).style.zIndex=1;
	document.getElementById(newId).style.top=y-25;
	document.getElementById(newId).style.left=x+25;
	document.getElementById(newId).style.backgroundColor="white";
	document.getElementById(newId).style.color="black";
	document.getElementById(newId).style.padding="5";
	document.getElementById(newId).style.border="medium solid blue";	
}

function findPositionX(obj) 
{
  var curleft = 0;
  if (obj.offsetParent) 
  {
    while (obj.offsetParent) 
        {
            curleft += obj.offsetLeft
            obj = obj.offsetParent;
        }
    }
    else if (obj.x)
        curleft += obj.x;
    return curleft;
}

function findPositionY(obj) 
{
    var curtop = 0;
    if (obj.offsetParent) 
    {
        while (obj.offsetParent) 
        {
            curtop += obj.offsetTop
            obj = obj.offsetParent;
        }
    }
    else if (obj.y)
        curtop += obj.y;
    return curtop;
}

//removes the newly created div
function removeDiv(span)
{
	message=span.id+i
	div=document.getElementById(message)
	document.body.removeChild(div)
}



