function externalLinkListener() {
	$$('a[rel=external]').each(function(el) {
		$(el).observe('click', function(event) {
			event.stop();
			window.open(this.href);
		});
	});
}

document.observe('dom:loaded', externalLinkListener);

function informationFeatureListener() {
	var information_element = 'home_extra_contents';
	
	if ($(information_element)) {
		// preload images
		(new Image).src = 'img/site_specific/layout/big-img-require.png';
		(new Image).src = 'img/site_specific/layout/big-img-sales.png';
		(new Image).src = 'img/site_specific/layout/big-img-vendor.png';
		(new Image).src = 'img/site_specific/layout/big-img-pack.png';

		// tab link listeners
		$$('#' + information_element + ' ul li a').each(function(el) {
			$(el).observe('click', displayInformationFeature);
		});
		
		// feature image listeners
		$$('#' + information_element + ' div.big-image a.next').each(function(el) {
			$(el).observe('click', displayInformationFeature);
		});
	}
}

function displayInformationFeature(e) {
	e.stop();
	
	var information_element = 'home_extra_contents';
	var tokens = $(this).readAttribute('href').split('#');
	
	// clear selected link
	$(information_element).down('a.selected').removeClassName('selected');
	$(information_element).down('a[href=#' + tokens[1] + ']').addClassName('selected');

	// display selected div
	var current = $(information_element).down('.' + tokens[1]);
	if ($(current).hasClassName('off')) {
		// clear previously "on" div
		$(information_element).down('div.on').addClassName('off');
		$(information_element).down('div.on').removeClassName('on');
		
		$(current).removeClassName('off');
		$(current).addClassName('on');
	}
}

document.observe('dom:loaded', informationFeatureListener);

function eventSearchHint() {
	if ($('event_search')) {
		var hint = 'Search: Title, Location, Date';
		
		$('event_search').observe('focus', function() {
			if ($(this).getValue() == hint) {
				$(this).setValue('');
			}
		});
		
		$('event_search').observe('blur', function() {
			if ($(this).getValue() == '') {
				$(this).setValue(hint);
			}
		});
	}
}

document.observe('dom:loaded', eventSearchHint);

function loginHint() {
	if ($('login-field')) {
		var hint = 'Login';
		
		$('login-field').observe('focus', function() {
			if ($(this).getValue() == hint) {
				$(this).setValue('');
			}
		});
		
		$('login-field').observe('blur', function() {
			if ($(this).getValue() == '') {
				$(this).setValue(hint);
			}
		});
	}
}

document.observe('dom:loaded', loginHint);

function searchHint() {
	if ($('searchbox')) {
		var hint = 'Search';
		
		$('searchbox').observe('focus', function() {
			if ($(this).getValue() == hint) {
				$(this).setValue('');
			}
		});
		
		$('searchbox').observe('blur', function() {
			if ($(this).getValue() == '') {
				$(this).setValue(hint);
			}
		});
	}
}

document.observe('dom:loaded', searchHint);

function eventCategoryFilter() {
	if ($('event_category_filter')) {
		$('event_category_filter').observe('change', function() {
			$('event_category_filter').up('form').submit();
		});
	}
}

document.observe('dom:loaded', eventCategoryFilter);
