function lib_HOME_slider() {
	var pages = Math.ceil(jQuery('#home #col0').children().length / 2);
	if (pages > 1) {
		var switcher = '<ul id="switcher">';
		for (var i = 1; i <= pages ; i++) {
			if (i == 1) {
				switcher += '<li id="switcher' + i + '" class="current">' + i + '</li>';
			} else {
				switcher += '<li id="switcher' + i + '">' + i + '</li>';
			}
		}
		switcher += '</ul>'
		jQuery('#container').append(switcher);
		jQuery('#col0').wrapInner('<div id="scroller"></div>');
		jQuery('#switcher li').bind(
			'click',
			function() {
				var index = jQuery('#switcher li').index(this);
				jQuery('#switcher li:eq(' + index + ')').addClass('current');
				jQuery('#switcher li:not(:eq(' + index + '))').removeClass('current');
				jQuery('#scroller').stop();
				jQuery('#scroller').animate({left: '-' + index*718 + 'px'}, 1000);
			}
		);
	}
}

function lib_TOP_closeme(me, you, b_me, b_you) {
	jQuery('#top').slideUp(
		300,
		function() {
			jQuery(me).css('display', 'none');
			jQuery(b_me).removeClass('current');
			jQuery(b_me).unbind('click');
			jQuery(b_me).bind(
				'click',
				function() {
					lib_TOP_openme(me, you, b_me, b_you);
					return false;
				}
			);
		}
	);
}

function lib_TOP_openme(me, you, b_me, b_you) {
	jQuery('#top').slideUp(
		300,
		function() {
			jQuery(you).css('display', 'none');
			jQuery(me).css('display', 'block');
			jQuery(b_me).addClass('current');
			jQuery(b_you).removeClass('current');
			jQuery('#top').css('height', jQuery(me).css('height'));
			jQuery('#top').slideDown(400);
			jQuery(b_me).unbind('click');
			jQuery(b_me).bind(
				'click',
				function() {
					lib_TOP_closeme(me, you, b_me, b_you);
					return false;
				}
			);
			jQuery(b_you).unbind('click');
			jQuery(b_you).bind(
				'click',
				function() {
					lib_TOP_openme(you, me, b_you, b_me);
					return false;
				}
			);
		}
	);
};

function lib_TOP() {
	// Höhe ermitteln
	jQuery('#quickanfrage').css('height', jQuery('#quickanfrage').height() + 'px');
	jQuery('#quicksitemap').css('height', jQuery('#quicksitemap').height() + 'px');
	// Elemente umhängen
	jQuery("#end>div").appendTo("#top"); 
	jQuery('#qbanfrage').bind(
		'click',
		function() {
			lib_TOP_openme('#quickanfrage', '#quicksitemap', '#qbanfrage', '#qbsitemap');
			return false;
		}
	);
	jQuery('#qbsitemap').bind(
		'click',
		function() {
			lib_TOP_openme('#quicksitemap', '#quickanfrage', '#qbsitemap', '#qbanfrage');
			return false;
		}
	);
};

function lib_SEARCH() {
	// S. Arnold 13.08.2009
	// Funktion zum Leeren und Befüllen des Suchfelds
	// Fake, da nur das label-Element im Hintergrund ein und ausgeblendet wird.
	jQuery('#search #q').bind(
		'click focus change',
		function() {
			jQuery('#search label').css('display', 'none');
		}
	);
	jQuery('#search #q').bind(
		'blur',
		function() {
			if (jQuery('#q').val() == '') { jQuery('#search label').css('display', 'block'); }
		}
	);
}

function lib_MEDIA() {
	jQuery('#media').cycle(
		{
			fx:     'fade',
			timeout: 4000,
			speed:   2500,
			random:  1
		}
	);
}


function lib_GO_WEST() {
	jQuery('#go_west span').hover(
		function () {
			jQuery(this).animate({ backgroundPosition: '88px top' }, 750, 'swing');
		},
		function () {
			jQuery(this).stop().animate({ backgroundPosition: '0px top' }, 750, 'swing');
		}
	);
}

jQuery(
	function($) {
		$.datepicker.regional['de'] = {
			closeText: 'schließen',
			prevText: 'zurück',
			nextText: 'weiter',
			currentText: 'heute',
			monthNames: ['Jänner','Februar','März','April','Mai','Juni',
			'Juli','August','September','Oktober','November','Dezember'],
			monthNamesShort: ['Jan','Feb','Mär','Apr','Mai','Jun',
			'Jul','Aug','Sep','Okt','Nov','Dez'],
			dayNames: ['Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag'],
			dayNamesShort: ['So','Mo','Di','Mi','Do','Fr','Sa'],
			dayNamesMin: ['So','Mo','Di','Mi','Do','Fr','Sa'],
			dateFormat: 'dd.mm.yy', firstDay: 1,
			buttonText: 'Kalender',
			isRTL: false
		};
		$.datepicker.regional['en'] = {
			buttonText: 'Calendar'
		};
		$.datepicker.setDefaults($.datepicker.regional[jQuery('html').attr('lang')]);
		$.datepicker.setDefaults({
			showOn: 'both',
			buttonImageOnly: true,
			buttonImage: '/fileadmin/template/img/icons/datepicker.png',
			minDate: '0y'
	 });

		
		// eigentliche Datepicker
		$('#qf_anreise').datepicker();
		$('#qf_abreise').datepicker();
		$('#mf_anreise').datepicker();
		$('#mf_abreise').datepicker();
	}
);

function zebra_tables() {
	jQuery('div.zebra table tr:nth-child(2n)').addClass('even');
	jQuery('div.zebra table tr').hover(
		function () {
			jQuery(this).addClass('hover');
		}, 
		function () {
			jQuery(this).removeClass('hover');
		}
	);
}

function calculator() {
	jQuery('#calculator').bind(
		'click',
		function() {
			window.open(jQuery(this).attr('href'), 'Skipasskalkulator', 'width=570,height=600,status=yes,scrollbars=yes,resizable=yes');
			return false;
		}
	);
}

jQuery(document).ready(
	function() {
		lib_TOP();
		lib_SEARCH();
		lib_MEDIA();
		lib_HOME_slider();
		lib_GO_WEST();
		zebra_tables();
		calculator();
		jQuery('#quicksitemap h3').addClass('sitemap');
	}
);