/* SI_menu() v1.2
 * 
 * Holds IEs hand through what can be accomplished using only
 * CSS in other modern browsers. That's right, I said "modern."
 * In a medium that moves as fast the internet you didn't really
 * consider a 4 year old browser like IE modern did you? :P
 */

function SI_menu() {
	var d = document;
	var isSafari 	= (navigator.userAgent.indexOf('Safari') != -1);
	var isIE 		= (navigator.appName == "Microsoft Internet Explorer");
	var isWinIE		= (isIE && window.print);
	
	SI_positionFooter();
	window.onresize = SI_positionFooter;
	
	/* Safari doesn't need any help...
	 * Gecko needs a little help remembering which parent elements are currently :hover
	 * I have no idea what to do with Opera...
	 * IE needs the most help...
	 */
	if (!d.getElementsByTagName || window.opera || isSafari) return;
	
	var m=SI_menu.arguments;

	for(i=0; i<m.length; i++) {
		for (var l=0; (lnk=d.getElementById(m[i]).getElementsByTagName("a")[l]); l++) {
			// If there are any nested menus...
			if (lnk.parentNode.childNodes.length > 1) {
				li = lnk.parentNode; // The containing <li>
				foundlink = false;
				for (var n=0; n < li.childNodes.length; n++) {
					node = li.childNodes[n];
					// Looks like this is our link...
					if (node.nodeType==1 && !foundlink) {
						li.link = node;
						foundlink = true;
						}
					// That should make this our submenu
					else if (node.nodeType==1 && foundlink) {
						li.ul = node; // The sibling <ul> (submenu)
						delete node;
						
						// li.ul.style.display	= 'none';	// Hide the submenu...
						li.isIE				= isIE;
						li.isWinIE			= isWinIE;
						li.onmouseover		= SI_showMenu
						li.onmouseout		= SI_hideMenu
						// li.onclick			= SI_debug
						foundlink = false;
						}
					}
				}
			}
		}
	}
function SI_showMenu() {
	this.link.className += (this.link.className=='')?'hover':' hover'; // leading space freaks out IE 5 Mac...go figure.
	if (this.isIE) {
		this.ul.style.display = 'block';
		this.style.zIndex = 100;
		if (this.isWinIE) SI_toggleSelects('hidden'); 
		}
	}
function SI_hideMenu() {
	this.link.className = this.link.className.replace(/(\s*)hover/g, '');
	if (this.isIE) {
		this.ul.style.display = 'none';
		this.style.zIndex = 1;
		if (this.isWinIE) SI_toggleSelects('visible'); 
		}
	}
function SI_toggleSelects(state) {
	var d = document;
	for (var i=0; (sel=d.getElementsByTagName('select')[i]); i++) {
		sel.style.visibility = state;
		}
	}
function SI_debug() { alert(this.link.className) }

function SI_positionFooter() {
	var d = document,w=window,dE=d.documentElement,dB=d.body;;
	if (!d.getElementById || !d.body.offsetHeight) return;
	if (!d.getElementById('footer')) return;
	
	// Reset our footer's margin-top...
	var footer = d.getElementById('footer');
	var mt = (footer.style.marginTop)?parseInt(footer.style.marginTop):0;
	
	var windowH		= (typeof(w.innerHeight)=='number')?w.innerHeight:(dE&&dE.clientHeight)?dE.clientHeight:(dB&&dB.clientHeight)?dB.clientHeight:0;
	var contentH	= d.getElementById('container').offsetHeight - mt;
	
	var footerMT	= (contentH <= windowH)?windowH-contentH:0;
	
	if (footerMT>0) {
		footer.style.marginTop = footerMT + 'px';
		}
	}
