$(document).ready(function() { 

	$('#hauptbereich a.play_game').click(function() { 
		var href = $(this).attr('href');
		var title = $(this).attr('title');
		popup(href, title, 1024, 768);
		return false;
	});	
	
	$('#rechte_spalte a.play_game').click(function() { 
		var href = $(this).attr('href');
		var title = $(this).attr('title');
		popup(href, title, 1024, 670);
		return false;
	});	
	
	// Klickbare Box (.linke_spalte)
	if($('.linke_spalte.hide').length) { 
		$('.linke_spalte').removeClass('hide');
		$('.linke_spalte:not(:first)').hide();
		$('.linke_spalte:first').show();
		$('.linke_spalte:last a.forw, .linke_spalte:first a.backw').addClass('aus');
		$('.linke_spalte').each(function(i) { 
			var $box = $(this);		
			$box.find('a.backw, a.forw').click(function() { 
			  if($(this).hasClass('aus') != true) {
				var wLs = i+1;
				if($(this).hasClass('backw')) var wLs = i-1;
				$box.hide();
				$('.linke_spalte:eq('+wLs+')').show();
			  };
				return false;
			});
		});
	};

	// ToggleTable
	$('table.toggletable tbody tr:odd').each(function() { 
		var $inhaltstr = $(this);
		$inhaltstr.hide();
		$('<a title="auf-/zuklappen" href="#" class="weiter"></a>')
			.prependTo($(this).prev().find('td:first'))
			.click(function() { 
				$(this).toggleClass('auf');
				$inhaltstr.prev().toggleClass('trauf');
				$inhaltstr.toggle();
				return false;
			});
	});

	// Schriftgrößen
	$('.funktionen1 li a').click(function() { 
		var groesse = $(this).attr('class');
		$('body').removeClass().addClass(groesse);
		return false;
	});
	
	$('select').selectbox();
	$('select').change(function() {	
		if($(this).val() != '' || $(this).val() != '#') { 
			window.location.href = $(this).val();
		}
	});
	
	equalHeight($('#hauptbereich *:not(.linke_spalte) div.box.round'));


});

function equalHeight(group) {
	tallest = 0;
	group.each(function() {
		thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.attr({ style: 'height: '+tallest+'px;' });
}

// Standard-JS-PopUp
function popup(url, title, pwidth, pheight) {
	var leftPos = (screen.width) ? (screen.width - pwidth) / 2:0;
	var topPos = (screen.height) ? (screen.height - pheight) / 2:0;
	var props = "width="+pwidth+", height="+pheight+", left="+leftPos+", top="+topPos+", toolbar=0, personalbar=0, menubar=0, scrollbars=0, resizable=0, status=0";
	newwindow = window.open(url, title, props);
	if (window.focus) { 
		newwindow.focus()
	}
	return false;
};