//	Script to handle hiding/showing div's on SteeleSoft home page

//	Set browser specific variables for different browsers
var ie4=document.all;var net4=document.layers;var dom=false;if(document.getElementById)dom=true;

//	Object to hold references to page layers
var pageLayers=null;
//	Object to hold references to page scroller layers
var pageScrollers=null;

//	navSet.opening is set to the currently opening page, can only open one 
//	page at a time, navSet.closing is a collection of pages that are closing,
//	can close more than one page at a time

//	Settings object stores settings necessary for handling of page layers 
var navSet={init:false,loading:false,opening:null,closing:{},homePageName:"Home",pagePrefix:"page_",scrollPrefix:"scroll_",waitingToOpen:null,layers:null,curPage:null,openLeft:null,closedLeft:-427,layerTop:null};

//	Used so script can tell what type of page we're on
var ToggleEle = false;

//	Called to initialize page layer objects on page load
function initPageLayers(){
	getPageLayers();
	
	//	Set left and top positions by getting them from 
	//	the current layer position of first layer
	for(page in pageLayers) {
		navSet.layerTop = getTop(pageLayers[page]);
		break;
		}
	navSet.init=true;
	navSet.moving=false;
};

//	Called to show a page, calls animate function to show page, 
//	and calls done showing page after complete to reset moving flag
//	if there is a page already visible, call function to hide it.
function showPage(page){
	if(!pageLayers[page])return;
	//	If this page is open, close it
	else if(page == navSet.curPage){
		hidePage(navSet.curPage);
		return;
		}
	//	If opening this page already, ignore
	if(navSet.opening == page)return;
	//	If another page is open, close it and
	//	continue to open this page
	if(navSet.curPage)hidePage(navSet.curPage);
	//	If opening another page, stop 
	//	and close the other page
	if(navSet.opening != null)hidePage(navSet.opening);
	//	If already closing this page, remove flag 
	//	and let it open
	if(navSet.closing[page]==true)navSet.closing[page]=null;
	
	//	Make sure there is a page layer for this page
	
	animateLayerInALine(pageLayers[page], [navSet.openLeft,navSet.layerTop], .25, finishShowingPage);
	navSet.opening = page;
};

function finishShowingPage(){
	navSet.curPage = navSet.opening;
	navSet.opening = null;
	//	Show scroll bar if one exists for this page
	if(pageScrollers[navSet.curPage]){
		pageScrollers[navSet.curPage].style.overflow="auto";
		pageScrollers[navSet.curPage].style.overflowX="hidden";
		}
};

//	Called to hide a page, if no page specified, 
//	it hides the current page.
function hidePage(page){
	if(!page){
		if(navSet.curPage != null) page=navSet.curPage;
		else if(navSet.opening != null) page=navSet.opening;
		}
	if(navSet.opening == page) navSet.opening = null;
	
	//	Hide scroll bar before closing
	if(pageScrollers[page])pageScrollers[page].style.overflow="hidden";
	
	//	If already closing this page, skip
	if(navSet.closing[page]==true)return;
	
	animateLayerInALine(pageLayers[page], [navSet.closedLeft,navSet.layerTop], .25, null, finishHidingPage);
	navSet.closing[page]=true;
	if(navSet.curPage == page)navSet.curPage=null;
};
function finishHidingPage(aniId){
	if(!aniId)return;
	//	Convert div id used by animation script to page 
	//	name used by this script, then cancel closing
	//	flag for that page
	var page=aniId.substring(navSet.pagePrefix.length);
	navSet.closing[page]=null;
};


//	Function to find all div's whose id's start with "page_", 
//	save references to them so they can be opened and closed 
function getPageLayers(){
	var name;

	var divs = document.getElementsByTagName("div");
		
	pageLayers = new Object();
	pageScrollers = new Object();
	
	for(var i=0; i < divs.length; i++){
		div = divs[i];
		if(div.id && (div.id.indexOf(navSet.pagePrefix)==0)){
			//	Have div that starts with page prefix, add a 
			//	reference to it to the page collection object,
			//	name the reference by cutting off the prefix
			name = div.id.substring(navSet.pagePrefix.length);
			pageLayers[name] = div;
			if(navSet.openLeft == null)navSet.openLeft = getLeft(pageLayers[name]);
			if(name != navSet.homePageName) setLeft(pageLayers[name],navSet.closedLeft);
			showLayer(pageLayers[name]);
			}
		else if(div.id && (div.id.indexOf(navSet.scrollPrefix)==0)){
			//	Have div that starts with scroller prefix, add a 
			//	reference to it to the scroller collection object,
			//	name the reference by cutting off the prefix
			name = div.id.substring(navSet.scrollPrefix.length);
			pageScrollers[name] = div;
			}
		}
};


//	Dummy function to create dummy href's
function doAction(){;};

