<script>
	(function(window, $, undefined) {

		// EasyConfirm
		$('[data-help-confirm]').click(function() {
			return confirm($(this).data('help-confirm'));
		});

		$('.redactor').redactor({
			focus: true,
			autoresize: true,
			fixedbox: true,
			imageUpload: {link redactorImageUpload!},
			fileUpload: {link redactorFileUpload!},
			lang: 'cs',
			minHeight: 350
		});

	})(window, window.jQuery);

	function searchTypeahead(typeData)
	{
		var $inputSearch = $('.form-search .search-query'),
			$inputTag = $('.form-search .search-tag');

		$inputSearch.typeahead({
			source: function (query, process) {
				items = [];
				map = {};

				$.each(typeData, function(i, item) {
					map[item.name] = item;
					items.push(item.name);
				});

				process(items);
			},
			updater: function(item) {
				console.log(item);
				$inputTag.val(1);
				$inputSearch.val(item);
				$inputSearch.parents('form').submit();
				return item;
			}
		});
	}

	function tagTypeahead(typeData, defaultData)
	{
		var $tagInput = $('.form-article .article-tag');

		if (typeof typeData !== 'undefined' && typeData.length !== 0) {

			$tagInput.tagsinput({
				typeahead: {
					source: typeData
				},
				freeInput: true
			});

		}

		if (typeof defaultData !== 'undefined' && defaultData.length !== 0) {

			for (key in defaultData) {
				$tagInput.tagsinput('add', defaultData[key]);
			}

		}
	}
</script>
