// JavaScript Document

//Collapsible Menu System
var lastExpanded = '';   //Last navigation div to expand
var navOffset = 150;     //Offset for navigation height expansion
var baseHeight = 0;      //Base height of page after loading
var bExpanded = 0;       //Should the page expand?
var bPageHasLoaded = 0;  //Has the page loaded?

function showHide(id)    //Expand & Contract the navigation list by showing and hiding the expanded divs...
{
	var menuDiv = document.getElementById(id); //Get instance of div to be altered...
	var status = menuDiv.className;            //Hidden?

	if (status == 'hide')                      //Hidden?
	{
		if (lastExpanded != '')                //Have we done this before?
		{
			var lastMenuDiv = document.getElementById(lastExpanded); //Get instance of the last div to expand...
		
			lastMenuDiv.className = 'hide';    //Hide the last div to expand...
		}
		menuDiv.className = 'show';            //Set the new div to expand...
		lastExpanded = id;                     //blah blah...
		bExpanded = 1;                         //Something is expanded...
	}
	else                                       //Div is expanded, let's contract it...
	{
		menuDiv.className = 'hide';            //Hidden blah blah...
		bExpanded = 0;                         //Nothing is expanded...
	}
	setHeights();                              //Adjust the height of the page, we may be overflowing right now...
}

//Adjust Page Heights - Damn Divs
function setHeights()
{
	var wrapperDiv = document.getElementById("wrapper");              //Instance of the wrapper div
	var leftDiv = document.getElementById("left");                    //Instance of the left div
	var navigationDiv = document.getElementById("navigation");        //Instance of the navigation div
	var contentDiv = document.getElementById("content");              //Instance of the content div
	var rightDiv = document.getElementById("right");                  //Instance of the right div
	var manufacturersDiv = document.getElementById("manufacturers");  //Instance of the manufacturers div
	var topDiv = document.getElementById("top");                      //Instance of the top div
	var bottomDiv = document.getElementById("bottom");                //Instance of the bottom div
	var bannerDiv = document.getElementById("banner");                //Instance of the banner div
	
	//Calculate new height based on wrapper height minus header/footer height
	var newHeight = wrapperDiv.offsetHeight - (topDiv.offsetHeight + bannerDiv.offsetHeight + bottomDiv.offsetHeight);
	
	if (bPageHasLoaded)  //Page has loaded...
	{
		if (bExpanded && newHeight == baseHeight)       //Is the navigation expanded?
			newHeight += navOffset;
		else if (!bExpanded && newHeight != baseHeight) //Set page length back to original...
			newHeight -= navOffset;
	}
	else
	{
		baseHeight = newHeight; //Page just loaded, set initial height of page in variable...
	}
	
	if (newHeight != '') //Is there a new height?
	{
		leftDiv.style.height = (newHeight) + "px";           //Set heights to maximum div height for equal columns...
		navigationDiv.style.height = (newHeight) + "px";
		contentDiv.style.height = (newHeight) + "px";
		rightDiv.style.height = (newHeight) + "px";
		manufacturersDiv.style.height = (newHeight) + "px";
	}
	bPageHasLoaded = 1; //Initial page height has been set...
}