$(document).ready(function(){
	$("a[rel^='prettyPhoto']").prettyPhoto({
		show_title: false,
		allow_resize: false,
	});
	
	$("#dialog-login").dialog({
		autoOpen: false,
		width: 600,
		resizable: false,
		modal: true,
		buttons: {
			'Anmelden': function() {
				$.ajax({
					type: 'POST',
					url: 'content/ajax.php',
					data: {
						Command: 'login',
						Username: $('#username').val(),
						Password: $('#password').val(),
					},
					success: function(data, textStatus, XMLHttpRequest) {
						location.reload();
					},
					dataType: 'json'
				});

				$(this).dialog('close');
			},
			'Abbrechen': function() {
				$(this).dialog('close');
			}
		}
	});

	$("#dialog-logout").dialog({
		autoOpen: false,
		width: 600,
		resizable: false,
		modal: true,
		buttons: {
			'Abmelden': function() {
				$.ajax({
					type: 'POST',
					url: 'content/ajax.php',
					data: {
						Command: 'logout',
					},
					success: function(data, textStatus, XMLHttpRequest) {
						location.reload();
					},
					dataType: 'json'
				});

				$(this).dialog('close');
			},
			'Abbrechen': function() {
				$(this).dialog('close');
			}
		}
	});
	
	$('#user a').click(function(e) {
		e.preventDefault();
		if ($('#user a').html() == 'Gast')
		{
			$('#dialog-login').dialog('open');
		}
		else
		{
			$('#dialog-logout .username').html($('#user a').html());
			$('#dialog-logout').dialog('open');
		}
	});
	
});

