$(document).ready(function() {
	$('#footer').prepend('<a href="#footer" onclick="window.print();" class="print">Inhalte drucken</a>');

	 $(document).SearchHighlight({
		 exact: 'partial',
         highlight: $('#content'),
         style_name: 'search-term',
         style_name_suffix: false,
         engines: [new RegExp('http:\/\/' + window.location.host,'i'),/suchbegriff=([^&]+)/i]
	 });

	$('.fx-select-autosubmit').each(function() {
		var select = $(this);
		var form = select.closest('form');
		form.find('input[type="submit"]').hide();
		select.change(function() {
			form.submit();
		});
	});

	$('.targeting-list').each(function() {
		$(this).find('li').addClass('targeting hoverable');
		$(this).find('li:first').addClass('targeting-list-first');
	});

	$('.fx-tabs').tabs({
		select: function(event, ui) {
			document.location.hash = $(ui.tab).attr('href').substr(1);
		}
	}).find('.fx-tab-heading').css({
		textIndent: '-9999px',
		height: '1px'
	});

	if (document.location.hash)
		$('.fx-tabs').find('a[href="' + document.location.hash + '"').click();


	$('.fx-link-selection').each(function(index) {
		var stage = $(this);
		stage.find('*').hide();
		var title = stage.find('.fx-link-selection-title').text();
		var lis = stage.find('li');

		var id = 'link-selection-' + index;
		stage.append('<label for="' + id + '" class="h3">' + title + '</label>');
		var selection = stage.append('<select id="' + id + '"></select>').children(':last');

		lis.each(function() {
			var li = $(this);
			var option = selection.append('<option>' + li.text() + '</option>').children(':last');
			var url = li.find('a:first').attr('href');
			if (url) {
				option.data('url', url);
			} else {
				option.attr('selected', 'selected');
			}
		});

		selection.change(function() {
			var selectedOption = selection.find('option:selected');
			if (selectedOption.data('url')) {
				document.location.replace(selectedOption.data('url'));
			}
		});
	});
});

