$().ready(function(){
	// general suckerfish exceptions
		// give all main entries numbers so we can access them in css
		$('#navi > ul > li').each(function(i){
			$(this).addClass('number_'+i);
		});

		// add active class to parent elements to show the hover path
		$('#navi li').hover(function(){
			$(this).parents('li').addClass('pathhover');
			$(this).siblings().removeClass('pathhover');
		});

		// show subitems of active element on load
		$('#navi > ul > li.active > ul').addClass('show');

		// remove title tag from a in #navi
		$('#navi a').attr('title', '');

	// subpage suckerfish exceptions
		// suppress open of second level
		$('body:not(.homepage) #navi > ul > li:not(.active) > ul').addClass('hide');

		// show subitems of active element on load
		$('body:not(.homepage) #navi > ul > li.active > ul').addClass('show');

	// homepage suckerfish exceptions
		// suppress open of third level
		$('body.homepage #navi > ul > li > ul > li > ul').addClass('hide');

		$('body.homepage #navi > ul > li').mouseenter(function(){
			// mark this item as active so it does not close on mouseleave
			$(this)
				.addClass('active')
				.siblings().removeClass('active');

			$(this).parent().find('li > ul').removeClass('show');
			$('> ul', this).addClass('show');
		});


	// we must always have at least 6 navigation list items so the contact box is at the end
	var top_items = $('#navi > ul > li');
	top_items.last().before(Array(6 - top_items.length + 1).join('<li></li>'));
	// is the same as :)
	// for (var i = top_items.length; i < 6; i++) top_items.last().before('<li></li>');

	// zebra tables
	$('tr:nth-child(odd)').addClass('odd');

	// accordion
	$('.slider').slider({
		clickElement: 'h3.slideTrigger',
		slideElement: 'div.slideContent',
		activeClass: 'active1',
		accordion: false
	});

	// tabs
	$('.tabs').accessibleTabs({
		'tabhead': 'h2',
		'tabbody': '> div.content > div',
		'fxspeed': 0
	});

	// tooltip
	// $('#body').tooltip('a[data-tooltip],span[data-tooltip]');
	$('#body').tooltip('.tx-contagged-tooltipwrapper > a');

	// styled selectboxes
	$('select').selectbox({
		'changeWidth': 20,
		'minWidth': 180
	});

	// homepage: footer min-distance-to-top-fix
	$('body.homepage #fix').fixedfooter({
		minDistance: 678
	});

	// homepage: fullscreenimage
	$('body.homepage #navi > ul > li[data-fullscreenimage]').each(function(i){
		var $el = $(this);
		var bg_image = $el.attr('data-fullscreenimage');

		// set default image
		if (i == 0) $.setFullscreenImage(bg_image);

		// link background image to navi
		$(this).mouseenter(function(){
			$.setFullscreenImage(bg_image);
		});
	});

	// homepage: crossfade of news
	$('body.homepage div.js_crossfade').crossfade({
		crossfade: false,
		fadeDuration: 'fast',
		delay: 5000
	});

	// center slider
	$('.centerslide').centerslide({
		width: 300
	});

	// searchfield
	$('input.autoEmpty').focus(function (e) {
		var $this = $(this);
		if ($this.val() == $this.attr('title'))
			$this.val('');

		$this.removeClass('autoEmpty');

	});
	$('input.autoEmpty').blur(function (e) {
		var $this = $(this);
		if ($this.val() == '') {
			$this.val($this.attr('title'));
			$this.addClass('autoEmpty');
		}
	});

	$('input.autoEmpty').blur();

	// print
	$('#printLink').click(function(e) {
		e.preventDefault();
		window.print();
	});
	
});

$(window).load(function(){
	// general suckerfish exceptions
		// suckerfish dropdown: entries longer than one block should expand the first block to the length of two
		$('#navi li li a').each(function(){
			var $el = $(this);
			if ($el.height() > 20) {
				$el.parents('ul:first').addClass('wide');
			}
		});

		// suckerfish dropdown: the second level on the homepage is always double width
		$('body.homepage #navi > ul > li > ul').addClass('wide');

		// animate show of uls
		$('#navi li li:not(.active) ul').hide();
		$('#navi li li')
			.hover(function(){
				$('ul', this).fadeIn('fast');
			}, function(){
				$('ul', this).hide();
			});

});


