var Apaja = {

	init: function() {
		Apaja.externalLinks();
		Apaja.siteSelect();
		Apaja.location();
		Apaja.FB();
	},

	externalLinks: function() {
		var anchors = document.getElementsByTagName('a');
		for (var i = 0, l = anchors.length; i < l; i++) {
		        var anchor = anchors[i];
		        if (anchor.getAttribute('href') && anchor.getAttribute('rel') == 'external') {
		                anchor.target = '_blank';
		                anchor.title = 'Link opens a new browser window';
		        }
		}
	},
	
	siteSelect: function() {
		var form = document.getElementById('sites');		
		if (form) {
			var select = document.getElementById('site');
			form.onsubmit = Apaja.gotoSite;
			select.onchange = Apaja.gotoSite;
		}
	},

	gotoSite: function() {
		var select = document.getElementById('site');
		if (select) {
			var site = select[select.selectedIndex].value;
			select.className = select[select.selectedIndex].className;
			window.open(site);
		}
	},
	
	location: function() {
		var link = document.getElementById('location');
		if (link) {
			link.onclick = function() {
			        window.open(link.href, 'loc', 'width=640,height=480,toolbar=no,menubar=no,resizable=no,scrollbars=no,status=no,location=no');
	        		return false; 
			}
		}
		var addr = document.getElementById('addr');
		if (addr && link) {
			addr.onclick = function() {
			        window.open(link.href, 'loc', 'width=640,height=480,toolbar=no,menubar=no,resizable=no,scrollbars=no,status=no,location=no');
	        		return false; 
			}
		}
	},

	FB: function() {
		window.fbAsyncInit = function() {
			FB.init({appId: '321228965266', status: true, cookie: true,
			xfbml: true});
		};
		(function() {
			var e = document.createElement('script'); e.async = true;
			e.src = 'http://connect.facebook.net/en_US/all.js';
			document.getElementById('fb-root').appendChild(e);
		}());
	}
};

window.onload = Apaja.init;
