//   8/23/08   Copyright (C) 2008. All rights reserved.


var	prevbrowserwidth,
	timeout = null;


/*
window.onload = function()
{
	window.onresize = resized;
	setupnavevents();
	currentpage();
	layout();

	postersetup();
}
*/


function gensetup()
{
	window.onresize = resized;
	setupnavevents();
	currentpage();
	layout();
}



function doresize()
{
	if (browserwidth() != prevbrowserwidth) {
		window.location.reload (false);
	}	
}



function ishgroup (div)
{
	return  getparam (div, 'g') == 'h';
}



function layout()
{
	var		browsewidth,
			left,
			topdiv,
			width;


	if (topdiv = document.getElementById ('top')) {
		browsewidth = browserwidth();

		left = topx (getstyleinfo (topdiv, 'left'), browsewidth);
		width = browsewidth - 2*left;

		topdiv.style.width = width + 'px';

		setwidths (topdiv);
		setheights (topdiv);
		setops (topdiv);
//traverse (topdiv);
	}

	prevbrowserwidth = browserwidth();
}



function resized()
{
	if (timeout != null) {
		clearTimeout (timeout);
	}

	timeout = setTimeout ("doresize()", 200);
}



function setheights (parent)
{
	var		curlevel,
			div,
			divlist,
			height,
			maxheight,
			numdivs,
			pos;
			


	curlevel = getsubdivs (parent);

	for (pos = 0; pos < curlevel.length; pos++) {
		div = curlevel[pos];
		height = setheights (div);

		if (height != null) {
			if (ishgroup (div)) {
				div.style.height = height + 'px';
			}
			else {
				height += topx (getstyleinfo (div, 'height'), 0);
				div.style.height = height + 'px';
			}
		}
	}

	if (curlevel.length > 0) {
		divlist = [];
		numdivs = maxheight = 0;

		for (pos = 0; pos < curlevel.length; pos++) {
			div = curlevel[pos];

			if (getparam (div, '=')) {
				divlist[numdivs++] = div;

				if (div.offsetHeight) {
					height = div.offsetHeight;
				}
				else if (div.style.pixelHeight) {
					height = div.style.pixelHeight;
				}
				else {
					height = 0;
				}

				if (height > maxheight) {
					maxheight = height;
				}
			}
		}

		if (numdivs > 0) {
			// assign maximum height value to all of container <div> elements
			for (pos = 0; pos < numdivs; pos++) {
				divlist[pos].style.height = maxheight + 'px';
			}
			height = maxheight;
		}
		else if (ishgroup (parent)) {
			div = curlevel[0];

			if (div.offsetHeight) {
				height = div.offsetHeight;
			}
			else if (div.style.pixelHeight) {
				height = div.style.pixelHeight;
			}
		}
		else {
			height = 0;
			for (pos = 0; pos < curlevel.length; pos++) {
				div = curlevel[pos];

				if (div.offsetHeight) {
					height += div.offsetHeight;
				}
				else if (div.style.pixelHeight) {
					height += div.style.pixelHeight;
				}
			}
		}
	}

	return  height;
}



function setline (line, totalwidth)
{
	var		divwidth,
			left,
			pixelsremain,
			pos,
			remainingdiv,
			widthinfo;



	widthinfo = false;

	for (pos = 0; pos < line.length; pos++) {
		div = line[pos];
		if (getparam (div, 'w')) {
			widthinfo = true;
		}
	}

	if (widthinfo) {
		pixelsremain = totalwidth;
		remainingdiv = null;

		for (pos = 0; pos < line.length; pos++) {
			div = line[pos];

			if (width = getparam (div, 'w')) {
				if (width == '+') {
					remainingdiv = div;
				}
				else {
					divwidth = topx (width, totalwidth);
					div.style.width = divwidth + 'px';
					pixelsremain -= divwidth;
				}
			}
			else {
				pixelsremain -= topx (getstyleinfo (div, 'width'), totalwidth);
			}				
		}

		if (remainingdiv != null) {
			remainingdiv.style.width = pixelsremain + 'px';
		}

		left = 0;
		for (pos = 0; pos < line.length; pos++) {
			div = line[pos];
			div.style.left = left + 'px';
			left += topx (getstyleinfo (div, 'width'), totalwidth);
		}
	}
	else {
		for (pos = 0; pos < line.length; pos++) {
			line[pos].style.width = totalwidth + 'px';
		}
	}
}


function setops (parent)
{
	var		curlevel,
			div,
			isvertical,
			pos,
			top;




	curlevel = getsubdivs (parent);
	if (curlevel.length > 0) {
		isvertical = !ishgroup (parent);

		top = ishgroup (parent)  ?  0 : topx (getstyleinfo (parent, 'top'), 0);
		for (pos = 0; pos < curlevel.length; pos++) {
			div = curlevel[pos];		
			div.style.top = top + 'px';

			if (isvertical) {
				top += topx (getstyleinfo (div, 'height'), 0);
			}
		}

		for (pos = 0; pos < curlevel.length; pos++) {
			setops (curlevel[pos]);
		}
	}
}



function setposition (div)
{
	div.style.position = 'absolute';
}



function setwidths (parent)
{
	var		curlevel,
			pos;


	curlevel = getsubdivs (parent);

setposition (parent)

	if (curlevel.length != 0) {

		setline (curlevel, topx (getstyleinfo (parent, 'width'), browserwidth()));

		for (pos = 0; pos < curlevel.length; pos++) {
			setwidths (curlevel[pos]);
		}
	}
}



function traverse (parent)
{
	var		curlevel,
			div,
			pos;


	curlevel = getsubdivs (parent);
	for (pos = 0; pos < curlevel.length; pos++) {
		div = curlevel[pos];
		alert (details (div));
	}

	for (pos = 0; pos < curlevel.length; pos++) {
		traverse (curlevel[pos]);
	}
}



//////////////////////////////////////////////////
//						//
// Functions for managing navigation buttons	//
//						//
//////////////////////////////////////////////////

function clearbox (evt)
{
	var		atag;


	atag = getarget (evt);
	if (atag.blur) atag.blur();
}



function currentpage()
{
	var		alist,
			atag,
			div,
			docfrag,
			found,
			group,
			pos;



	alist = document.getElementsByTagName ("A");

	found = false;
	for (pos = 0; !found  &&  pos < alist.length; pos++) {
		atag = alist[pos];

		if (atag.href == document.location) {
			found = true;
		}
	}


	if (found) {
		group = atag.parentNode.parentNode;

		div = document.createElement ("div");
		div.className = "currentlink";
		div.appendChild (document.createTextNode (atag.firstChild.data));
		docfrag = document.createDocumentFragment();
		docfrag.appendChild (div);

		group.parentNode.replaceChild (docfrag, group);
	}
}



//////////////////////////////////////////////////////////////////////////
//									//
// An event handler (e.g enterbutton) will receive an event object as	//
// its first parameter only if:						//
//									//
//	the event handler is assigned outside the HTML tag (not as an	//
//	attribute-value pair in the HTML tag)				//
//									//
// or,									//
//									//
// 	the event handler is assigned using an attribute-value pair in	//
//	the HTML tag, AND the keyword 'event' is explicitly passed to	//
//	the handler							//
//									//
//////////////////////////////////////////////////////////////////////////

function enterbutton (evt)
{
	movebackground (evt, "-80px");
}



function exitbutton (evt)
{
	movebackground (evt, "0px");
}



function getarget (evt)
{
	evt = evt  ||  window.event;

	return  evt.target  ||  evt.srcElement;
}



function movebackground (evt, offset)
{
	var		atag,
			divlist,
			group,
			pos;



	atag = getarget (evt);

	group = atag.parentNode.parentNode;
	divlist = getsubdivs (group);

	for (pos = 0; pos < divlist.length; pos++) {
		div = divlist[pos];

		if (div.id.indexOf ("buttons") >= 0) {
			div.style.backgroundPosition = "0px " + offset;
		}
	}
}



function setupnavevents()
{
	var		alist,
			atag,
			pos;



	alist = document.getElementsByTagName ("A");
	for (pos = 0; pos < alist.length; pos++) {
		atag = alist[pos];
		if (atag.parentNode.id == "navigation") {
			atag.onmouseover = enterbutton;
			atag.onmouseout = exitbutton;
			atag.onfocus = clearbox;
		}
	}
}