if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
	var is_iOS = true;
} else {
	var is_iOS = false;
}

// $ 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() {
	var input = $('#search input#q');
	var label = $('#search label');
	input.bind(
		'click focus change',
		function() {
			label.css('visibility', 'hidden');
		}
	);
	input.bind(
		'blur',
		function() {
			if (input.val() == '') {
				label.css('visibility', '');
			}
		}
	);
});


$(document).ready(function() {
	$('#quickinfo span.toggle').toggle(
		function() {
			$('#after').animate(
				{
					height: '320px'
				}
			);
			$(this).css('background-position', '0 -39px');
		},
		function() {
			$('#after').animate(
				{
					height: '0'
				}
			);
			$(this).css('background-position', '0 0');
		}
	);

});

$(document).ready(function() {
	// wrap span-Element into a.button
	$('a.button:not(:has(input))').wrapInner('<span />');
	
	$('.frame, #menu2').append('<div class="after" />');
	
	// 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:   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
									}
								);
							});
					}
				);
			}
		});
	});
});

$(document).ready(function() {

$('.home #col0 .section').wrapAll('<div class="scrollbody" />');
$('.home #col0').append('<ul class="controls" />');
$('.home #col0 .scrollbody')
			.cycle(
				{
					cleartypeNoBg: true,
					fx:     'scrollHorz',
					timeout: 5000,
					speed:   250,
					random:  0,
					pager: '.home #col0 .controls',
					pagerAnchorBuilder: function(index, slide) {
						return '<li><a href="#">' + (index+1) + '</a></li>';
					},
					prev: '#teaser .prev',
					next: '#teaser .next',
					activePagerClass: 'cur',
					updateActivePagerLink: function(pager, currSlide, activePagerClass) { 
						$('li', pager)
							.removeClass(activePagerClass) 
							.filter('li:eq('+(currSlide)+')').addClass(activePagerClass); 
					}
				}
			);

	
	$('a.ajax, a.highslide').append('<span class="zoom" />');
	
	
	//Startseite Accordion
	
	//$('body.home #col2').append('<div class="accordion" />');
//	$('body.home #col2 .section:not(:first-child)').appendTo('body.home #col2 .accordion');
//	
//	
//	$('body.home #col2 .accordion .section:first-child').addClass('first-child');
//	
//	$('body.home #col2 .accordion .section').each(
//		function() {
//			 $('h4', this).insertBefore($('.csc-textpic', this)); 
//			 $('h4', this).append('<span class="state" />');
//			 
//		}
//	);
//
//	$('body.home #col2 .accordion .section:first-child>h4').addClass('cur');
//	
//	$('body.home #col2 .accordion .section:not(:first-child)>*:not(h4)').slideUp(250);
//	
//	$('body.home #col2 .accordion .section>h4:not(.cur)').live(
//		'click',
//		function() {
//			$('body.home #col2 .accordion .section h4').removeClass('cur');
//			$('body.home #col2 .accordion .section>*:not(h4)').slideUp(250);
//			$(this).addClass('cur');
//			$(this).parent().find('*:not(h4)').stop(true).slideDown(300);
//		}
//	);
	

	
	//Startseite Produkt Slider
	
	var scrollamount = 760;
	var productelements = $('#col4 .section');
	var maxposition = (productelements-6);
	var position = 0;
	
	
	$('.layout1 #col4').append('<div class="scroller"><div id="sliderbox"></div></div>');
	$('.layout1 #col4 .section').appendTo('.layout1 #col4 .scroller #sliderbox');
	
	if(productelements.length > 1) {
		$('.layout1 #col4')
			.append('<a id="slidePrev"/>')
			.append('<a id="slideNext"/>')
			.append('<div id="slider_mask_left"/>')
			.append('<div id="slider_mask_right"/>');
			
		window.setTimeout("myautoslide()", 4000);
	}
	

	$('.layout1 #col4>a#slideNext').bind(
		'click',
		function() {
			autoslideMe = false;
			if($('.layout1 #sliderbox').position().left == 0){
				$('.layout1 #sliderbox').animate({left: '-' + scrollamount + 'px'}, 500, 'easeInOutSine',
					function() {
						$(this)
							.css({left: '0px'})
							.find('.section:first-child').appendTo(' .layout1 #sliderbox');
					}
				);
			}
		}
	);
	
	$('.layout1 #col4>a#slidePrev').bind(
		'click',
		function() {
			autoslideMe = false;
			if($('#sliderbox').position().left == 0){
				$('#sliderbox').find('.section:last-child').prependTo('#sliderbox');
				$('#sliderbox').animate({left: '-' + scrollamount + 'px'}, 0, 'easeInOutSine',
						function() {
							$(this).animate({left: '0px'}, 500, 'easeInOutSine');
						}
					);
			}
		}
	);
	
	// Bildfading Startseite
	
	$(document).ready(function(){
		$('.home #col1 #c1589 a').hover(function() {
				$(this).stop(true).animate(
					{
						opacity:1	
					},
					550
				);
				$('.home #col1 #c1651 a').stop(true).animate(
					{
						opacity: .30		
					},
					550
				)
		});
		$('.home #col1 #c1651 a').hover(function() {
				$(this).stop(true).animate(
					{
						opacity:1	
					},
					550
				);
				$('.home #col1 #c1589 a').stop(true).animate(
					{
						opacity: .30		
					},
					550
				)
		});
		$('.home #col1 #c1589 a').mouseout(function() {
				$('.home #col1 #c1651 a').stop(true).animate(
					{
						opacity: 1		
					},
					250
				)
		});
		$('.home #col1 #c1651 a').mouseout(function() {
				$('.home #col1 #c1589 a').stop(true).animate(
					{
						opacity: 1		
					},
					250
				)
		});
	});
	
	
	//Flowplayer
	$('#videobox .video_player').each(function() {
		if (true) {
			image         = $(this).parent().find('ul .image').text();
			image_small   = $(this).parent().find('ul .image-small').text();
			video_width   = parseInt($(this).parent().find('ul .video-width').text());
			video_height  = parseInt($(this).parent().find('ul .video-height').text());
			video         = $(this).parent().find('ul .video').text();
			video_2       = $(this).parent().find('ul .video_2').text();
			
			$f(
				this,
				{
					src: '/fileadmin/template_schartner/js/flowplayer/flowplayer.commercial-3.2.4.swf',
					width: video_width,
					height: video_height,
					wmode: 'transparent'
				},
				{
					key: '#$f325b0e6b483220688d',
					logo: null,
					play: {
						url: '/fileadmin/template_schartner/img/bt_play_video.png',
						width: 168,
						height: 204
					},
					plugins: {
						controls: {
							borderRadius:         5,
							timeColor:            '#f27225',
							bufferGradient:       'none',
							slowForward:          true,
							backgroundColor:      'rgba(255, 255, 255, 0.8)',
							volumeSliderGradient: 'none',
							slowBackward:         false,
							timeBorderRadius:     20,
							progressGradient:     'none',
							time:                 false,
							height:               26,
							volumeColor:          '#f27225',
							tooltips: {
								marginBottom: 5,
								scrubber:     true,
								volume:       true,
								buttons:      false
							},
							fastBackward:      false,
							opacity:           1 ,
							timeFontSize:      12,
							bufferColor:       'rgba(255, 255, 255, 0.75)',
							border:            '0px',
							volumeSliderColor: '#f27225',
							buttonColor:       '#f27225',
							mute:              true,
							autoHide: {
								enabled:        true,
								hideDelay:      1500,
								hideStyle:      'fade',
								mouseOutDelay:  500,
								hideDuration:   400,
								fullscreenOnly: false
							},
							backgroundGradient:      'none',
							width:                   '460px',
							sliderBorder:            'none',
							sliderBorderWidth:       0,
							display:                 'block',
							buttonOverColor:         '#f27225',
							fullscreen:              false,
							timeBgColor:             'rgb(0, 0, 0, 0)',
							borderWidth:             0,
							bottom:                  '10px',
							stop:                    false,
							sliderColor:             'rgba(242, 114, 37, 0.5)',
							zIndex:                  1,
							scrubberHeightRatio:     0.5,
							scrubberBarHeightRatio:  0.125,
							volumeSliderHeightRatio: 0.5,
							volumeBarHeightRatio:    0.2,
							tooltipTextColor:        'rgba(70, 107, 140, 1)',
							sliderGradient:          'none',
							timeBgHeightRatio:       0.5,
							name:                    'controls',
							timeSeparator:           ' ',
							left:                    '10px',
							tooltipColor:            'rgba(255, 255, 255, 0.8)',
							playlist:                false,
							durationColor:           'rgba(255, 255, 255, 0.6)',
							play:                    true,
							fastForward:             true,
							timeBorder:              'none',
							progressColor:           '#f27225',
							scrubber:                true,
							volume:                  true,
							volumeBorder:            'none',
							builtIn:                 false
						}
					},
					playlist: [
						{ 
							url: (is_iOS ? video_2 : video),
							autoPlay: true,
							scaling: 'fit'
						}
					]
				}
			).ipad({simulateiDevice: false});
		}
	});
	
	//Alternative weil Flowplayer spinnt!
	if(is_iOS)
	{
		alternativVideo = $('#videobox').find('ul .video_2').text();
		//alert(alternativVideo);
		$('#videobox').empty();
		$('#videobox').append('<object width="480" height="270" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab"><param name="src" value="'+image+'" /><param name="href" value="'+alternativVideo+'" /><param name="target" value="myself" /><param name="controller" value="false" /><param name="autoplay" value="false" /><param name="scale" value="aspect" /><embed width="480" height="270" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/" src="'+image+'" href="'+alternativVideo+'" target="myself" controller="false" autoplay="false" scale="aspect"></embed></object>');
	}

});


// Autoslide(Timeout) Startseite Produkt Slider
var autoslideMe = true;

function myautoslide() {
	if(autoslideMe == true) {
		$('#col4>a#slideNext').trigger('click');
		window.setTimeout("myautoslide()", 4000);
		autoslideMe = true;
	}
}


function gmap2_after_initialize() {
	$('#media_outer .media_mask').css('display', 'none');
};


