(function() {
	
	// set the date in the hedaer of the page
	function setDate (container) {
		var date = new Date();

		var weekday = [];
		weekday[1] = "Monday";
		weekday[2] = "Tuesday";
		weekday[3] = "Wednesday";
		weekday[4] = "Thursday";
		weekday[5] = "Friday";
		weekday[6] = "Saturday";
		weekday[7] = "Sunday";

		var month = [];
		month[0] = "January";
		month[1] = "February";
		month[2] = "March";
		month[3] = "April";
		month[4] = "May";
		month[5] = "June";
		month[6] = "July";
		month[7] = "August";
		month[8] = "September";
		month[9] = "October";
		month[10] = "November";
		month[11] = "December";
		
		$(container).update(weekday[date.getDay()] + ', ' + month[date.getMonth()] + ' ' + date.getDate() + ', ' + date.getFullYear());
		
	}
	
	function recentNews (container) {
		if (container) {
			var newsText = container.firstChild.nodeValue;
			container.update(newsText.truncate(126));	
		}
	}
	
	function resetField (field) {
		if (!field.defaultValue) return;
		
		field.observe("focus", function() {
			if (this.value == this.defaultValue) {
				this.value = '';
			}
		});
		
		field.observe("blur", function() {
			if (this.value == '') {
				this.value = this.defaultValue;
			}
		});
	}
	
	function sideNav (el) {
		console.log(el);
	}
	
	function init () {
		setDate($('header_date'));
		recentNews($('recent_news_item'));
		$$("input.reset").each(resetField);
		$$("ul.docs li:nth-child(odd)", "ul.results li:nth-child(odd)").invoke('addClassName', 'other');
		$$("dl.link_listing dd:last-child").invoke('addClassName', 'last');
	}
	
	document.observe("dom:loaded", init);
	
})();
