function selectAll(chkbox) {
	if (chkbox.checked) {
		$('input[type=checkbox]').attr('checked', true);
	} else {
		$('input[type=checkbox]').attr('checked', false);
	}
	
}

function selectTags(elem) {
	// get select from server
	$.post(baseUrl + '/admin/tags/json', {tags : $('input#tags', elem.parentNode).val()}, function (data) {
		if (data.error) {
			alert(data.errorMessage);
		} else {
			$tagsDialog = $(data.tags).dialog({
				modal: true,
				autoOpen : true,
				title : 'Seznam tagů',
				close : function () {
					tagsSelected(true);
				},
				buttons: {
					'Vybrat' : function () {
						tagsSelected();
					}
				}
			});
		}
	}, 'json');
}

function tagsSelected(close) {
	var list = '';
	var prvni = true;
	
	// get list of selected tags
	$('div#tags-select input[type=checkbox]').each(function () {
		if (this.checked)
			list += this.value + ',';
			
	});
	
	// remove dialog
	$tagsDialog.remove();
	
	if (close)
		return;
	
	list = list.substr(0, list.length - 1);
	
	$('input#tags').val(list);
	
}

function slideshowZmena(cesta) {
	$('div#slideshow-preview img').fadeOut('normal', function () {
		$('div#slideshow-preview img').load(function () {
			$('div#slideshow-preview img').fadeIn('slow');
		}).attr('src', cesta);
	});
}

function alertMessage(message) {
	var $dialog = $('<div style="text-align:left;">' + message + '</div>').dialog({
		modal: true,
		autoOpen : true,
		title : 'Oznámení',
		buttons: {
			'Zavřít' : function () {
				$dialog.remove();
			}
		}
	});
}
