function initializeExternalLinks() {
	
	$$('a.external').each(function(link) {
		link.observe('click', function(e){
			window.open(link.href, 'external');
			Event.stop(e);
		})
		
	})
	
	$$('a.popped').each(function(link) {
		link.observe('click', function(e){
			var options = 'toolbars=0,directories=0,scrollbars=1,resizable=1,location=0,width=600,innerWidth=600,height=700,innerHeight=700'
			if (link.rev) {
				options = link.rev;
			}
			
			popped = window.open(link.href, 'popped', options);
			popped.focus();
			Event.stop(e);
		})
		
	})
	
}

function initializeBannerAlerts() {
	
	$$('a.bannerAlert').each(
		function(link) {
			link.observe('click', function(e) {
				
				var url = "/banner_alert.php?src=" + encodeURIComponent(link.id)
				new Ajax.Request(url,{
					method: 'get',
					  onComplete: function(transport) {
						/* if target on link, or link marekd as external, new window is already open, do nothing */
						if (!link.target && !link.hasClassName('external')) {
							window.location.href = link.href;
						}
					  }
					});
				
				/* if there's no target, or link is not marked as external, stop event, we'll process it later */
				if (!link.target && !link.hasClassName('external')) {
					Event.stop(e);
				}
			});
		
		}
	)
}

function initializeQuickSearch() {
	
	$('qsselect').observe('change', function(e) {
		document.location.href = $F('qsselect');
		Event.stop(e);
	});
	
}

NavBuilder = {
	
	topNavHtml: '<ul>' +
		'<li><a href="/">home</a></li>' +
		'<li><a href="/map/">map</a></li>' + 
		'<li><a href="http://forum.1stopthailand.com/">forum</a></li>' +
		'<li><a href="http://blogs.1stoppattaya.com/">blogs</a></li>' +
		'<li><a href="/travel_news/">news</a></li>' +
		'<li><a href="/video/">video</a></li>' +
		'<li><a href="/about/">about</a></li>' +
		'<li><a href="/about/#contact">contact</a></li>' +
		'</ul>',
	
	insertTopNav: function() {
		$('header').firstDescendant().insert({after: this.topNavHtml})
	}
	
	
}


document.observe('dom:loaded', function() {NavBuilder.insertTopNav()});
Event.observe(window, 'dom:loaded', initializeExternalLinks);
Event.observe(window, 'dom:loaded', initializeBannerAlerts);
Event.observe(window, 'dom:loaded', initializeQuickSearch);