// Expanding Layed Interface by
// Pat Friedl of Nebulus Deigns
// pfriedl@nebulus.org
// http://www.nebulus.org
//
// This script is (C) 1999 and may not be used
// in whole or in part without the express
// permission of the author

// browser/version detect

var NS = (navigator.appName == "Netscape") ? true : false;
var goodVer = (navigator.appVersion.charAt(0) == "4") ? true : false;

// redirect the browser if it sucks

if(!goodVer){
	announce = 'Your browser is not displaying javascript correctly!';
	announce = announce + '\nWe\'ll be changing the page to a simpler';
	announce = announce + '\n navigation interface, Click OK.';
	alert(announce);
	window.location = "ind_navig_simple.html";
}

// layer referencing
// sets the proper document reference
// for browser type

function setLayer(layerName){
	if(NS){
		var layerRef = eval("document." + layerName);
	} else {
		var layerRef = eval("document.all." + layerName + ".style");
	}
	return layerRef;
}

// toggle layer visibility
// if it's hidden, it goes visible,
// if it's visible, it goes hidden.

function setLayerVis(layerName){
	layerName = setLayer(layerName);
	if(layerName.visibility.charAt(0) == "h"){
		layerName.visibility = "visible";
	} else {
		layerName.visibility = "hidden";
	}
}


// get left corner X of a layer

function getLayerX(layerName){
	layerName = setLayer(layerName);
	if(NS){
		return layerName.left;
	} else {
		return layerName.pixelLeft;
	}
}

// get layer clip width

function getLayerWidth(layerName){
	layerName = setLayer(layerName);
	if(NS){
		var layerWidth = layerName.clip.width;
	} else {
		var widthVar = layerName.width;
		widthVar = Number(widthVar.slice(0,-2));
		var layerWidth = widthVar;
	}
	return layerWidth;
}

// set clip width of a layer

function setLayerClipWidth(layerName, w){
	layerName = setLayer(layerName);
	if(NS){
		layerName.clip.width = w;
	} else {
		layerName.width = w;
	}
}

// get left corner Y of a layer

function getLayerY(layerName){
	layerName = setLayer(layerName);
	if(NS){
		return layerName.top;
	} else {
		return layerName.pixelTop;
	}
}


// get layer clip height

function getLayerHeight(layerName){
	layerName = setLayer(layerName);
	if(NS){
		var layerHeight = layerName.clip.height;
	} else {
		var heightVar = layerName.height;
		heightVar = Number(heightVar.slice(0,-2));
		var layerHeight = heightVar;
	}
	return layerHeight;
}

// set clip height of a layer

function setLayerClipHeight(layerName, h){
	layerName = setLayer(layerName);
	if(NS){
		layerName.clip.height = h;
	} else {
		layerName.clipHeight = h;
	}
}

// move layers to a particular position

function moveLayer(layerName, x, y){
	layerName = setLayer(layerName);
	if(NS){
		layerName.moveTo(x,y);
	} else {
		layerName.pixelLeft = x;
		layerName.pixelTop = y;
	}	
}

// move layer by some increment

function moveLayerBy(layerName, deltaX, deltaY){
	layerName = setLayer(layerName);
	if(NS){
		layerName.moveBy(deltaX,deltaY);
	} else {
		layerName.pixelLeft += deltaX;
		layerName.pixelTop += deltaY;
	}	
}


// expansion function for layered interface.

function expando(layerArray,layerIndex,vertical,downORright){	
	
	ExpandingLayer = layerArray[layerIndex];
	
	// set visibility of the expanding/collapsing layer
	setLayerVis(ExpandingLayer);
	
	// get the values we need for shifting layers
	var tmpLayer = setLayer(ExpandingLayer);
	if(tmpLayer.visibility.charAt(0) == "h"){
		if(vertical){
			Y = - getLayerHeight(ExpandingLayer);
			X = 0;
		} else {
			X = - getLayerWidth(ExpandingLayer);
			Y = 0;
		}
	} else {
		if(vertical){
			Y = getLayerHeight(ExpandingLayer);
			X = 0;
		} else {
			X = getLayerWidth(ExpandingLayer);
			Y = 0;
		}
	}
	if(!downORright){
		Y = - Y;
		X = - X;
	}
	
	// move all subordinate layers
	for(i = layerIndex + 1; i < layerArray.length; i++){		
		// move the layer by the height of the expanding/collapsing layer
		moveLayerBy(layerArray[i],X,Y);
	}
}