var onloadEvents = new Array();

function addToOnload(event){
	onloadEvents.push(event);
	window.onload = function() { 
		for (var x = 0; x < onloadEvents.length; x ++) {
			eval(onloadEvents[x]);
		}
	}
}

var containerHeight = 0;
sfHover = function() {
	var sfEls = document.getElementById("navigation").getElementsByTagName("LI");
	var container = document.getElementById("container");
	containerHeight = container.offsetHeight;
	for (var i=0; i<sfEls.length; i++) {

		var className = this.className;
		if(className == 'first' || className == 'last' || className == '') continue;
	
		sfEls[i].onmouseover=function() {
			this.className+=" hover";
			document.getElementById("container").style.height = containerHeight + 'px';
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" hover\\b"), "");
			document.getElementById("container").style.height = containerHeight + 'px';
		}
	}
}

// only attach for ie
if (window.attachEvent) window.attachEvent("onload", sfHover);
//addToOnload('pageControl.init()');
//addToOnload('searchBar.init()');
//addToOnload('textControl.init()');
//addToOnload('tableControl.init()');

var textControl = {
	currentSize: 1.00,
	emModifier: .10,
	init: function() {
		this._attachEvents();
		//for(var i = 0; i < 10; i++)
			//this.increaseText();
	},
	printPage: function() {
		window.print();
	},
	increaseText: function() {
		if(this.currentSize < 1.5) {
			this.currentSize += this.emModifier;
			this._changeTextSizeEM(this.currentSize);
		}
	},
	decreaseText: function() {
		if(this.currentSize > 1) {
			this.currentSize -= this.emModifier;
			this._changeTextSizeEM(this.currentSize);
		}
	},
	_changeTextSizeEM: function(emSize) {
		var area = $$('#column-left-content');
		var area2 = $$('#column-full');
		// make sure the content area exists
		if(area != null && area != '') {
			area.setStyle('font-size', emSize+'em').setStyle('line-height', '1em');
		} else if(area2 != null) {
			area2.setStyle('font-size', emSize+'em').setStyle('line-height', '1em');
			var labels = $$('#column-full li>label');
			for(var i = 0; i < labels.length; i++) {
				if(emSize == 1) {
					labels[i].setStyle('line-height', '16px');
				} else {
					labels[i].setStyle('line-height', '1em');
				}
				var h = parseInt(labels[i].getHeight());
				if(h == 0) {
					// (lines) * (16px * emSize)
					h = parseInt((labels[i].get('text').length / 14) * (16 * (emSize + .1)));
				}
				labels[i].getParent().setStyle('min-height', (h)+'px');
			}
		}
	},
	_attachEvents: function() {
		$$('#contentControl>button.print').addEvent('click', function() {
			textControl.printPage();
		});
		$$('#contentControl>button.decrease').addEvent('click', function() {
			textControl.decreaseText();
		});
		$$('#contentControl>button.increase').addEvent('click', function() {
			textControl.increaseText();
		});
	}
}

function processKeyPress(e){
	var e = window.event  || e;
	
	try {
		var key = e.keyCode || e.which;
	} catch (e){
		var key = 0;
	}
	//Esc or x (lowercase)
	if (key == 27 || key == 120) closePopup();
	
}

function closePopup() {
	e = document.getElementById('map-display');
	if (e){
		e.parentNode.removeChild(e);
	} 
}

function popupKeyListener() {document.onkeypress = processKeyPress; }

function getWindowDimensions(){
	
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	return [myWidth, myHeight];
}