	$(function() {
		$('a[rel=lb]').lightBox({
			maxHeight: 500,
			maxWidth: 700
		});
	});
	
		$('a[rel=lb]').live('click', function(e){
			e.preventDefault();
			$(this).lightBox({
				maxHeight: 500,
				maxWidth: 700
			}); 
		});	
	

	
	
	$(document).ready(function() {

	
	// ##############################################################
	// ORT
	$('form.register input[name=plz]').live('keyup', function() {
		
		if($(this).val().length > 2) {
			$.post('core/ajax.inc.php', {
					action:		'ort',
					plz:		$(this).val()
				},
				function(data) {
					if(data.success) {
						$('form.register #ort').show();
						$('form.register #ort').html(data.ort);
					} else {
						$('form.register #ort').hide();
					}

				}, 'json'
			);
			return false;
		}

	});


	// ##############################################################
	// USERNAME check (register)
	$('.register input[name=username]').live('change', function() {

		$.post('core/ajax.inc.php', {
				action:		'usercheck',
				value:		$(this).val()
			},
			function(data) {
				if(data.success) {
					$('.register div#usercheck').html('<b style="color:green;">Benutzername noch frei</b>');
				} else {
					$('.register input[name=username]').val('');
					$('.register div#usercheck').html('<b style="color:red;">Username bereits vergeben</b>');
				}

			}, 'json'
		);
		return false;

	});

	// ##############################################################
	// EMAIL check (register)
	$('.register input[name=email]').live('change', function() {

		$.post('core/ajax.inc.php', {
				action:		'emailcheck',
				value:		$(this).val()
			},
			function(data) {
				if(data.success) {
					$('.register div#emailcheck').html('');
				} else {
					$('.register input[name=email]').val('');
					$('.register div#emailcheck').html('<b style="color:red;">E-Mail bereits im System registriert.</b>');
				}

			}, 'json'
		);
		return false;

	});

	// ##############################################################
	// CHRONIK
	$('ul#chronik a.show').click(function() {
		/*
		$('ul#chronik table.chronik').hide();
		$('ul#chronik a.show').text('Chronik anzeigen');
		$('ul#chronik a.show').attr('status', '');
		
		if($(this).attr('status') == 'on') {
			$('ul#chronik table#'+$(this).attr('rel')).fadeOut();
			$(this).text('Chronik einblenden');
			$(this).attr('status', '');
		} else {
			$('ul#chronik table#'+$(this).attr('rel')).fadeIn();
			$(this).text('Chronik ausblenden');
			$(this).attr('status', 'on');
		}
		*/
		$('ul#chronik table#'+$(this).attr('rel')).toggle();

		return false;
	});
	
	// ##############################################################
	// 
	var $j = jQuery;
	$j.fn.extend({
		toggleValue : function (defaultText) {
			return this.each(function() {
				$j(this).focus(function() {
					if ($j(this).val() == defaultText) {
						$j(this).val('');
					}
					$j(this).blur(function () {
						if ($j.trim($j(this).val()) == '') {
							$j(this).val(defaultText);
						}
					});
				});
			});
		}
	});

	// $j('input[name=username]').toggleValue('Benutzername');
	// $j('input[name=password]').toggleValue('Passwort');

	$j('input.username').toggleValue('Benutzername');
	$j('input.password').toggleValue('Passwort');

	// ###############################################################
	// LOGIN/LOGOUT - CHECK
		
		function checkLogin() {

			$.post('core/ajax.inc.php', {
				action:		'activity'
			},
				function(data) {
					if(data.success) {
						if(data.timeout) {
							location.href="login.php?logout";
						}
					} else {
						
					}

				}, 'json'
			);
			return false;

			// $('#checkLogin').text('0');
		};

	    setInterval(function() {
          checkLogin();
		}, 30000);

}); // document
