/***************************************************************/
//* adjustLayout.js created for Faith and Evolution release 1.0*/
//Created by Mike Cleek 3.24.2009    (mr.cleek@gmail.com )     */
//**************************************************************/

/* INDEX of functions in this script:

1) function adjustLayout() The main function that determines if there is a rightBar
2) function rightBar(rightBarDocObj) calls index if it's an index page otherwise does layout for page
3) function noRightBar() calls twoColumns if it's a two column page otherwise does layout for page
4) function indexLayout(mainTextindexDocObj, rightBarDocObj) adjusts layout of index page
5) function twoColumns(lColumnDocObj) adjusts layout for a two column page
*/


/****************************************************************************/
/*Maintains correct height for three different divs and dynamic text layouts*/
/*Also adjust the CSC Logo to keep it at the bottom of the left navigation  */
/****************************************************************************/
/*
Update:
By:

*/
/***************************************************************************/
/*Document any changes in the area above. Be sure to list date of change and
who made the changes, and be sure to comment your changes below as well
****************************************************************************/

/////////////////////////////////////////////////////////////////////////////
/*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*/
/////////////////////////////////////////////////////////////////////////////

function adjustLayout()
{	
	//alert('entered');
	//determine if there is a rightBar so that we can adjust complete page
	var rightBarDocObj = document.getElementById('rightBar');
	if(rightBarDocObj != null) //there is a rightBar
	{  
		rightBar(rightBarDocObj);
	}
	
	else   //there is no rightBar
	{
		noRightBar();		
	}
}

/////////////////////////////////////////////////////////////////////////////
/*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*/
/////////////////////////////////////////////////////////////////////////////

function rightBar(rightBarDocObj)
{
	var mainTextindexDocObj = document.getElementById('mainText-index');
	if(mainTextindexDocObj != null) //if this is the index page
	{
		indexLayout(mainTextindexDocObj, rightBarDocObj);
	}
	else //this is not the index page.
	{
		//Get all the elements (div id's) we are going to work with
		var rbHeight = rightBarDocObj.offsetHeight  //get height of the rightbar.
		//alert(rbHeight);
		
		var accordion1DocObj = document.getElementById('Accordion1');
		var rSideDocObj = document.getElementById('rSide');
		var lSideDocObj = document.getElementById('lSide');
		var cscLogoDocObj = document.getElementById('cscLogo');
	
		var mainTextShortDocObj = document.getElementById('mainTextShort');
		var top = mainTextShortDocObj.offsetTop;   //Find the height of the greenInside class
		var height = mainTextShortDocObj.offsetHeight;
		
		if(rbHeight > top + height) //if the rightside bar is the longest thing on the page
		{	
			//Make mainTextShort relative to the greenInside.
			//also compensate for padding, borders etc. with 56px
			mainTextShortDocObj.style.height = rbHeight - top - 56 + 'px'; 
			
			//make sure the left nav/Accordion1 is the same height as the rightBar
			accordion1DocObj.style.height = rbHeight - 2 + 'px';
			cscLogoDocObj.style.top = rbHeight - 133 + 'px'; //place the CSC Logo at the bottom of the left nav
			rSideDocObj.style.height = rbHeight + 162 + 'px';
			lSideDocObj.style.height = rbHeight + 162 + 'px';
		}
		
		//enter this else: if (rbHeight <= top + height) and there is enough content in the center of the page 
		//and it pushes the main text  beyond the rightBar
		else 
		{
			//set the two side bars to the main height
			accordion1DocObj.style.height = top + height + 2 + 'px';
			rightBarDocObj.style.height = top + height + 1 + 'px';
			//and the fancy edges Plus 166px for the header image
			rSideDocObj.style.height = top + height + 166 + 'px';
			lSideDocObj.style.height = top + height + 166 + 'px';	
			cscLogoDocObj.style.top = top + height - 120 + 'px';	//place the CSC Logo at the bottom of the left nav			
		}
	}
}

/////////////////////////////////////////////////////////////////////////////
/*3*3*3*3*3*3*3*3*3*3*3*3*3*3*3*3*3*3*3*3*3*3*3*3*3*3*3*3*3*3*3*3*3*3*3*3*3*/
/////////////////////////////////////////////////////////////////////////////

function noRightBar()
{
	var lColumnDocObj = document.getElementById('lColumn');
	if(lColumnDocObj != null)
	{
		twoColumns(lColumnDocObj);				
	}
	
	else //if there is no rightBar and there is no lColumn
	{  
		//Get all the elements (div id's) we are going to work with
		var accordion1DocObj = document.getElementById('Accordion1');
		aHeight = accordion1DocObj.offsetHeight;
		
		var rSideDocObj = document.getElementById('rSide');
		var lSideDocObj = document.getElementById('lSide');
		var mainTextDocObj = document.getElementById('mainText');
		var cscLogoDocObj = document.getElementById('cscLogo');
		var top = mainTextDocObj.offsetTop;   //Find the height of the greenInside class
		var height = mainTextDocObj.offsetHeight;  //Find the height of the mainText area
		
		if(aHeight > top + height)
		{	
			//if it is from the article databse it won't have a greenInside div.
			//Therefore mainText needs to be adjusted.
			var greenDocObj = document.getElementById('greenInside');
			if(greenDocObj == null)
			{
				mainTextDocObj.style.height = aHeight - top - 52 + 'px';
				cscLogoDocObj.style.top = aHeight - 133 + 'px';
			}
			else
			{
			//Make mainText dynamic to the greenInside.
			mainTextDocObj.style.height = aHeight - top - 56 + 'px'; 
			cscLogoDocObj.style.top = aHeight - 133 + 'px'; //place the CSC Logo at the bottom of the left nav
			}
		}
		else //if(aHeight <= top + height)
		{	
			//if it is from the article database it won't have a greenInside div.
			//Therefore accordion1 needs to be adjusted to fit new size.
			var greenDocObj = document.getElementById('greenInside');
			if(greenDocObj == null)
			{
				accordion1DocObj.style.height = top + height - 2 + 'px'
				cscLogoDocObj.style.top = top + height - 150 + 'px';
				rSideDocObj.style.height = top + height + 162 + 'px';
				lSideDocObj.style.height = top + height + 162 + 'px';
			}
			else
			{
			//set the left nav/Accordion1 to the size of the mainText
			accordion1DocObj.style.height = top + height + 2 + 'px';
			//and the fancy edges Plus 166px for the header image
			rSideDocObj.style.height = top + height + 166 + 'px';
			lSideDocObj.style.height = top + height + 166 + 'px';
			cscLogoDocObj.style.top = top + height - 150 + 'px';	//place the CSC Logo at the bottom of the left nav
			}
			
		}
	}
}

/////////////////////////////////////////////////////////////////////////////
/*4*4*4*4*4*4*4*4*4*4*4*4*4*4*4*4*4*4*4*4*4*4*4*4*4*4*4*4*4*4*4*4*4*4*4*4*4*/
/////////////////////////////////////////////////////////////////////////////

function indexLayout(mainTextindexDocObj, rightBarDocObj) //layout for indexes
{

	//Get all the elements (div id's) we are going to work with
	var rbHeight = rightBarDocObj.offsetHeight  //get height of the rightbar.
	
	var accordion1DocObj = document.getElementById('Accordion1');
	var rSideDocObj = document.getElementById('rSide');
	var lSideDocObj = document.getElementById('lSide');
	var cscLogoDocObj = document.getElementById('cscLogo');

	var mainTextIndexDocObj = document.getElementById('mainText-index');
	var top = mainTextIndexDocObj.offsetTop;   //Find the height of the greenInside class
	var top2 = mainTextIndexDocObj.offsetParent.offsetTop; //Find the position of greenInside from the Header
	var height = mainTextIndexDocObj.offsetHeight;
	top = top + top2;
	//alert('top2 ' + top2);
	
	if(rbHeight > top + height) //if the rightside bar is the longest thing on the page
	{
		//Make mainTextShort relative to the greenInside.
		//also compensate for padding, borders etc. with 56px
		mainTextIndexDocObj.style.height = rbHeight - top - 56 + 'px'; 
		
		//make sure the left nav/Accordion1 is the same height as the rightBar
		accordion1DocObj.style.height = rbHeight - 2 + 'px';
		cscLogoDocObj.style.top = rbHeight - 220 + 'px'; //also check imageLayout function if home.php
		//cscLogoDocObj is redundant, adjusted further in imageLayout() below depending on pageload.
		rSideDocObj.style.height = rbHeight + 162 + 'px';
		lSideDocObj.style.height = rbHeight + 162 + 'px';
	}
	
	//enter this else: if (rbHeight <= top + height) there is enough content in the center of the page 
	//and it pushes the main text beyond the rightBar
	else 
	{ 
		//set the two side bars to the main height
		accordion1DocObj.style.height = top + height + 'px';
		rightBarDocObj.style.height = top + height - 1 + 'px';
		//alert('height ' + height);
		//and the fancy edges Plus 164px for the header image
		rSideDocObj.style.height = top + height + 164 + 'px';
		lSideDocObj.style.height = top + height + 164 + 'px';
		cscLogoDocObj.style.top =  top + height - 154 + 'px';	//place the CSC Logo at the bottom of the left nav
		//cscLogoDocObj is redundant, adjusted further in imageLayout() below depending on pageload.
		//alert('from top ' + cscLogoDocObj.style.top);
		//alert('top ' + top);
		//alert('height ' + height);
	}
	var imageDocObj = document.getElementById('image');
	if(imageDocObj != null)
	{ 
		imageLayout(imageDocObj, cscLogoDocObj, top, height, rbHeight);
	}
}
function imageLayout(imageDocObj, cscLogoDocObj, top, height, rbHeight)
{
	//this function is to adjust layout for the logo on the home.php page
	if(rbHeight < top + height)
	{
		cscLogoDocObj.style.top = top + height - 344 + 'px';
	}
	else
	{
		cscLogoDocObj.style.top = rbHeight - 450 + 'px';
	}
}

/////////////////////////////////////////////////////////////////////////////
/*5*5*5*5*5*5*5*5*5*5*5*5*5*5*5*5*5*5*5*5*5*5*5*5*5*5*5*5*5*5*5*5*5*5*5*5*5*/
/////////////////////////////////////////////////////////////////////////////

function twoColumns(lColumnDocObj)
{
	//Get all the elements (div id's) we are going to work with
	var accordion1DocObj = document.getElementById('Accordion1');
	aHeight = accordion1DocObj.offsetHeight;
	
	var rSideDocObj = document.getElementById('rSide');
	var lSideDocObj = document.getElementById('lSide');
	var lColumnDocObj = document.getElementById('lColumn');
	var rColumnDocObj = document.getElementById('rColumn');
	var cscLogoDocObj = document.getElementById('cscLogo');
	var top = lColumnDocObj.offsetTop;   //Find the height of the greenInside class
	var height = lColumnDocObj.offsetHeight;  //Find the height of the mainText area
	

	//set the left nav/Accordion1 to the size of the mainText
	accordion1DocObj.style.height = top + height + 2 + 'px';
	//make sure rColumn is same as lColumn
	rColumnDocObj.style.height = height - 2 + 'px';
	//and the fancy edges Plus 166px for the header image
	rSideDocObj.style.height = top + height + 166 + 'px';
	lSideDocObj.style.height = top + height + 166 + 'px';
	cscLogoDocObj.style.top = top + height - 130 + 'px';	//place the CSC Logo at the bottom of the left nav	
}