$().ready(function(){
	// general suckerfish exceptions
		// set active tab via url hash if active class was not set
		var list_items = $('#navi > ul > li');
		if (list_items.filter('.active').length == 0) {
			var hash = parseInt(location.hash.substr(1));
			if (list_items.eq(hash).length == 0) hash = 0;
			list_items.eq(hash).addClass('active');
		}
		
		// 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');
	
	// subpage suckerfish exceptions
		// suppress open of second level
		$('body:not(.homepage):not(.country) #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, body.country #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',
		accordion: true
	});
	
	// tabs
	$('.tabs').accessibleTabs({
		'tabhead': 'h2',
		'tabbody': '> div.content > div',
		'fxspeed': 0
	});

	// tooltip
	$('#body').tooltip('a[data-tooltip],span[data-tooltip]');

	// 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
	});
});

$(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();
			});
	
});
