(function() {
	function search_field (field) {
		var str = 'Search';
		if (field.value == '') {
			field.value = str;
		}
		
		field.observe('focus', function() {
			if (field.value == field.defaultValue || field.value == str) {
				field.value = '';
			}
		});
		
		field.observe('blur', function() {
			if (field.value == '') {
				field.value = field.defaultValue;
			}
		});
	}
	
	function ad_target (el) {
		el.observe('click', function(e) {
			e.preventDefault();
			window.open(el.href);
		});
	}
	
	function nav_links (el) {
		if (el.next('a')) {
			el.next('a').insert({before: ' &nbsp;|&nbsp; '})
		};
	}
	
	function preloadImg(image) {
		var img = new Image();
		img.src = image;
	}
	
	function rollovers (el) {
		el.srcOver = el.src.replace(/(\.[^.]+)$/, '_r$1');
		el.srcOut = el.src;
		preloadImg(el.srcOver);
		el.observe('mouseover', function() {
			this.src = el.srcOver;
		});
		el.observe('mouseout', function() {
			this.src = el.srcOut;
		});
	}
	
	function init () {
		$$('input.search').each(search_field);
		$$('div.ad_links a', 'a.flickr', 'div#flickr_photo a').each(ad_target);
		$$('div.navigation a').each(nav_links);
		$$('a.rollover img').each(rollovers);
	}
	
	document.observe('dom:loaded', init);
	
})();
