/*
	Site-specific JavaScript for Little People
	Requires dhtml_lib.js, mootools.js
*/

EventHelper.AddEvent(window, 'load', lp_init, false);

function lp_init() {
	
		if (typeof $ != 'undefined') {
			
			var theInstructionToggle = $('instruction-intro');
			
			if (theInstructionToggle) {
				var toggle = false;
				var el = $('instructions').getElementsByTagName('dl')[0];
				$(el).setStyle('overflow', 'hidden');
				var elHeight = el.scrollHeight;
				var instructionFx = new Fx.Style(el, 'height', { duration : 400 });
				instructionFx.start(0);
				
				$(theInstructionToggle).addEvent('click', function(e) {
					if (toggle == false) {
						instructionFx.start(0, elHeight);
						toggle = true;
					} else {
						instructionFx.start(elHeight, 0);
						toggle = false;
					}
				});
			}
		}

	
	
	
	
	// this is temporary, as the ajax call from dhtml_lib doesn't work correctly 
	// due to a bizarre firefox bug that skips over readyState 3 and ends up with 
	// empty responseText
	
					var links = document.getElementsByTagName('a');
					for (i=0; i<links.length; i++) {
						if (links[i].getAttribute('rel') && links[i].getAttribute('rel').match(/temporary-modal/g)) {
							var theLink = links[i];
							EventHelper.AddEvent(links[i], 'click', ptr = function(e) { runStuff(e, theLink); }, false);
						}
					}
					
					function runStuff(e, url) {
								// create new div
						var theBody = document.getElementsByTagName('body')[0];
						var newDiv = document.createElement('div');
						newDiv.className += 'overlay-modal';
						theBody.appendChild(newDiv);
								// make the ajax call
						AjaxHelper.load(newDiv, url);
						EventHelper.CancelDefault(e);
						EventHelper.AddEvent(document.body, 'click', ptr = function(e) { hideDiv(newDiv); }, false);
					}
					
					function hideDiv(el) {
						el.style.display = 'none';
					}
	
	
	
}

