$(function() {
	$('#search-icons > ul').tabs();
	// ugly - .tabs(2) doesn't seem to work
	$('#search-icons > ul .needed').trigger("click");
});

$(function() {
	var region= new Array();
	var updateSelect= function(regions) {
		var select= $('select[name=region]');
		select.empty();
		select.append("<option value=\"\">Alle regioner</option>");
		$.each(regions, function(i, opt) {
			select.append("<option value=\""+opt["id"]+"\">" + opt["title"]+"</option>");
		});
	};
	$('select[name=country]').change(function() {
		var code= $(this).val();
		var uri= "../../" + code + "/?format=json";
		if(!region[code]) {
			$.getJSON(uri, function(data) {
				region[code]= data;
				updateSelect( data );
			});
		} else {
			updateSelect( region[code] );
		}
	});
	$('form[name=searchbox]').bind("submit", function() { 
		if($('select[name=country]').val() != "") return true;
		$('select[name=country]').focus();
		return false;
	});
});
