

$(document).ready(function(){
	var $cookieOptions = { path: '/', expires: 30 };

	var $adjustLayout = function() {

		if($.browser.msie && $.browser.version < 7)
			$('#content').height(0);
		else
			$('#content').css({minHeight:0});

		var $contentHeight = Math.max($('#bd').height(), $(window).height()-$('#hd').height()-$('#ft').height()-10)-20;
		$contentHeight = Math.max($contentHeight, $('#content_right').height()-32);
		$contentHeight = Math.max($contentHeight, $('#content_left').height()-32);

		if($.browser.msie && $.browser.version < 7)
		{
			$('#content_right, #content_left').height($contentHeight);
			$('#content').height($contentHeight);
		}
		else
		{
			$('#content_right, #content_left').css({minHeight:$contentHeight});
			$('#content,').css({minHeight:$contentHeight});
		}
	}

	// Font size
	$('#fontSmall, #fontMedium, #fontBig').css('cursor','pointer').click(function(){
		var $fontSize = $(this).attr('size');
		$.cookie('fontSize', $fontSize, $cookieOptions);
		if($.browser.msie)
			$('body').css({fontSize:$fontSize});
		else
			$('body').animate({fontSize:$fontSize}, 1000);
		$adjustLayout();
	});
	var $fontSize = $.cookie('fontSize');
	if($fontSize)
	{
		$('body').css('font-size', $fontSize);
		$.cookie('fontSize', $fontSize, $cookieOptions);
	}


	// hide login box an show an request (show always of its forgot password form)
	//if(($('.tx-newloginbox-pi1').length > 1))
	//	$('#hd .tx-newloginbox-pi1').hide();

	// show box if has new password form
    $('#hd .tx-newloginbox-pi1:has(#tx-newloginbox-pi1-forgot_email)').show();

	$('#hd #login_btn').click(function(){
		//$(this).toggle(300);
		$('#hd .tx-newloginbox-pi1').toggle(300);

		return false;
	});
	$('#bd').click(function(){
		$('#hd .tx-newloginbox-pi1').hide(300);
	});

	// destroy logout-box an display its contents inline
	$('#hd .tx-newloginbox-pi1:has(#tx-newloginbox-pi1-logout_submit)').find('form').each(function(){
		$(this).appendTo($('#content_hd')).find('table').remove().find('p, h3, :input').appendTo($(this));
		$('#hd .tx-newloginbox-pi1, #hd #login_btn').remove();
	});
	// hide login boxes without controls after 5sek
	$('#hd .tx-newloginbox-pi1:not(:has(form))').show().animate({opacity:0.8}, 5000, function(){ $(this).hide(300); });



	// initial layout adjustment
	$(window).resize($adjustLayout);
	$adjustLayout();
	window.setTimeout($adjustLayout, 1000);






	/// ### User Registration Gender Settings for cwt_community
	// copy gender-input to tx_cwtcommunityuser_sex-input
	$('#tx-srfeuserregister-pi1-gender-1, #tx-srfeuserregister-pi1-gender-0').change(function(){
		if($(this).attr('checked'))
			$('#tx-srfeuserregister-pi1-tx_cwtcommunityuser_sex').val($(this).val());
	});
	$('#tx-srfeuserregister-pi1-tx_cwtcommunityuser_sex').val($('#tx-srfeuserregister-pi1-gender-1').attr('checked') ? $('#tx-srfeuserregister-pi1-gender-1').val() : 0);

});