// $ UI Datepicker
$(function($) {
	$.datepicker.regional['de'] = {
		prevText:        'zurück',
		nextText:        'weiter',
		monthNames:      ['Jänner','Februar','März','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember'],
		dayNames:        ['Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag'],
		dayNamesMin:     ['So','Mo','Di','Mi','Do','Fr','Sa'],
		firstDay:        1,
		buttonText:      'Kalender',
		isRTL:           false
	};
	$.datepicker.regional['en'] = {
		buttonText:      'Calendar'
	};
	$.datepicker.regional['fr'] = {
		prevText:        'préc',
		nextText:        'suiv',
		monthNames:      ['Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Août','Septembre','Octobre','Novembre','Décembre'], 
		dayNames:        ['Dimanche','Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi'], 
		dayNamesMin:     ['Di','Lu','Ma','Me','Je','Ve','Sa'],
		firstDay:        0,
		buttonText:      'Calendrier',
		isRTL:           false
	};
	$.datepicker.regional['it'] = {
		prevText:        'prec',
		nextText:        'succ',
		monthNames:      ['Gennaio','Febbraio','Marzo','Aprile','Maggio','Giugno','Luglio','Agosto','Settembre','Ottobre','Novembre','Dicembre'], 
		dayNames:        ['Domenica','Lunedì','Martedì','Mercoledì','Giovedì','Venerdì','Sabato'], 
		dayNamesMin:     ['Do','Lu','Ma','Me','Gi','Ve','Sa'], 
		firstDay:        1,
		buttonText:      'Calendario',
		isRTL:           false
	};
	$.datepicker.setDefaults($.datepicker.regional[$('html').attr('lang')]);
	$.datepicker.setDefaults({
		buttonImage:     '/fileadmin/template/img/icons/datepicker.png',
		buttonImageOnly: true,
		dateFormat:      'yy-mm-dd', // ISO 8601
		minDate:         '0y',
		showOn:          'both',
		showOtherMonths: true
	});
	
	function select_to_datepicker(prefix, min_date, bind_to) {
		if($('select[name="' + prefix + '_yyyy"], select[name="' + prefix + '_mm"], select[name="' + prefix + '_dd"]').length == 3) {
			$('select[name="' + prefix + '_yyyy"], select[name="' + prefix + '_mm"], select[name="' + prefix + '_dd"]').css({display: 'none'});
			$('select[name="' + prefix + '_yyyy"]').before('<input type="text" name="' + prefix + '" readonly="readonly" class="s25" />');
			$('input[name="' + prefix + '"]').val(
				$('select[name="' + prefix + '_yyyy"]').val() + '-' +
				$('select[name="' + prefix + '_mm"]'  ).val() + '-' +
				$('select[name="' + prefix + '_dd"]'  ).val()
			);
			
			// Wenn die select-Elemente keine Werte haben, wird das Textfeld wieder geleert.
			if ($('input[name="' + prefix + '"]').val() == '--') {
				$('input[name="' + prefix + '"]').val('');
			}
			$('input[name="' + prefix + '"]').datepicker({
				minDate: min_date,
				onSelect: function(dateText, inst) {
					var arr = dateText.split('-');
					$('select[name="' + prefix + '_yyyy"]').val(arr[0]);
					$('select[name="' + prefix + '_mm"]'  ).val(arr[1]);
					$('select[name="' + prefix + '_dd"]'  ).val(arr[2]);
					
					// Bei der Auswahl eines Anreisedatums wird der Picker des Abreisedatums auf eine Mindestauswahl von +1 Tag (86400000 Millisekunden) gesetzt.
					$('input[name="' + bind_to + '"]').datepicker(
						'option',
						$.extend({
							minDate: new Date(
								parseInt(
									Date.parse(
										$('input[name="' + prefix + '"]').datepicker('getDate')
									)
								)+86400000
							)
						})
					);
					
				}
			});
		}
	}
	
	select_to_datepicker('mf_datum_von', '+1d', 'mf_datum_bis');
	select_to_datepicker('mf_datum_bis', '+2d');
	select_to_datepicker('mf_datum', '+1d');
});

$(document).ready(function() {
	$.ajax({
		type: 'GET',
		url: window.location.href,
		data: 'type=71629',
		dataType: 'xml',
		success: function(xml) {
			$(xml).find('media>img').each(
				function() {
					$('<img />')
						.attr('src',    $(this).attr('src'   ))
						.attr('width',  $(this).attr('width' ))
						.attr('height', $(this).attr('height'))
						.attr('alt',    $(this).attr('alt'   ))
						.attr('title',  $(this).attr('title' ))
						.load(function(){
							// static: new images will be appended to the bottom of the list
							$('#media').append($(this));
							// random: new images will be added randomly to the list 
							// $('#media>img:nth-child(' + Math.ceil(Math.random() * $('#media>img').length) + ')').after($(this));
							$('#media').cycle(
								{
									fx:     'fade',
									timeout: 4000,
									speed:   2500,
									random:  0      // does not work with with $.cycle.lite.min.js
									                // but we don't care, because the preloading would mix up and brake the slideshow anyways
								}
							);
						});
				}
			);
		}
	});
	$('a.highslide').append('<span class="zoom" />');
	
	
});

/*
$(document).ready(function() {
	$('body').toggle(
		function() { $(this).css('font-size', '14px'); },
		function() { $(this).css('font-size', '16px'); },
		function() { $(this).css('font-size', '12px'); }
	);
});
*/

jQuery(document).ready(function() {
	
	jQuery('body.home #col3').append('<div class="scroller" /><ul class="controls" />');
	jQuery('body.home #col3 .section:not(:first-child)').appendTo('body.home #col3 .scroller');
	
	jQuery('body.home #col3 .scroller .section:nth-child(3n-2)').each(
		function() {
			jQuery(this).wrap('<div class="sectiongroup" />');
			jQuery(this).parent().next().appendTo(jQuery(this).parent());
			jQuery(this).parent().next().appendTo(jQuery(this).parent());
		}
	);
	
	for (var i = 1; i <= jQuery('body.home #col3 .scroller .sectiongroup').length ; i++) {
		jQuery('body.home #col3 .controls').append('<li />');
	}
	
	jQuery('body.home #col3 .controls>li').bind(
		'click',
		function() {
			jQuery('body.home #col3 .scroller').cycle(jQuery(this).index()).cycle('pause');
		}
	);
	
	jQuery('body.home #col3 .scroller').cycle({
		fx:      'scrollHorz',
		timeout: 8000,
		speed:   333,
		before:  function(currSlideElement, nextSlideElement, options, forwardFlag) {
			jQuery('body.home #col3 .controls>li').removeClass('cur');
			jQuery('body.home #col3 .controls>li:eq(' + jQuery(nextSlideElement).index() + ')').addClass('cur');
		}
	});
	
	
	jQuery('body.home #col0 div:eq(0)').append('<div class="scroller" /><ul class="controls" />');
	jQuery('body.home #col0 .section:not(:first-child)').appendTo('body.home #col0 .scroller');
	
	
	for (var i = 1; i <= jQuery('body.home #col0 .scroller .section').length ; i++) {
		jQuery('body.home #col0 .controls').append('<li />');
	}
	
	jQuery('body.home #col0 .controls>li').bind(
		'click',
		function() {
			jQuery('body.home #col0 .scroller').cycle(jQuery(this).index()).cycle('pause');
		}
	);
	
	jQuery('body.home #col0 .scroller').cycle({
		fx:      'fade',
		timeout: 8000,
		speed:   333,
		before:  function(currSlideElement, nextSlideElement, options, forwardFlag) {
			jQuery('body.home #col0 .controls>li').removeClass('cur');
			jQuery('body.home #col0 .controls>li:eq(' + jQuery(nextSlideElement).index() + ')').addClass('cur');
		}
	});
	

	$("#facebook").mouseover(function() {
    $("#facebook").animate({"top": "-=14px"}, "fast")}).mouseout(function(){
    $("#facebook").animate({"top": "+=14px"}, "fast")});
	
	/*$("#facebook").mouseover(function() {
    $("#facebook").css({"top": "31px"})}).mouseout(function(){
    $("#facebook").css({"top": "45px"})});*/
});
