$(document).ready(function() {
	$('#list-first input[type=radio]').click(function() {
		document.location.href = '/' + $('input[name=choice-first]:checked').attr('id').split(/-/)[1];
	});
	
	$('#lag-chooser').change(function() { $('#choice-lag-form').submit(); });
	$('#language').change(function() { $('#language-form').submit(); });
	
	$('#choice-tabeller-klass').change(function() {
		$('#choice-tabeller-serie').get(0).options[0].selected = 'selected';
	});
	
	$('#embed-text').focus(function() {
		$('#embed-text').get(0).focus();
		$('#embed-text').get(0).select();
	});
	
	$('#embed_size').keyup(function() {
		var val = $('#embed_size').get(0).value;
		var height = 300+(val*10);
		
		$('#embed-text').html('&lt;iframe width="300" height="' + height + '" frameborder="0" scrolling="no" src="http://gothia.dev.trodon.se/lag/frame?id=25023&amp;games=' + val + '"&gt;&lt;/iframe&gt;');
	});
	
	$('#gruppspel-klass').change(function() {
		var class_id = $('#gruppspel-klass').val();
		
		$.getJSON("/gruppspel/grupper", { 'class_id': class_id }, function(json) {
			if (json && json[0] && json[0].name) {				
				var el = $('#gruppspel-serie').get(0);
				$(el).html('');
				
				$.each(json, function () {
					el.options[el.options.length] = new Option(this.name, this.name);
				});
			}
		});
	});
});

