/**
 * @author nbalsaras
 */
if (document.addEventListener) {
	document.addEventListener("DOMContentLoaded", init, false);
}
else if (checkIE < 7) {
	document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
	var script = document.getElementById("__ie_onload");
	script.onreadystatechange = function(){
		if (this.readyState == "complete") {
			init(); // call the onload handler
		}
	};
}
else {
	window.onload = init;
}

function init(){
	forms();
	edge();
	dropDown();
	minHeight();
}

function edge(){
	if (checkIE > 7) {
		var wrapper = document.getElementById('bodyWrapper');
		var topWrapper = document.getElementById('header');
		
		leftShadow = document.createElement('div');
		leftShadow.style.position = 'absolute';
		leftShadow.style.left = '-25px';
		leftShadow.style.top = '0';
		leftShadow.style.height = '100%';
		leftShadow.style.width = '25px';
		leftShadow.style.background = 'url(_fuse/4/_/leftShadow.png) repeat-y 0 0';
		
		rightShadow = document.createElement('div');
		rightShadow.style.position = 'absolute';
		rightShadow.style.right = '-25px';
		rightShadow.style.top = '0';
		rightShadow.style.height = '100%';
		rightShadow.style.width = '25px';
		rightShadow.style.background = 'url(_fuse/4/_/rightShadow.png) repeat-y 0 0';
		
		topShadow = document.createElement('div');
		topShadow.style.position = 'absolute';
		topShadow.style.zIndex = '15';
		topShadow.style.left = '0';
		topShadow.style.bottom = '-25px';
		topShadow.style.height = '25px';
		topShadow.style.width = '100%';
		topShadow.style.background = 'url(_fuse/4/_/topShadow.png) repeat-x 0 0';
		
		wrapper.appendChild(leftShadow);
		wrapper.appendChild(rightShadow);
		topWrapper.appendChild(topShadow);
	}
}

var dropItem = new Array();
function dropDown() {
	var listItem = document.getElementById('mainNav').getElementsByTagName('li');
	for(i = 0; i < listItem.length; i++){
		if(listItem[i].getElementsByTagName('div').length > 0){
			if(listItem[i].getElementsByTagName('div')[0].offsetParent.offsetLeft + 236 + listItem[i].getElementsByTagName('div')[0].offsetWidth > 900){
				listItem[i].getElementsByTagName('div')[0].style.left = (900 - (listItem[i].getElementsByTagName('div')[0].offsetParent.offsetLeft + 236 + listItem[i].getElementsByTagName('div')[0].offsetWidth)) + 'px';
			}
			dropItem[dropItem.length] = listItem[i];
			listItem[i].state = 0;
			listItem[i].ident = i;
			listItem[i].onmouseover = function(){
				this.state = 1;
				showDropDown(this);
				hideDropDown();
				//setTimeout(function(){
				//	hideDropDown();
				//}, 5000);
			}
			listItem[i].onmouseout = function(){
				this.state = 0;
				t = this;
				setTimeout(function(){
					hideDropDown();
				}, 3000);
			}
		}
	}
}
function showDropDown(t){
	t.state = 1;
	t.getElementsByTagName('div')[0].style.visibility = 'visible';
}
function hideDropDown(){
	for (i = 0; i < dropItem.length; i++) {
		//if (console) {console.log('attempt to hide ' + dropItem[i].ident + ' : ' + dropItem[i].state);}
		if (dropItem[i].state == 0) {
			dropItem[i].getElementsByTagName('div')[0].style.visibility = '';
		}
	}
}

var longPost = new Array();
var footer = new Array();
function minHeight(){
	var divs = document.getElementsByTagName('div');
	for(i = 0; i < divs.length; i++){
		if(divs[i].className.match('longPost') == 'longPost'){
			longPost[longPost.length] = divs[i];
		}
		if(divs[i].className.match('footer') == 'footer'){
			footer[footer.length] = divs[i];
		}
	}
	setHeight();
	window.onresize = setHeight;
}

function setHeight(){
	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;
	}
	
	for(i = 0; i < longPost.length; i++){
		if(checkIE > 6){
			longPost[i].style.minHeight = (myHeight - footer[0].offsetHeight - 0) + 'px';
		}
		else{
			longPost[i].style.height = (myHeight - footer[0].offsetHeight - 0) + 'px';
		}
	}
}