



document.observe('dom:loaded', function() {





	/**
	*
	*	MISC
	*
	**/

	if($('b_scrolltop')) { $('b_scrolltop').onclick = function() { _scrollTop(); return false; }; }

	if($('b_pageinfo')) { $('b_pageinfo').onclick = function() { openPageInfo(); return false; }; }

	pos1EndScroll = function(e) {
		key = (e.keyCode) ? e.keyCode : e.which;
		src = Event.element(e);

		if(src.tagName != 'INPUT' && src.tagName != 'TEXTAREA') {
			if(key == 36) { Event.stop(e); _scrollTop(); }
			if(key == 35) { Event.stop(e); _scrollDown(1); }
		}

		return false;
	}
	document.observe('keypress', pos1EndScroll);
















	/**
	*
	*	OPEN PAGE INFO
	*
	**/

	contentOriginalTopValue = parseInt($('content').getStyle('top'));
	openPageInfo = function() {

		$('b_pageinfo').hide();

		pageInfoHeight = $('content_pageinfo').getHeight();

		new Effect.Morph('content', {
			duration: 0.3,
			style: { 'top': contentOriginalTopValue+(pageInfoHeight-30)+'px' }
		});

		$('content_pageinfo').setStyle('opacity: 0.001;');

		$('content_pageinfo').appear({
			duration: 0.5
		});

	}

	closePageInfo = function() {

		new Effect.Morph('content', {
			duration: 0.3,
			style: { 'top': contentOriginalTopValue+'px' }
		});

		$('content_pageinfo').fade({
			duration: 0.3
		});

		$('b_pageinfo').show();

	}












	/**
	*
	*	SLMAIL-SIDEBOX
	*
	**/

	isrunning_slmail = false;
	if($('sidebox_slmail')) {

		$('form_sidebox_slmail').onsubmit = function() {

			if(!isrunning_slmail) {

				isrunning_slmail = true;

				new Insertion.Top($$('#form_sidebox_slmail p.submit')[0], '<img src="/imgs/loading_main.gif" alt="loading" id="slmail_loading" />');

				$$('#form_sidebox_slmail p.submit span')[0].hide();

				window.setTimeout(function() {

					new Ajax.Request('/slmail/', {
						parameters: $('form_sidebox_slmail').serialize(),
						onSuccess: function(t) {

							$('slmail_loading').remove();
							$$('#form_sidebox_slmail p.submit span')[0].show();

							e = eval('('+t.responseText+')');

							if(e.state == '1') {

								$('form_sidebox_slmail').reset();

								if($('b_cancel_slmailanswer')) {
									$('b_cancel_slmailanswer').onclick = function() {
										cancelslmail('regenerate');
										return false;
									};
								}
								Element.hide($('form_sidebox_slmail').getElementsByTagName('fieldset')[0]);

								new Insertion.Top('form_sidebox_slmail', '<div id="slmail_tmp" style="display: none;">'+e.html+'</div>');

								new Effect.Appear('slmail_tmp', { duration: 0.5 });

								isrunning_slmail = false;
							}

							else {

								new Effect.Shake('msg', { duration: 0.3 });
								window.setTimeout(function() { isrunning_slmail = false; }, 400);

							}


						}
					});

				}, 300);

			}

			return false;

		}

		if($('b_cancelslmail')) {

			$('b_cancelslmail').onclick = function() {

				return cancelslmail('');

			}

		}

	}

	if($('b_openslmailform')) {

		$('b_openslmailform').onclick = function() {

			openslmailsidebox();

			return false;

		}

	}



	// focus slmail textarea
	function setSelectionRange(input, selectionStart, selectionEnd) {
		if(input.createTextRange) {
			var range = input.createTextRange();
			range.collapse(true);
			range.moveEnd('character', selectionEnd);
			range.moveStart('character', selectionStart);
			range.select();
		}
		else if (input.setSelectionRange) {
			input.focus();
			input.setSelectionRange(selectionStart, selectionEnd);
		}
	}


	openslmailsidebox_running = false;
	openslmailsidebox = function() {

		if(!openslmailsidebox_running) {

			if(!$('sidebox_slmail').visible()) {

				openslmailsidebox_running = true;

				if($('b_openslmailform')) {
					$('b_openslmailform').hide();
				}

				if($('sidebox_allemitglieder')) {
					$('sidebox_allemitglieder').hide();
				}

				if($('sidebox_slmailoptions')) {
					$('sidebox_slmailoptions').hide();
				}

				new Effect.Appear('sidebox_slmail', { duration:0.5, afterFinish:function() {
					$('msg').focus();
					setSelectionRange($('msg'), 0, 0);
					openslmailsidebox_running = false;
				}});

			}

		}

	}



	cancelslmail = function(mode) {

		if(!isrunning_slmail) {

			if($('b_openslmailform')) {
				$('b_openslmailform').show();
			}

			if($('sidebox_slmail')) {
				$('sidebox_slmail').hide();
			}

			if($('sidebox_allemitglieder')) {
				$('sidebox_allemitglieder').appear({ duration:0.5 });
			}

			if($('sidebox_slmailoptions')) {
				$('sidebox_slmailoptions').appear({ duration:0.5 });
			}

			if(window.slmail_unhighlight) {
				slmail_unhighlight();
			}

			if(mode == 'regenerate') {
				if($('slmail_tmp')) {
					$('slmail_tmp').remove();
				}
				$('form_sidebox_slmail').getElementsByTagName('fieldset')[0].show();
			}

		}

		return false;

	}

















	/**
	*
	*	SLMAIL-BENACHRICHTIGUNG
	*
	**/

	slmail_blink = function() {

		if($('slmail_notifier')) {

			slmail_blink_fade = new Effect.Fade('slmail_notifier', { to:0.2, queue:'end', afterFinish:function() {
				slmail_blink_appear = new Effect.Appear('slmail_notifier', { to:0.9, queue:'end', afterFinish:function() {
					slmail_blink();
				}});
			}});

		}

	}

	slmail_unblink = function() {

		if(window.slmail_blink_fade) {
			slmail_blink_fade.cancel();
		}

		if(window.slmail_blink_appear) {
			slmail_blink_appear.cancel();
		}

		$('slmail_notifier').setStyle('opacity: 1;');

	}




















	/**
	*
	*	LISTENER (USER ONLINE + SLMAIL)
	*
	**/

	sl3listener = function() {

		new Ajax.Request('/', {
			parameters: 'source=default&action=sl3listener',
			onSuccess: function(t) {

				e = eval('('+t.responseText+')');

				// SLMAIL
				if(e.slmail_state == '1') {

					if(e.slmail_newmail == '1') {

						if(!$('slmail_notifier')) {
							new Insertion.Before('container', '<div id="slmail_notifier"><p><a href="/slmail/" onmouseover="slmail_unblink();" onmouseout="slmail_blink();"><span>'+e.slmail_sender+'</span></a></p></div>');
							slmail_blink();
						}

					}

					else {

						if($('slmail_notifier')) {
							$('slmail_notifier').remove();
						}

					}

				}

				// USER ONLINE
				if(e.useronline_state == '1') {

					$('whoisonline').innerHTML = e.useronline_html;

				}

			}
		});


	}

	sl3listener();
	sl3listenerInterval = window.setInterval(function() { sl3listener(); }, 15000);














	// msg box resize
	if($('msg')) {

		new Insertion.After('msg', '<div id="msgboxresize">&nbsp;</div>');
		Event.observe('msgboxresize', 'mousedown', msgBoxResizeStart);

	}








	var Browser = {
		detect: function() {
			var UA = navigator.userAgent;
			this.isKHTML = /Konqueror|Safari|KHTML/.test(UA);
			this.isGecko = (/Gecko/.test(UA) && !this.isKHTML);
			this.isOpera = /Opera/.test(UA);
			this.isMSIE = (/MSIE/.test(UA) && !this.isOpera);
			this.isMSIE7 = this.isMSIE && !(/MSIE 6\./.test(UA) && !this.isOpera);
			this.isMSIE6 = this.isMSIE && !this.isMSIE7;
		}
	}
	Browser.detect();






	/**
	*
	*	FIREBUG?
	*
	**/

	if(window.console && $('footer_nav') && Browser.isGecko) {
		new Insertion.After('footer_nav', '<p id="footer_firebug"><span>Achtung</span> Bei aktiviertem Firebug-Addon k&ouml;nnen technische Probleme auf dieser Seite auftreten.</p>');
	}









});








	// msg box resize
	initPointerY = false;
	msgBoxResizeStart = function(e) {

		msgBoxCurHeight = $('msg').getHeight()-(parseInt($('msg').getStyle('padding-top'))+parseInt($('msg').getStyle('padding-bottom')));
		msgBoxResize_dragging = true;
		initPointerY = e.pointerY();

		Event.observe(document, 'mousemove', msgBoxResizeDrag);
		Event.observe(document, 'mouseup', msgBoxResizeEnd);

	}

	msgBoxResizeDrag = function(e) {

		dragPointerY = e.pointerY();
		dragDistance = dragPointerY - initPointerY;
		msgBoxNewHeight = (msgBoxCurHeight+dragDistance);

		if(msgBoxNewHeight > 100 && msgBoxNewHeight < 400) {
			$('msg').setStyle('height: '+msgBoxNewHeight+'px;');
		}

	}

	msgBoxResizeEnd = function(e) {

		resizeObj = ($('forum_form_addedit')) ? 'forum' : 'slmail';

		new Ajax.Request('/', {
			parameters: 'source=default&action=msgboxresize&value='+($('msg').getHeight()-(parseInt($('msg').getStyle('padding-top'))+parseInt($('msg').getStyle('padding-bottom'))))+'&object='+resizeObj
		});

		Event.stopObserving(document, 'mousemove', msgBoxResizeDrag);
		Event.stopObserving(document, 'mouseup', msgBoxResizeEnd);

	}














	/**
	*
	*	DIVERSES
	*
	**/

	_scrollEffect = false;
	_scrollDown = function(duration) {
		if(_scrollEffect) { _scrollEffect.cancel(); }
		_scrollEffect = new Effect.ScrollTo('footer', { offset: -(document.viewport.getHeight()-180), transition: Effect.Transitions.Cubic, duration: duration });
	}

	_scrollTop = function() {
		if(_scrollEffect) { _scrollEffect.cancel(); }
		_scrollEffect = new Effect.ScrollTo('container', { transition: Effect.Transitions.Cubic, duration: 0.4 });
	}