document.observe("dom:loaded", function() {

	$('lang-switcher').observe('change', function() {
		var path;
		var options = $$('#lang-switcher option');
		for(var i = 0; i < options.length; i++)
		{
			if(options[i].selected)
			{
				path = options[i].readAttribute('value');
				break;
			}
		}
		
		if(path != window.location.pathname)
		{
			window.location = window.location.protocol + '//' + window.location.hostname + path;
		}
	});

	// selecting the current language
	$$('#lang-switcher option').each(function(option) {
		if(option.readAttribute('value') == window.location.pathname)
		{
			option.writeAttribute('selected', 'selected');
		}
	}); 
});

