//document.addEventListener("load", indexInit ,false);
window.addEventListener("load", onLoadHandler, false);

//index JS
function onLoadHandler(event) {
	
	//set email on index
	var el = document.getElementById("liam");
	var el2 = document.getElementById("em");
	if(el) { el.setAttribute("href","mailto:" + "edwin.webb@gmail.com") }
	if(el2) { el2.setAttribute("href","mailto:" + "edwin.webb@gmail.com") } //this has to be the laziest edit ever
	
	//set text sizes on index splash
	if(el) { //still on index
		var cont = document.getElementById("index-splash");
		var img = cont.children[0];
		var txt = cont.children[1];
		var fsa = ["4em","3em","2em","1.5em","1em"];
		
		//shrink quote until it fits, clientHeights should be cached
		while(txt.clientHeight > img.clientHeight && fsa.length) {
			txt.style.fontSize = fsa.shift();
		}
		
		//center it
		txt.style.top = -img.clientHeight/2  -txt.clientHeight/2 + "px";
		
		//show it
		txt.style.visibility = "visible";
	}
	 
	//check col height for sub menu and scroll if needs be
	var sm = document.getElementById("submenu");
	if(sm.clientHeight > window.innerHeight) {
		sm.style.position = "absolute";
	}
	
	//collapse sub menus kinda TODO here
	document.getElementById("submenu").addEventListener("click",submenuClickHanlder);
	
	function submenuClickHanlder(e) {
		
		var list;
		
		if(!e.target.tagName) {
			return;
		} else if(e.target.tagName == "H2") {
			list = e.target.nextElementSibling;
		} else if (e.target.tagName == "A" && e.target.parent.tagName == "H2") {
			e.preventDefault();
			list = e.target.parentElement.nextElementSibling;
		}
		
		list.style.maxHeight = list.style.maxHeight == "0px" ? "300px" : "0px";
		
	}
	
}



