// contents of ../_/js/general/print.js
function showPrint(id, link, removeElement)
{
	var element = $(id);
	var onresize = window.onresize;
	window.onresize = null;
	var className = document.body.className;
	document.body.className = 'print';

	var elements = [], temp;
	while(temp = document.body.lastChild)
	{
		elements.push(temp)
		document.body.removeChild(temp);
	}
	
	if(removeElement)
	{
		for(var n = 0; n < element.childNodes.length; n++) // adds everything except the print link
			if((temp = element.childNodes[n]) != link)
				document.body.appendChild(temp.cloneNode(true));
	}
	else document.body.appendChild(element.cloneNode(true));
	
	window.setTimeout(print, 250);
	
	function print()
	{
		window.print();
		window.setTimeout(clear, 100);
	}
	
	function clear()
	{
		while(temp = document.body.lastChild)
			document.body.removeChild(temp);
		for(var n = 0; n < elements.length; n++)
			document.body.appendChild(elements[n]);
		window.onresize = onresize;
		document.body.className = className;
	}
	
	return false;
}
// contents of js/index.js
var currentID, currentDiv = null, currentLink = null;

window.init = init;
window.showLinks = showLinks;
window.showHide = showHide;
window.showPage = showPage;

function init(id, title)
{
	currentID = id
	currentDiv = $('codeAbout_div');
	currentLink = $('codeAbout_a');
	
	if(window.location.hash)
	{
		var page = window.location.hash.substr(1);
		$(page+'_a').onclick();
	}
	
	var match = navigator.userAgent.match(/MSIE\s*([\d\.]+)/);
	if(match == null || match[1] > '6.0')
	{
		roundedEM({r:15, top:false}, null, 'header_div');
		roundedEM({r:15}, null, 'content_div');
//		roundedEM({r:15, bottom:false}, null, 'footer_div');
		if($('select_div'))
			roundedEM({r:15, left:false}, null, 'select_div');
		if($('programs_div'))
			roundedEM({r:15, right:false}, null, 'programs_div');
		if($('quoteNav_div'))
			roundedEM({r:15, left:false}, null, 'quoteNav_div');
		if($('quoteContent_div'))
			roundedEM({r:15, right:false}, null, 'quoteContent_div');
	}
	var lis = document.ge('link_ul').childNodes;
	
//	for(var n = 0; n < lis.length; n++)
//		if(lis[n].nodeName.toLowerCase() == 'li')
//			roundedEM({r:10}, null, lis[n].firstChild);
}

function showLinks(link, id)
{
	link.blur();
	var expand = link != currentLink;
	var children = link.parentNode.childNodes;
	for(var n = 0; n < children.length; n++)
		if(children[n].nodeName.toLowerCase() == 'ul')
			children[n].style.display = (expand || children[n].style.display == 'none') ? '' : 'none';

	if(currentLink)
		currentLink.className = '';
	currentLink = link;
	currentLink.className = 'current';
	
	if(currentDiv)
		currentDiv.style.display = 'none';
	
	currentDiv = ge(id);
	if(currentDiv.innerHTML.charAt(0) == '@')
	{
		var url = 'files/'+currentDiv.innerHTML.substr(1)+'.inc.html';
		currentDiv.innerHTML = '';
		currentDiv.appendChild(loadFile(url));
	}
	currentDiv.style.display = '';
}

function showHide(id, link)
{
	var div = ge(id); 
	div.style.display = (div.style.display == 'none') ? '' : 'none'; 
	return false;
}

function showPage(id, title, link)
{
	if(link)
		link.blur();

	var element;
	if(element = ge(currentID+'_a'))
		element.className = '';
	if(element = ge(id+'_a'))
		element.className = 'current';
	
	if(element = ge(currentID+'_div'))
		element.style.display = 'none';
	if(element = ge(id+'_div'))
		element.style.display = '';

	window.location.hash = currentID = id;
	document.title = 'Joseph Hermens - '+title;
	
	return false;
}

var lastQuoteLink;
function showQuotes(link, index)
{
	if(lastQuoteLink)
		lastQuoteLink.className = '';
	if(link)
	{
		lastQuoteLink = link;
		link.className = 'current';
		link.blur();
	}
	
	var n = 0, current;
	while(current = ge('quotes_'+n))
		current.style.display = (index != n++ && index !== null) ? 'none' : '';
	
	if(index !== null)	
		ge('quotes_'+index).parentNode.scrollTop = 0;
	return false;
}

function ge(id)
{
	return document.getElementById(id);
}



function loadFile(url)
{
	var div = divEM({});
	var loading = div.ac(loadingEM({}));
	httpRequest(url, onLoad);
	return div;
	
	function onLoad(html)
	{
		loading.rs();
		div.innerHTML = html;
	}
}

function httpRequest(url, handler)
{
	if(window.XMLHttpRequest || window.ActiveXObject)
	{
		var request = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		request.onreadystatechange = onStateChange;
		request.open('GET', url, true);
		request.send(null);
	}
	else alert('XML request not supported, get a new browser!!!');
	
	function onStateChange()
	{
		if(request.readyState == 4) // 4 means done loading
		{
			if(request.status == 200)
				handler(request.responseText);
			else alert('Load Failed: status: '+request.status+": "+request.statusText);
		}
	}
}
// contents of ../_/js/em/em.js
//var googleChrome = navigator.userAgent.match(/Chrome/i) ? true : false;
var firefox = navigator.userAgent.match(/Firefox/i) ? true : false;

function $(id)
{
	return document.getElementById(id);
}

document.doc  = function()
{
	return (document.compatMode && document.compatMode != 'BackCompat') ? document.documentElement : document.body;
};
document.size = function()
{
	var height = (document.documentElement) ? document.documentElement.clientHeight : document.body.clientHeight;
	var width  = (document.documentElement) ? document.documentElement.clientWidth  : document.body.clientWidth;
	var bodyW = document.style('width', null), match;
	var offset = (bodyW && (match = bodyW.match(/(\d+)px/i))) ? Math.round((width - match[1]) / 2) : 0;
	width -= offset * 2;
	return {w:width, h:height, o:offset};
};
document.style = function(key, def, numeric) 
{ 
	var doc = document.doc();
	var style = (doc.currentStyle) ? doc.currentStyle : getComputedStyle(doc, null);
	if(key)
	{
		var value = style[key];
		if(value == undefined)
			return def;
		else return (numeric) ? parseInt(value) : value;
	}
	else return style;
};
document.ge = function(id, def) 
{ 
	var element = document.getElementById(id); 
	if(element)
		return element;
	else if(def)
		return def;
	else alert('element not found: '+id);
};
document.cl = function()      { while(document.body.hasChildNodes()) document.rc(document.body.firstChild); };
document.ac = function(child) { document.body.appendChild(typeof(child) != 'object' ? child = document.createTextNode(child) : child); return child; };
document.rc = function(child) { document.body.removeChild(child); return child; };
document.sw = function(newChild, oldChild) { document.body.replaceChild(newChild, oldChild); };

function baseEM(prop, content, element, type) // type is tag or element
{
	element = element ? (typeof(element) == 'string' ? document.ge(element) : element) : document.createElement(type);
	element.prop = prop;

	if(firefox == false || element.protoBase == null)
	{
		var proto, match;
		if(firefox && (match = element.toString().match(/\s[^\]]+/)) && (proto = eval(match[0]).prototype))
		{
			proto.proto = proto;
			proto.protoBase = true;
		}
		else proto = element;

		proto.ac = function(child)
		{
			if(typeof(child) == 'object')
			{
				if(child instanceof Array)
				{
					for(var n = 0; n < child.length; n++)
					{
						if(typeof(child[n]) == 'object')
							this.appendChild(child[n]);
						else this.appendChild(child[n] = document.createTextNode(child[n]));
					}
				}
				else this.appendChild(child);
			}
			else this.appendChild(child = document.createTextNode(child));
			
			return child;
		};
	
		proto.cl = function(startAfter, stopBefore)
		{
			if(startAfter != null)
			{
				var current = this.firstChild;
				while(current != null)
				{
					if(current == startAfter)
					{
						current = current.nextSibling;
						while(current != null && current != stopBefore)
						{
							var temp = current;
							current = current.nextSibling;
							this.removeChild(temp);
						}
						break;
					}
					else current = current.nextSibling;
				}
			}
			else if(stopBefore != null)
			{
				while(this.hasChildNodes() && this.firstChild != stopBefore)
					this.removeChild(this.firstChild);
			}
			else
			{
				while(this.hasChildNodes())
					this.removeChild(this.firstChild);
			}
		};
		
		proto.cn = function(index)
		{
			return this.childNodes[index];
		};
		
		proto.ih = function(html)
		{
			this.innerHTML = html;
		};

		proto.rs = function()
		{
			var parent = this.parentNode
			if(parent != null && parent != '#document-fragment')
				parent.removeChild(this);
		};

		proto.ia = function(newElement, oldElement)
		{
			if(typeof(newElement) != 'object')
				newElement = document.createTextNode(newElement);
			if(oldElement.nextSibling)
				this.insertBefore(newElement, oldElement.nextSibling);
			else this.appendChild(newElement);
			return newElement;
		}
		proto.ib = function(newElement, oldElement)
		{
			if(typeof(newElement) != 'object')
				newElement = document.createTextNode(newElement);
			this.insertBefore(newElement, oldElement);
			return newElement;
		};
		
		proto.rc = element.removeChild;
		
		proto.rw = function(newElement) 
		{ 
			if(typeof(newElement) != 'object')
				newElement = document.createTextNode(newElement);
			this.parentNode.replaceChild(newElement, this);
			return newElement;
		};
		
		proto.sw = function(newElement, oldElement)
		{
			if(typeof(newElement) != 'object')
				newElement = document.createTextNode(newElement);
			this.replaceChild(newElement, oldElement);
			return newElement;
		};
		
		proto.hide = function() { this.style.display = 'none'; };
		proto.show = function() { this.style.display = ''; };

		// proto.size not allowed for form elements
		proto.setSize = function(size)
		{
			if(typeof(size) == 'object')
			{
				if(size.w)
					this.style.width = size.w+'px';
				if(size.h)
					this.style.height = size.h+'px';
			}
			else if(typeof(size) == 'number')
				this.style.width = size+'px';
		};
		
		proto.gs = function(key, def, numeric) 
		{ 
			var style = this.currentStyle || getComputedStyle(this, null) || this.style;
			if(key)
			{
				var value = style[key];
				if(value !== undefined)
					return def;
				else return (numeric) ? parseInt(value) : value;
			}
			else return style;
		};

	}

	if(prop.id)
		element.id = prop.id;
	if(prop.c)
		element.className = prop.c;
	if(prop.s)
		element.setSize(prop.s);
	if(prop.t)
		element.title = prop.t;
	if(content != undefined)
	{
		if(prop.html)
		{
			if(content)
				element.innerHTML = content;
		}
		else element.ac(content);
	}
	return element;
}

function absEM(prop, content, element)
{
	element = baseEM(prop, content, element, 'div');
	
	if(firefox == false || element.protoAbs == null)
	{
		var proto;
		if(firefox && element.proto)
		{
			proto = element.proto;
			proto.protoAbs = true;
		}
		else proto = element;

		proto.position = function(position)
		{
			if(typeof(position.l) == 'number')
				this.style.left = position.l+'px';
			if(typeof(position.r) == 'number')
				this.style.right = position.r+'px';
			if(typeof(position.t) == 'number')
				this.style.top = position.t+'px';
			if(typeof(position.b) == 'number')
				this.style.bottom = position.b+'px';
		};
		
		proto.level = function(level) { this.style.zIndex = level; };
	}
	element.style.position = 'absolute';
	if(prop.p)
		element.position(prop.p);
	return element;
}

function brEM()
{
	return document.createElement('br');
}

function divEM(prop, content, element)
{
	element = baseEM(prop, content, element, 'div');
	return element;
}

function iframeEM(prop, url, element)
{
	element = baseEM(prop, null, element, 'iframe');
	if(firefox == false || element.protoIframe == null)
	{
		var proto;
		if(firefox && element.proto)
		{
			proto = element.proto;
			proto.protoIframe = true;
		}
		else proto = element;

		proto.init = function(url) { this.src = url; };
	}
	
	if(url)
		element.init(url);
	return element;
}

function linkEM(prop, content, element)
{
	element = baseEM(prop, content, element, 'a');
	element.href = (prop.url) ? prop.url : 'javascript:;';
	
	if(firefox == false || element.protoLink == null)
	{
		var proto;
		if(firefox && element.proto)
		{
			proto = element.proto;
			proto.protoLink = true;
		}
		else proto = element;
		
		proto.onclick = function()
		{ 
			if(prop.oc)
				prop.oc(this);
			return (prop.allow || prop.allow == undefined) ? true : false;
		};
		
		proto.setT = function(title)
		{
			prop.t = title;
			this.sw(title, this.firstChild);
		};
	}
	if(prop.blank)
		element.target = '_blank';
	
	return element;
}

function spanEM(prop, content, element)
{
	return baseEM(prop, content, element, 'span');
}

function strongEM(prop, content, element)
{
	return baseEM(prop, content, element, 'strong');
}

function subEM(prop, content, element)
{
	return baseEM(prop, content, element, 'sub');
}

function supEM(prop, content, element)
{
	return baseEM(prop, content, element, 'sup');
}

function pEM(prop, content, element)
{
	return baseEM(prop, content, element, 'p');
}

function h1EM(prop, content, element)
{
	return baseEM(prop, content, element, 'h1');
}
function h2EM(prop, content, element)
{
	return baseEM(prop, content, element, 'h2');
}
function h3EM(prop, content, element)
{
	return baseEM(prop, content, element, 'h3');
}
function h4EM(prop, content, element)
{
	return baseEM(prop, content, element, 'h4');
}
function h5EM(prop, content, element)
{
	return baseEM(prop, content, element, 'h5');
}

function ulEM(prop, content, element)
{
	element = baseEM(prop, null, element, 'ul');
	if(firefox == false || element.protoUL == null)
	{
		var proto;
		if(firefox && element.proto)
		{
			proto = element.proto;
			proto.protoUL = true;
		}
		else proto = element;

		proto.ac = function(child)
		{
			if(typeof(child) == 'object')
			{
				if(child instanceof Array)
				{
					for(var n = 0; n < child.length; n++)
					{
						if(typeof(child[n]) == 'object')
						{
							if(child[n] instanceof Array)
								this.appendChild(child[n] = ulEM({}, child[n]));
							else this.appendChild(child[n]);
						}
						else this.appendChild(child[n] = liEM({}, child[n]));
					}
				}
				else this.appendChild(child);
			}
			else this.appendChild(child = liEM({}, child));
			return child;
		}
	}
	if(content)
		element.ac(content);
	return element;
}

function liEM(prop, content, element)
{
	return baseEM(prop, content, element, 'li');
}

function imgEM(prop, src, element)
{
	element = baseEM(prop, null, element, 'img');
	if(src)
		element.src = src;
	element.alt = prop.alt || prop.t || src;

	if(firefox == false || element.protoIMG == null)
	{
		var proto;
		if(firefox && element.proto)
		{
			proto = element.proto;
			proto.protoIMG = true;
		}
		else proto = element;

		proto.fit = function(fit)
		{
			var heightRatio = fit.ih / fit.ah;
			var widthRatio  = fit.iw / fit.aw;
			var scaledW, scaledH;
			if(heightRatio > widthRatio)
			{
				scaledW  = Math.floor(fit.iw / heightRatio);
				scaledH = fit.ah;
				if(fit.c)
					element.style.marginRight = element.style.marginLeft = Math.round((fit.aw - scaledW) / 2)+'px';
			}
			else
			{
				scaledW  = fit.aw;
				scaledH = Math.floor(fit.ih / widthRatio);
				if(fit.c)
					element.style.marginBottom = element.style.marginTop = Math.round((fit.ah - scaledH) / 2)+'px';
			}
			this.width  = scaledW;
			this.height = scaledH;
			this.style.width  = scaledW+'px';
			this.style.height = scaledH+'px';
		}
	}
	
	if(prop.f)
		element.fit(prop.f);
	if(prop.oc)
		element.onclick = prop.oc;
	return element;
}
// contents of ../_/js/em/loading.js
function loadingEM(prop, content, element)
{
	prop.c = 'loading_div'+(prop.c ? ' '+prop.c : '');
	var element   = (prop.inline) ? spanEM(prop, content, element) : divEM(prop, content, element);
	element.start = function() { intervalID = window.setInterval(element.onInc, prop.interval); };
	element.stop  = function() { window.clearInterval(intervalID); };

	var intervalID;
	var counter = 0;
	if(prop.interval == null)
		prop.interval = 500;
	if(prop.length == null)
		prop.length = 5;
	prop.timeout = (prop.timeout ? prop.timeout * 1000 : 30000) / prop.interval;
	
	element.onInc = function()
	{
		if(element.parentNode == null || element.parentNode.nodeName == '#document-fragment' || counter > prop.timeout)
			element.stop();
		else if(++counter % prop.length)
			element.ac('.');
		else element.cl(element.firstChild);
	}
	return element;
}
// contents of ../_/js/em/rounded.js
function roundedEM(prop, content, element)
{
	prop.c = 'rounded_div'+(prop.c ? ' '+prop.c : '');
	var element = divEM(prop, content, element);
	element.radius = setRad;
	var bottom = (prop.bottom === false) ? false : true;
	var top    = (prop.top    === false) ? false : true;
	var left   = (prop.left   === false) ? false : true;
	var right  = (prop.right  === false) ? false : true;
	
	var elements = [];
	if(prop.minR !== undefined && prop.maxR !== undefined)
	{
		var inc = prop.inc | 1, min = prop.minR, max = prop.maxR, cur = prop.r | Math.round((max - min) / 2), step = prop.step | 100, up = true;
		setRad(cur);
		window.setInterval(run, step);
	}
	else setRad(prop.r | 15);
	return element;
	
	function run() 
	{ 
		setRad(up ? cur += inc : cur -= inc); 
		if(cur >= max)
			up = false;
		else if(cur <= min)
			up = true;
	}
											   
	function setRad(rad)
	{
		while(elements.length)
			elements.pop().rs();
		var lastW = 0, lastH = 0;
		for(var n = Math.PI / 2; n <= Math.PI; n += Math.PI / rad / 3)
		{
//			if(bottom == false && n > Math.PI / 2)
//				continue;
//			if(top == false && n < Math.PI / 2)
//				continue;
			
			var w = Math.round((1 + Math.cos(n)) * rad);
			var h = Math.round((1 - Math.sin(n)) * rad);
			if(w > 0 && h > 0 && (w != lastW || h != lastH))
			{
				if(top && left)
					addDiv(w, h, true, true);
				if(top && right)
					addDiv(w, h, true, false);
				if(bottom && left)
					addDiv(w, h, false, true);
				if(bottom && right)
					addDiv(w, h, false, false);
			}
	//		else if(w == lastW)
	//			document.ac('width same');
	//		else if(h == lastH)
	//			document.ac('height same')
			lastW = w;
			lastH = h;
		}

		function addDiv(width, height, top, left)
		{
			var div = document.createElement('div'); // more efficient
			div.className = 'edge_div';
			div.style[top  ? 'top' : 'bottom'] = 0;
			div.style[left ? 'left' : 'right'] = 0;
			div.style.width = width+'px';
			div.style.height = height+'px';
			element.ac(div);
			elements.push(div);
		}
	}
}


