
function dodajEtykiete(galeria, foto)
{
	if (confirm('Dodaj etykietkę ze swoim nickiem.\nKliknij w miejscu w którym pojawiasz się na zdjęciu.'))
	{
		$('div.Foto img').wrap('<a style="cursor:crosshair;" href="foto.php?galeria='+galeria+'&foto='+foto+'&pozycja="></a>');
	}
}

function wyswietlWszystkie(profil)
{
	$.ajax({
		type: 'POST',
		url: 'profile.ajax.php',
		data: { akcja: 'wyswietl wszystkie', profil: profil },
		beforeSend:	function() {
			$('div#wyswietlWszystkie button').attr('disabled', 'disabled');
		},
		success: function(response) {
			$('div#wyswietlWszystkie button').remove();
			$('div#wyswietlWszystkie').append(response);
		}
	});
}

function dodajPosta(temat)
{
	var tresc = $('textarea#nowyPost').val();
	if (tresc != '')
	{
		$.ajax({
			type:	'POST',
			url:	'temat.ajax.php',
			data:	{ akcja: 'nowy post', temat: temat, tresc: tresc },
			beforeSend: function() {
				$('li.nowyPost textarea, li.nowyPost button.dodaj').attr('disabled', 'disabled');
			},
			success:	function(response) {
				$('li.nowyPost').replaceWith(response);
			}
		});
	}
}

function edytujPosta(post)
{
	var guzik = $('li#post' + post + ' button.edytuj');
	var tresc = $('li#post' + post + ' div.tresc');

	if ( $(guzik).text() == ' edytuj' )
	{
		$.ajax({
			type:	'POST',
			url:	'temat.ajax.php',
			data:	{ akcja: 'edycja start', post: post },
			beforeSend:	function() {
				$(guzik).attr('disabled', 'disabled');
			},
			success:	function(response) {
				$(guzik).attr('disabled', '');
				var height = $(tresc).height();
				if (height < 200) height = 200;
				$(tresc).empty().append('<textarea>'+response+'</textarea>').find('textarea').css('height', height+'px');
				$(guzik).html('<img src="layout/ikonki/accept.png" alt="" /> zapisz edycję');
			}
		});

	} else {

		if ( $(tresc).find('textarea').val() != '' )
		{
			$.ajax({
				type:	'POST',
				url:	'temat.ajax.php',
				data:	{ akcja: 'edycja zapisz', post: post, tresc: $(tresc).find('textarea').val() },
				beforeSend:	function() {
					$(guzik).attr('disabled', 'disabled');
				},
				success:	function(response) {
					$(tresc).html(response);
					$(guzik).html('<img src="layout/ikonki/comment_edit.png" alt="" /> edytuj').attr('disabled', '');
				}
			});

		} else alert('Brak tekstu.');
	}
}

function usunPosta(post)
{
	var guzik = $('li#post' + post + ' button.usun');
	
	if (confirm('Na pewno usunąć?'))
	{
		$.ajax({
			type:	'POST',
			url:	'temat.ajax.php',
			data:	{ akcja: 'usun posta', post: post },
			beforeSend:	function() {
				$(guzik).attr('disabled', 'disabled');
			},
			success:	function() {
				$('li#post'+post).slideUp().remove();
			}
		});
	}
}

function przeniesPosta(post)
{
	var guzik = $('li#post' + post + ' button.przenies');

	if ( $(guzik).text() == ' przenieś' )
	{
		$.ajax({
			type:	'POST',
			url:	'temat.ajax.php',
			data:	{ akcja: 'przenies', post: post },
			beforeSend:	function() { $(guzik).attr('disabled', 'disabled'); },
			success:	function(response) { 
				$(guzik).attr('disabled', '').html('<img src="layout/ikonki/bullet_go.png" alt="" /> nie przenoś');
			}
		});

	} else {

		$.ajax({
			type:	'POST',
			url:	'temat.ajax.php',
			data:	{ akcja: 'nie przenos', post: post },
			beforeSend:	function() { $(guzik).attr('disabled', 'disabled'); },
			success:	function(response) {
				$(guzik).attr('disabled', '').html('<img src="layout/ikonki/bullet_go.png" alt="" /> przenieś');
			}
		});
	}
}

function showBBCode()
{
	var width = 450;
	var height = 500;
	var left = (screen.width - width) / 2;
    var top = (screen.height - height) / 2;
	window.open('bbcode.php', '', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width='+width+',height='+height+',left='+left+',top='+top);
}

function zmienFilm(nr)
{
	$('ul.GlownaFilmy li').hide();
	$('ul.GlownaFilmy li#film'+nr).show();
	$('h2.najnowszeFilmy a').removeClass('active');
	$('h2.najnowszeFilmy a:eq('+(3 - nr)+')').addClass('active');
}