/*

Wee bit of custom JS to handle creating the overlay dynamically, without
needing a 3rd party library.

*/

(function(){

	var w=window, d=document, fn=w.onload;												// make sure this doen't break onload functions elsewhere
	w.IE6=false;																		// flag as false (conditional comments flag true for IE6)
	
	var $=function(id){
		return d.getElementById(id);
		};
	
	window.onload=function(e){
		if (fn) fn(e);
		
		var overlay=d.createElement('div');												// create the overlay div dynamically, since we can't mess around with the SL header/footer markup.
		overlay.id='overlay';
		
		var el=w.IE6 ? d.body : d.documentElement;
		overlay.style.height=(Math.max(el.offsetHeight || el.clientHeight, rv=el.scrollHeight))+'px';		// set the overlay height to the height of the document
		
		document.body.appendChild(overlay);												// applying the CSS rule after the body has rendered.
		
		var wrapper=document.createElement('div');										// now generate the wrapper. We need this as the overlay is transparent
		wrapper.id='overlay_content_wrapper';											// but the content needs to be opaque. We also use this to position the
		document.body.appendChild(wrapper);												// content centrally in the page.
		
		var close=document.createElement('a');											// add the close button to the wrapper
		close.id='overlay_close';
		close.href='#';
		wrapper.appendChild(close);
		
		var content;																	// this will reference the content to load into the wrapper
		
		close.onclick=function(){														// add handler to close the current overlay
			
			$('overlay').style.display=close.style.display='none';
			content.parentNode.removeChild(content);
			$('overlay_content').appendChild(content);
			return false;
			};
			
		var openOverlay=function(e){
			content=$(this.id.replace('_link','_overlay'));
			content.parentNode.removeChild(content);
			
			wrapper.style.top=(el.scrollTop)+'px';
			
			wrapper.appendChild(content);
			$('overlay').style.display=close.style.display='block';
			return false;
			};
			
			
		// find overlay links and give them event handlers
		
		var cls=!!d.getElementsByClassName;
		var links=cls ? d.getElementsByClassName('overlay_link') : $('front-container').getElementsByTagName('a'), l=links.length, n, i=0;
		while (n=links[i++]){
			if (cls || n.className=='overlay_link'){
				n.onclick=openOverlay;
				}
			}
		
		};

	})();