// $ 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/16x16/calendar.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() {
	// wrap span-Element into a.button
	$('a.button:not(:has(input))').wrapInner('<span />');
	
	// zoom icon für Bilder
	$('#col0 .csc-textpic-imagewrap a ').append('<span class="image_zoom" />');
	
	// lib.MEDIA
	$('#media').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:   1200,
										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
										next:   '#media_controls .next',
    									prev:   '#media_controls .prev'
									}
								);
							});
					}
				);
			}
		});
	});
	$('#media').parent().append('<ul id="media_controls"><li class="prev"><a href="#">‹</a></li><li class="next"><a href="#">›</a></li></ul>');
	
	
	
});


$(document).ready(function() {
	$('body.layout1 #col2').append('<div class="scroller" />');
	$('body.layout1 #controls2').append('<ul class="controls2"><li class="prev"><a href="#">‹</a></li><li class="next"><a href="#">‹</a></li></ul>');
	$('body.layout1 #col2 .section').appendTo('body.layout1 #col2 .scroller');
	$('body.layout1 #col2 .scroller').cycle(
		{
			cleartypeNoBg: true,
			fx:     'fade',
			timeout: 4000,
			speed:   500,
			random:  0,
			pager: 'body.layout1 #col3',
			prev: 'body.layout1 #controls2 ul.controls2 li.prev a',
			next: 'body.layout1 #controls2 ul.controls2 li.next a',
			activePagerClass: 'cur',
			updateActivePagerLink: function(pager, currSlide, activePagerClass) { 

				$('.section', pager)
					.removeClass(activePagerClass) 
					.filter('.section:eq('+(currSlide)+')').addClass(activePagerClass); 
			}      
		}
	);
	
	$('body.layout1 #col3>.section').bind(
		'click',
		function() {
			$('body.layout1 #col3>.section:eq(' + jQuery(this).index() + ')')
			$('body.layout1 #col2 .scroller').cycle(jQuery(this).index()).cycle('pause');
		}
	);
});

$(document).ready(function() {	
	$('.mowisweather').append('<ul class="controls" />');
	$('.mowisweather ul:eq(0)').cycle(
		{
			cleartypeNoBg: true,
			fx:     'scrollHorz',
			timeout: 0,
			speed:    0,
			random:  0,
			pager: '.mowisweather .controls',
			pagerAnchorBuilder: function(index, slide) {
				var datum = ($('.mowisweather ul:eq(0) li:eq(' + index + ') .day span').html());
				// Achtung, funktioniert nicht für englisch (en), weil die Defaults nicht gelesen werden, sondern nur das abstrahierte Konfigurationsarray
				return '<li><a href="#"> ' + [datum] +  ' </a></li>';
			},
			activePagerClass: 'cur',
			updateActivePagerLink: function(pager, currSlide, activePagerClass) { 

				$('li', pager)
					.removeClass(activePagerClass) 
					.filter('li:eq('+(currSlide)+')').addClass(activePagerClass); 
			}      
		}
	);
	
	// Link und Wetterübersetzung
	$('#c114 .mowisweather').append ('<a href="/de/service-info/wetter/" class="weather">Zum 7-Tage Überblick</a>'); 		// de
	$('#c996 .mowisweather').append ('<a href="/en/service-info/weather/" class="weather">7-day forecast</a>'); 				// en
	$('#c1000 .mowisweather').append('<a href="/nl/service-info/weertje/" class="weather">7-dagen forecast</a>'); 			// nl
});

	//Sommer
    var vrHeight = 580;
    var vrWidth = 1000;

    function startVR(pano)
    {
        var vrLeft = ((screen.availWidth - vrWidth)/2);
        var vrTop = ((screen.availHeight - vrHeight)/2);
        window.open('/fileadmin/filzmooserhof-tour/html/de_sommer/filzmooser_' + pano + '.html', '360_degree_vrtour', 'width=' + vrWidth + ',height=' + vrHeight + ',top=' + vrTop + ',left=' + vrLeft + ',menubar=no,resizable=no, scrollbars=no, toolbar=no');
    }
	

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