window.addEvent('domready', function() {
	
	/* Hide from non-spambots */
	$($('contact_content').getParent()).setStyle('display','none');
	
	/* Do form submitters run Javascript I wonder? */
	$('js').setAttribute('value','yes');
	
	/* Do ajax form submit */
	$('contact_form').addEvent('submit', function (e) {
		e = new Event(e);
		e.stop();
		
		// Ignore enter keypresses on input fields
		if (e.target === $('contact_form')){
			var post = e.target.subject.value + e.target.email.value + e.target.body.value;
			if (window.lastPost == null || window.lastPost != post) {
				$('contact_results').set('text','');
				this.send();
				window.lastPost = post;
			}
		}
	});
	$('contact_form').get('send').addEvent('onSuccess', function(responseText){
			$('contact_results').set('text',responseText);
		});
	
	 /* Smooth scrolling to internal links */
	new SmoothScroll(null, window);
	
	/* Slide-out of lists */
	
	var titles = $$('.listTitle');
	var extras = $$('.listExtra');
	
	if (titles.length != extras.length){
		alert("Avast! It appears someone's not finished editing this page. Whoops!");
		return;
	}
	
	window.sliders = new Array();
	window.slideHideCount = 0;
	
	var fn = function(title, extra){
		var slide = new Fx.Slide(extra).hide();
		window.sliders[window.sliders.length] = slide;
		window.slideHideCount++;
		
		title.set('class','listTitle ' + (slide.open ? 'open' : 'closed'));
		title.addEvent('click', function(){
			slide.toggle();
		});
		slide.addEvent('onComplete', function(){
			if (slide.open) {
				title.set('class','listTitle open');
				window.slideHideCount--;
			} else {
				title.set('class','listTitle closed');
				window.slideHideCount++;
			}
		});
	};
	
	for (var i = titles.length - 1; i >= 0; i--){
		fn(titles[i], extras[i]);
	};
});