function getWindowHeight() {
  var myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
	//Non-IE
	myHeight = window.innerHeight;
  } else if( document.documentElement &&
	  ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	//IE 6+ in 'standards compliant mode'
	myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	//IE 4 compatible
	myHeight = document.body.clientHeight;
  }
  return myHeight;
}

function adjustLayout() {
	$('#navlist').css('height', (getWindowHeight() - 52 /* padding-top im ul */) + 'px');
	$('#nav').css('height', getWindowHeight() + 'px').addClass('loaded');
	$('#content').css('height', (getWindowHeight() - 95 /* padding-top + padding-bottom im #content */) + 'px').addClass('loaded');
}

$(document).ready(function() {
	adjustLayout();
	$('#content').focus();

	if ($('body').is('.templateanwaelte')) {
		$('#anwaelte li').click(function() {
			var href = $(this).find('a').attr('href');
			window.location = href;
			return false;
		});
	}

	if ($('body').is('.templaterechtsgebiete')) {
		$('#rechtsgebiete > ul').each(function(index) {
			$(this).find('ul').hide();
			$(this).find('span.rgg-head').wrap('<a href="#" class="rgg-head"></a>');
			$(this).find('a.rgg-head').click(function() {
				$(this).parents('li').find('ul').toggle();
				return false;
			});
		});
	}

	if ($('body').is('.templatenewsletter')) {
		$('#newsletter div.rgg').hide();
		$('#newsletter input[type=checkbox]').click(function() {
			var div = $(this).parent().find('div.rgg');
			if ($(this).attr('checked'))
				div.show();
			else
				div.hide();
		});
	}

	$('select.selector').change(function() {
		$('#element-list').load($(this).val() + '.html?ajax');
		$('select.selector').not(this).attr('selectedIndex',0);
	});

});

$(window).resize(function() {
	adjustLayout();
});
