window.addEvent('domready', function(){
	$(document.body).addClass('has_script');
	
	// setup header search interactivity
	if ($('global_search')) {
		(function () {
			// text that shows up in search input box
			var initialText = 'Enter Keywords';
			// gather elements
			var form = $('global_search');
			var input = $('global_search-input');
			var submit = $('global_search-submit');
			
			input.value = initialText;
			
			// when input is blurred
			function inputBlur() {
				input.setProperty('class', 'blurred');
				input.setProperty('value', initialText);
			}
			// when input is focused
			function inputFocus() {
				input.setProperty('class', '');
				input.setProperty('value', '');
			}
			// add input events
			input.addEvent('focus', function () {
				if (this.value === initialText) inputFocus();
			});
			input.addEvent('blur', function () {
				if (this.value === '') inputBlur();
			});
			// initially blur input
			inputBlur();
			
			// form validation
			form.addEvent('submit', function (e) {
				if (input.value === '' || input.value === initialText) {
					e.preventDefault();
					input.setProperty('class', 'error');
				}
			});
		})();
	}
	
	// automatically replace all scroll bars on the page
	$$('.scroll_wrapper').each(function(item){
		item.scrollBar = new ScrollBar(item);
	});
	
	// helper for opening links in a new window
	// - add class="new_window" to all anchors that need to open in a pop up window
	// - add the rel attribute to the anchor to define window dimensions rel="width=XXX;height=XXX;"
	$$('a.new_window').addEvent('click', function(e){
		var target = $(e.target);
		e.preventDefault();
		// default dimensions 800x600
		var width = 800;
		var height = 600;
		// parse user configured window dimensions
		if(this.rel != ''){
			width = this.rel.split('width=')[1].split(';')[0].toInt();
			height = this.rel.split('height=')[1].split(';')[0].toInt();
		}
		window.open(this.href, '', 'toolbar=1,location=1,menubar=1,resizable=1,scrollbars=1,height=' + height + ',width=' + width);
	});
	
	// helper for opening links to external sites in a new window
	// - add class="link_outgoing" to all anchors that need to open in a pop up window
	// - add the rel attribute to the anchor to define window dimensions rel="width=XXX;height=XXX;"
	$$('.link_outgoing').each(function (item) {
		item.target = '_blank';
	});
	
	// click event for back link
	if($('page_back')){
		$('page_back').addEvent('click', function(e){
			e.preventDefault();
			history.back();
		});
	}
});