jQuery(document).ready(function() {
	try {
		document.execCommand("BackgroundImageCache", false, true);
	} catch(err) {}

	//IE PNG Fix
	jQuery(document).pngFix();

	//tt popup
	if(window.name == 'tui_details') {
		jQuery('#container').css({marginTop:'10px'});
		jQuery('#container, #header, #contentbox').css('width', '740px');
		jQuery('#contentwrap, #content, #footerwrap').css('width', '546px');
		jQuery('#topmenu, #header .logo, #selectmenu .clubselect, #rightcontentwrap, #footer, #copyright').css('display', 'none');
		jQuery('#header, #footerwrap').css('overflow', 'hidden');
		jQuery('#submenu li').each(function() {
			if(jQuery(this).find('a').text().toLowerCase() == 'online-katalog') {
				jQuery(this).css({overflow: 'hidden', width:'0', height:'0'});
			}
		});
		if(jQuery('#content .csc-frame-toverlay:eq(1)').length && jQuery('#rightcontent .csc-frame-gallery:eq(0)').length) {
			jQuery('#content .csc-frame-toverlay:eq(1)').after(jQuery('#rightcontent .csc-frame-gallery:eq(0)'))
			jQuery('#content .csc-frame-toverlay:eq(1)').css({display: 'none'});
		}
	}

	//tt popup
	if(window.name == 'popup') {
		// ausblenden
		jQuery('#outerLeft').css('display', 'none');
		jQuery('#subMenu').css('display', 'none');
		jQuery('#breadcrumb').css('display', 'none');
		jQuery('#stageHome').css('display', 'none');
		jQuery('#topMenu').css('display', 'none');
		jQuery('#footer').css('display', 'none');
	}

	//servicemenu
	servicemenuBuild();

	//submenu
    jQuery('#subMenu ul.secondline li:first-child').addClass('first');
	jQuery('#subMenu li').each(function() {
		var colorClass = jQuery(this).attr('class').match(/cc.*/g);
		if(colorClass) {
			jQuery(this).removeClass(colorClass[0]);
			jQuery(this).parent('ul').addClass(colorClass[0]);
		}
	})
	jQuery('#subMenu').contents().filter('ul').contents().filter('li').each(function(i) {
		jQuery(this).hover(function(e) {
			jQuery('.subSubmenu').stop().css('height', 'auto').hide();
			jQuery(this).addClass('active');
			jQuery(this).find('.subSubmenu').slideDown(function() {
				if(jQuery.browser.msie && !jQuery(this).find('.subsubmenuiframe').length) {
					jQuery(this).prepend('<iframe class="subsubmenuiframe" frameborder="0" scrolling="no"></iframe>');
					jQuery(this).find('.subsubmenuiframe').css({width:jQuery(this).width(), height:jQuery(this).height()})
				}
			});
		}, function() {
			jQuery('.subSubmenu').stop().css('height', 'auto').hide();
			jQuery(this).removeClass('active');
		});
	});

	//headermenu
	jQuery('#mainMenu').css('top', jQuery('#stage').height()-jQuery('#mainMenu').height());

	jQuery('#subMenu a').each(function(){
		if(jQuery(this).text() == 'Aktionen'){
			linkText = jQuery(this).text();
			jQuery(this).replaceWith('<span class="summer">' + linkText + '</span>');
			jQuery('.summer').siblings().addClass('summerActions');
		}
	});

	//tabmenu
	tabmenuBuild();

	// breadcrumb
	breadcrumbBuild();

	//teaserscroller
	scrollerReInit()

	//quicklinks
	quicklinksBuild();

	//countryinfos
	countryInfosBuild();

	//accordion
	jQuery('.accordion').each(function() {accordionBuild(jQuery(this))});
	jQuery('.accordionSmall').each(function() {accordionBuild(jQuery(this))});

	//searchhighlight
	highlightSearchKeyword();

	//headerfade
	if(jQuery('#page_2752').length) {
		jQuery('#stage').after('<div id="headerNavi"><div class="up"></div><div class="play"></div><div class="pause"></div><div class="down"></div></div>');
		jQuery('#stage').html('');
		headerFadeCache = new Array();
		headerFadeCurrent = 0;
		jQuery.get('index.php', {'id': 2641, 'tx_tuiheaderchanger_pi1[offset]': headerFadeCurrent, 'type': 100}, function(data){
			dataCount = data.match(/\|\|\|(.*?)\|\|\|/g)[0].replace(/\|\|\|/g, '');
			headerFadeCache[headerFadeCurrent] = data.replace(/\|\|\|(.*?)\|\|\|/g, '');
			headerFadeChange();
			headerFadeStart();
		});
		jQuery('#stageHome').css('background', '#fff');
	}

	//flashmap
	jQuery('.flashMap').each(function() {
		map = jQuery(this);
		map.prev('.neustateaserscrollermenu').find('a').each(function() {
			var href = jQuery(this).attr('href');
			jQuery(this).attr('href', 'javascript:void(0);');
			jQuery(this).click(function() {
				jQuery(this).parent('li').parent('ul').find('li').removeClass('active');
				jQuery(this).parent('li').addClass('active');
				if(map.find('object').length) {
					document[map.find('object').attr('id')].changeMap(href);
				} else {
					document[map.find('embed').attr('name')].changeMap(href);
				}
			});
		});
	});

	//vacationcalendar
	vacationCalendarBuild();

	//fly&more search
	flyMoreQuickSearchBuild();

	jQuery('.tx-tuisearch-pi1 #lf_origin').autocomplete('/index.php?eID=tx_tuiflightlist_ajax&sec=0', {minChars: 3});
	jQuery('.tx-tuisearch-pi1 #lf_destination').autocomplete('/index.php?eID=tx_tuiflightlist_ajax&sec=1', {minChars: 3});

	jQuery('.tx-tuisearch-pi1 input[name=flextime]:checked').click();
	jQuery('.tx-tuisearch-pi1 input[name=trip_type]:checked').click();

	//fly&more submenu
	jQuery('#flySubMenu ul li').each(function() {
		jQuery(this).bind('mouseover', function() {
			if(jQuery(this).find('ul').length) {
				jQuery(this).find('a:first').addClass('hover');
				jQuery(this).find('ul').show();
			}
		});
		jQuery(this).bind('mouseout', function() {
			if(jQuery(this).find('ul').length) {
				jQuery(this).find('a:first').removeClass('hover');
				jQuery(this).find('ul').hide();
			}
		});
	});

	//blackoverlays
	blackOverlayBuild();

	//tooltip
	jQuery('.tooltipInfo').click(function() {
		tooltip = jQuery(this).parents('.tooltip').length ? jQuery(this).parents('.tooltip') : jQuery(this).parent().next('.tooltip');
		if (tooltip.css('display') == 'none') {
			tooltip.css({'left': jQuery(this).position().left + jQuery(this).width()+10, 'top': jQuery(this).position().top});
			tooltip.show(500);
		} else {
			tooltip.hide(500);
		}
	});

	// checking strings in searchbox for seasons
	if(jQuery('#offlineSearchInput').length > 0){
		var searchValue = jQuery('#offlineSearchInput').val();
		if(searchValue.indexOf('Winter 2008') != -1){
			jQuery('#sommer2009').removeAttr('checked');
		}else if(searchValue.indexOf('Sommer 2009') != -1){
			jQuery('#winter2008').removeAttr('checked');
		}
	}

	//offlinesearch
	jQuery('.osrlTeaserSeasonCheck').click(function() {
		selBox = jQuery(this);
		jQuery('.osrlTeaserSeasonCheck').each(function(){
			if(jQuery(this).attr('id') != selBox.attr('id')) {
				jQuery(this).attr('checked', 'checked');
			}
			jQuery('#offlineSearchInput').val(jQuery('#offlineSearchInput').val().replace(new RegExp(',?\\s?' + jQuery.trim(jQuery(this).parent().find('label').text())), ''));
		}).each(function(){
			if(jQuery(this).is(':checked') && jQuery('.osrlTeaserSeasonCheck:checked').length < 2) {
				searchValue = jQuery('#offlineSearchInput').val();
				if(!searchValue){
					jQuery('#offlineSearchInput').val(jQuery('#offlineSearchInput').val() + jQuery.trim(jQuery(this).parent().find('label').text()));
				} else {
					jQuery('#offlineSearchInput').val(jQuery('#offlineSearchInput').val() + ', ' + jQuery.trim(jQuery(this).parent().find('label').text()));
				}
			}
		});
		jQuery('#offlineSearch form').submit();
	});

	// set Season Dates
	setSeasonDate();

	//leftheight
	setLeftHeight();

	setTimeout(function() {
		jQuery('.contenttable tr').each(function() {
			if(jQuery(this).find('.price, .priceTop, .priceBottom').length) {
				jQuery(this).css('cursor', 'pointer');
				jQuery(this).click(function() {
					window.location.href = jQuery(this).find('a:last').attr('href');
				});
			}
		});
	}, 2000)

	golfStartTimeReservationForm();

	//jQuery('#pid4205 a').attr('href','http://ww2.tui.ch/booking/tui_ch/index.php?KID=792500&formular=4&engine=pauschal&personen=25;25;');
	//jQuery('#pid4208 a').attr('href','http://ww2.tui.ch/booking/tui_ch/index.php?KID=792500&formular=4&showresult=1&detail=zielgebiet&abflughafen=ZRH,BSL,GVA&personen=25;25;');
});

/******************/
/*  servicemenu  */
/****************/
function servicemenuBuild() {
	jQuery('#triggerService').append(jQuery('#triggerService').next('#service'));
	jQuery('#triggerService').next('#service').remove();
	jQuery('#triggerService').find('#service').css({'top': jQuery('#triggerService').offset().top+jQuery('#triggerService').height(), 'left': jQuery('#triggerService').offset().left})
	jQuery('#triggerService').hover(function() {
		if(jQuery(this).find('#service').css('display') == 'none') {
			jQuery(this).find('#service').slideDown(function() {
				if(!jQuery('#serviceiframe').length) {
					jQuery(this).prepend('<iframe id="serviceiframe" frameborder="0" scrolling="no"></iframe>')
				}
				jQuery('#serviceiframe').css({'width': jQuery(this).outerWidth(), 'height': jQuery(this).outerHeight()});
				jQuery('#serviceiframe').show();
			});
		}
	}, function() {
		jQuery(this).find('#service').slideUp(function() {
			jQuery('#serviceiframe').hide();
		});
	});
}

/***************/
/*  tabmenu  **/
/*************/
function tabmenuBuild() {
	jQuery('.tx-neustatabs-pi1').not(jQuery('.tx-neustatabs-pi1 .tx-neustatabs-pi1')).each(function() {
		firstLevelTabs = jQuery(this);
		firstLevelTabs.contents().filter('ul').find('a').each(function() {
			var aElm = jQuery(this);
			var href = aElm.attr('href');
			aElm.attr('href', 'javascript:void(0);')
			if(aElm.hasClass('preserveContent')) {
				aElm.preservedContent = firstLevelTabs.contents().filter('.neustatabs').html();
			}
			aElm.click(function() {
				aElm.parent().parent().find('a').removeClass('active');
				aElm.addClass('active');
				if(aElm.preservedContent) {
					console.log('test')
					firstLevelTabs.contents().filter('.neustatabs').html(aElm.preservedContent);
					scrollerReInit();
				} else {
					jQuery.get(href, function(data){
						firstLevelTabs.contents().filter('.neustatabs').html(data);
						tabmenuSecondLevelBuild(firstLevelTabs.contents().filter('.neustatabs').find('.tx-neustatabs-pi1'));
						scrollerReInit();
						countryInfosBuild();
						TB_init();
					});
				}
			});
		});
		tabmenuSecondLevelBuild(firstLevelTabs.contents().filter('.neustatabs').find('.tx-neustatabs-pi1'));
	});
}

function tabmenuSecondLevelBuild(elm) {
	if(jQuery('#page_2890').length) {
		var optionFields = ''
		elm.find('ul li a').each(function() {
			optionFields += '<option id="' + jQuery(this).attr('id') + '" value="' + jQuery(this).attr('href') + '"' + (jQuery(this).hasClass('active') ? ' selected="selected"' : '') + '>' + jQuery(this).text() + '</option>';
		});
		elm.contents().filter('ul').replaceWith('<select>' + optionFields + '</select>');
		elm.contents().filter('select').change(function() {
			jQuery.get(jQuery(this).find('option:selected').attr('value'), function(data) {
				elm.contents().filter('.neustatabs').html(data);
				tabmenuReplaceFormAction();
			});
		});
		tabmenuReplaceFormAction();
	}
}

function tabmenuReplaceFormAction() {
	var mainDefaultID = jQuery('#content').contents().filter('.tx-neustatabs-pi1').contents().filter('ul').find('a.active').attr('id').replace(/el_/, '');
	var subDefaultID = jQuery('.tx-neustatabs-pi1 .tx-neustatabs-pi1').contents().filter('select').find('option:selected').attr('id').replace(/el_/, '');
	jQuery('.tx-neustatabs-pi1').find('form').attr('action', window.location.href.split('?')[0] + '?tx_neustatabs_pi1[default]=' + mainDefaultID + '-' + subDefaultID);
}

/***************/
/* breadcrumb */
/*************/
function breadcrumbBuild(){
	jQuery('#breadcrumb a').each(function(){
		if(jQuery(this).text() == '... in der Wintersaison' || jQuery(this).text() == '... in der Sommersaison' || jQuery(this).text() == 'Aktionen'){
			linkText = jQuery(this).text();
			jQuery(this).replaceWith(linkText);
		}
	});
}

/**********************/
/*  teaserscroller  **/
/********************/
function scrollerReInit() {
	jQuery('.tx-neustateaserscroller-pi1').filter(':not(.scrollerbuild)').each(function(i){
		var scroller = jQuery(this);
		scrollerInit(scroller);
		scrollerTabsInit(scroller);
	});
	jQuery('.scrollcluster .tx-neustateaserscroller-pi1').parent().hide();
	jQuery('.scrollcluster').find('.tx-neustateaserscroller-pi1:first').parent().show();
}

function scrollerInit(scroller) {
	scroller.addClass('scrollerbuild');
	scroller.classExt = 0;
	scroller.scrollerWidth = 0;
	scroller.scrollerHeight = 0;
	scroller.currentOffset = 0;
	scroller.cols = parseInt(scroller.parent().attr('class').match(/(\d)x(\d)/)[1]);
	scroller.rows = parseInt(scroller.parent().attr('class').match(/(\d)x(\d)/)[2]);
	scroller.find('.scrollcontent .scrollcontent').removeClass('scrollcontent');
	scroller.find('.scrollcontent').each(function(i) {
		scroller.classExt += !(i%scroller.rows) ? 1 : 0;
		jQuery(this).addClass('teaserscrollerwrap'+ scroller.classExt);
		jQuery(this).css({'clear': 'both'});
		if((i%scroller.rows) == scroller.rows-1 || i == scroller.find('.scrollcontent').length-1) {
			jQuery('.teaserscrollerwrap'+ scroller.classExt).wrapAll('<div class="tx-neustateaserscroller-pi1-innerwrap"></div>');
			jQuery('.teaserscrollerwrap'+ scroller.classExt).removeClass('teaserscrollerwrap'+ scroller.classExt);
		}
	});
	scroller.find('.tx-neustateaserscroller-pi1-innerwrap').css({'float': 'left'});
	scroller.find('.tx-neustateaserscroller-pi1-innerwrap').each(function(i) {
		scroller.scrollerWidth += jQuery(this).width();
		if(jQuery(this).height() > scroller.scrollerHeight) {
			scroller.scrollerHeight = jQuery(this).height()
		}
	});
	if(scroller.parents('.scrollcluster').length) {
		if(!scroller.parents('.scrollcluster').find('.scrollcontentclick').length) {
			if(scroller.parents('.scrollcluster').find('.neustateaserscrollermenu')) {
				scroller.parents('.scrollcluster').find('.neustateaserscrollermenu').after('<div class="scrollcontentclick">' + (scroller.find('.hideMeTillIGrow:first').html() ? scroller.find('.hideMeTillIGrow:first').html() : '') + '</div>');
			} else {
				scroller.parents('.scrollcluster').prepend('<div class="scrollcontentclick">' + (scroller.find('.hideMeTillIGrow:first').html() ? scroller.find('.hideMeTillIGrow:first').html() : '') + '</div>');
			}
		}
	} else {
		if(!scroller.parent().prev('.scrollcontentclick').length) {
			scroller.parent().before('<div class="scrollcontentclick">' + (scroller.find('.hideMeTillIGrow:first').html() ? scroller.find('.hideMeTillIGrow:first').html() : '') + '</div>');
		} else {
			scroller.parent().prev('.scrollcontentclick').html(scroller.find('.hideMeTillIGrow:first').html() ? scroller.find('.hideMeTillIGrow:first').html() : '');
		}
	}
	scroller.wrapInner('<div class="tx-neustateaserscroller-pi1-scroll"></div>');
	scroller.find('.tx-neustateaserscroller-pi1-scroll').css({'position': 'absolute', 'left': '0', 'width': (scroller.scrollerWidth + (jQuery.browser.msie ? 4 : 0)) + 'px'});
	scroller.css({'position': 'relative', 'overflow': 'hidden', 'height': scroller.scrollerHeight});
	var paddingTop = scroller.height()/2-26;
	if (paddingTop < 0) paddingTop = 0;
	scroller.parent().find('.iceOfferLeft').css({'visibility': 'hidden', 'paddingTop': (paddingTop) +'px'});
	scroller.parent().find('.iceOfferRight').css({'visibility': scroller.find('.tx-neustateaserscroller-pi1-innerwrap').length <= scroller.cols ? 'hidden' : 'visible', 'paddingTop': (paddingTop)+'px'});
	if(!scroller.find('.scrollcontent:last').hasClass('video') && !scroller.find('.scrollcontent:last').hasClass('audio') && jQuery.browser.msie) {
		// IE Fixes
		scroller.find('.scrollcontent:last').append('<br style="clear:both;">');
		scroller.find('.scrollcontent:last').css({'marginRight':'-3px'});
		scroller.find('.scrollcontent:last .teaserSmallTrigger').append('<br style="clear:both;">');

		scroller.find('.tx-neustateaserscroller-pi1-innerwrap:last').css('marginRight', '-3px');
		window.setTimeout(function(){
			scroller.find('.tx-neustateaserscroller-pi1-scroll').css({'width': (scroller.find('.tx-neustateaserscroller-pi1-scroll').width()-4) + 'px'});
		}, 1000);
		
		scroller.find('.offerD:last img:last').css({'width': '20px', 'height' : '20px'});
		window.setTimeout(function(){
			scroller.find('.offerD:last img:last').css({'width': '203px', 'height': '109px'});
		}, 4000);
	}
	scrollerMoveBind(scroller);
	blackOverlayBuild();
}

function scrollerTabsInit(scroller) {
	if(scroller.parents('.scrollcluster').length) {
		scrollerMenu = scroller.parents('.scrollcluster').find('.neustateaserscrollermenu');
	} else {
		scrollerMenu = scroller.parent().prev().prev('.neustateaserscrollermenu');
	}
	if(!scrollerMenu.hasClass('scrollmenubuild')) {
		scrollerMenu.addClass('scrollmenubuild');
		scrollerMenu.find('a').each(function(i) {
			var href = jQuery(this).attr('href');
			jQuery(this).attr('href', 'javascript:void(0)');
			jQuery(this).click(function() {
				jQuery(this).parent().parent().find('li').removeClass('active');
				jQuery(this).parent().addClass('active');
				if(scroller.parents('.scrollcluster').length) {
					scroller.parents('.scrollcluster').find('.tx-neustateaserscroller-pi1').parent().each(function() {
						if(jQuery(this).css('display') != 'none') {
							jQuery(this).fadeOut(500, function() {
								scroller.parents('.scrollcluster').find('.tx-neustateaserscroller-pi1:eq(' + i + ')').parent().fadeIn(500);
							});
						}
					})
					scroller.parents('.scrollcluster').find('.scrollcontentclick').slideUp(500, function() {
						jQuery(this).html(scroller.parents('.scrollcluster').find('.tx-neustateaserscroller-pi1:eq(' + i + ') .hideMeTillIGrow:first').html() ? scroller.parents('.scrollcluster').find('.tx-neustateaserscroller-pi1:eq(' + i + ') .hideMeTillIGrow:first').html() : '');
						eval(jQuery(this).find('.evalScript').html())
						setTimeout(function() {
							scroller.parents('.scrollcluster').find('.scrollcontentclick').slideDown(500);
						}, 50);
					});
				} else {
					var loaderPosLeft = scroller.offset().left+scroller.width()/2-110;
					var loaderPosTop = scroller.offset().top+scroller.height()/2-10;
					scroller.parent().css('height', scroller.height());
					scroller.parent().find('.iceOfferLeft').css('visibility', 'hidden');
					scroller.parent().find('.iceOfferRight').css('visibility', 'hidden');
					scroller.fadeOut(500, function() {
						scroller.next().after('<div class="loader"><img src="fileadmin/tui/pics/img/loader.gif"></div>');
						scroller.next().next('.loader').css({'position': 'absolute', 'left': loaderPosLeft + 'px', 'top': loaderPosTop + 'px'});
						var type = get('type', href);
						jQuery.get(href, {type: type?type:111}, function(data) {
							scroller.html(data);
							scroller.css({'left': '-10000', 'display': 'block'});
							scrollerInit(scroller);
							scroller.parent().css({'height': 'auto'});
							scroller.css({'left': '0', 'display': 'none'});
							scroller.fadeIn(500);
							scroller.next().next('.loader').remove();
							TB_init();
						});
					});
				}
			});
		});
	}
}

function scrollerMoveLeft(scroller) {
	scrollerMoveBind(scroller, 1);
	scroller.prev('.iceOfferLeft').css('visibility', 'visible');
	if(scroller.currentOffset+scroller.cols+1 == scroller.find('.tx-neustateaserscroller-pi1-innerwrap').length) {
		scroller.next('.iceOfferRight').css('visibility', 'hidden');
	}
	var leftMove = parseInt(scroller.find('.tx-neustateaserscroller-pi1-scroll').css('left')) - scroller.find('.tx-neustateaserscroller-pi1-innerwrap:eq(' + scroller.currentOffset + ')').width();
	scroller.find('.tx-neustateaserscroller-pi1-scroll').animate({left: leftMove}, 500, 'easeOutExpo', function() {
		scroller.currentOffset++;
		scrollerMoveBind(scroller);
	});
}

function scrollerMoveRight(scroller) {
	scrollerMoveBind(scroller, 1);
	scroller.next('.iceOfferRight').css('visibility', 'visible');
	if(scroller.currentOffset == 1) {
		scroller.prev('.iceOfferLeft').css('visibility', 'hidden');
	}
	var leftMove = parseInt(scroller.find('.tx-neustateaserscroller-pi1-scroll').css('left')) + scroller.find('.tx-neustateaserscroller-pi1-innerwrap:eq(' + (scroller.currentOffset - 1) + ')').width();
	scroller.find('.tx-neustateaserscroller-pi1-scroll').animate({left: leftMove}, 500, 'easeOutExpo', function() {
		scroller.currentOffset--;
		scrollerMoveBind(scroller);
	});
}

function scrollerMoveBind(scroller, unbind){
	if(unbind) {
		scroller.next('.iceOfferRight').unbind('click');
		scroller.prev('.iceOfferLeft').unbind('click');
	} else {
		if(scroller.find('.hideMeTillIGrow').length) {
			scroller.find('.scrollcontent').unbind('click')
			if(scroller.next('.iceOfferRight:visible').length) {
				scroller.find('.scrollcontent:eq(' + (scroller.cols+scroller.currentOffset-1) + ')').click(function() {scrollerMoveLeft(scroller)});
			}
			if(scroller.prev('.iceOfferLeft:visible').length) {
				scroller.find('.scrollcontent:eq(' + scroller.currentOffset + ')').click(function() {scrollerMoveRight(scroller)});
			}
		}
		scroller.next('.iceOfferRight').click(function() {scrollerMoveLeft(scroller)});
		scroller.prev('.iceOfferLeft').click(function() {scrollerMoveRight(scroller)});
		scroller.find('.hideMeTillIGrow').each(function() {
			var growElm = jQuery(this);
			jQuery(this).parent().click(function() {
				if(scroller.parents('.tx-neustahoteldetail-pi1').length) {
					scroller.parent().parent().find('.scrollcontentclick').fadeOut(100, function() {
						jQuery(this).html(growElm.html());
						eval(jQuery(this).find('.evalScript').html())
						jQuery(this).fadeIn(100);
					});
				} else {
					scroller.parent().prev('.scrollcontentclick').slideUp(500, function() {
						jQuery(this).html(growElm.html());
						jQuery(this).slideDown(500);
					});
				}
			});
		});
	}
}

/******************/
/*  quicklinks  **/
/****************/
function quicklinksBuild(){
	jQuery('#quickLinks').append('<div id="quicklinksButtonMore"><img src="http://tui.tuiprod.onlinetravel.ch/fileadmin/tui/pics/img/quicklinks_mehr.gif" alt="mehr"></div><div id="quicklinksButtonLess"><img src="http://tui.tuiprod.onlinetravel.ch/fileadmin/tui/pics/img/quicklinks_weniger.gif" alt="weniger"></div>');
	jQuery('#quicklinksRandom').after('<div id="quicklinksRandom2"></div>');
	jQuery('#quicklinksRandom li').each(function(i){
		if (i > 6) {
			jQuery('#quicklinksRandom2').append('<li>' + jQuery(this).html() + '</li>');
			jQuery(this).remove();
		}
	});
	if(jQuery('#stage img').height() > 400) {
		jQuery('#quicklinksRandom, #quicklinksFixed').show();
		jQuery('#quicklinksRandom2, #quicklinksButtonLess').hide();
		var toggleFields = '#quicklinksRandom2';
	} else {
		jQuery('#quicklinksFixed, #quicklinksRandom, #quicklinksRandom2, #quicklinksButtonLess').hide();
		var toggleFields = '#quicklinksFixed, #quicklinksRandom, #quicklinksRandom2';
	}
	jQuery('#quicklinksButtonMore').click(function(){
		jQuery(toggleFields).slideDown(function() {
			if(!jQuery('#quicklinksiframe').length) {
				jQuery('#quickLinks').prepend('<iframe id="quicklinksiframe" frameborder="0"></iframe>')
			}
			jQuery('#quicklinksiframe').css({'width': jQuery('#quickLinks').outerWidth(), 'height': jQuery('#quickLinks').outerHeight()});
			jQuery('#quicklinksiframe').show();
		});
		jQuery('#quicklinksButtonLess').show();
		jQuery('#quicklinksButtonMore').hide();
	});
	jQuery('#quicklinksButtonLess').click(function(){
		jQuery(toggleFields).slideUp(function() {
			jQuery('#quicklinksiframe').hide();
		});
		jQuery('#quicklinksButtonMore').show();
		jQuery('#quicklinksButtonLess').hide();
	});
}

/********************/
/*  countryinfos  **/
/******************/
function countryInfosBuild() {

	jQuery('#waitOverlay').css('display', 'block');
	var countryTabs = '';
	jQuery('#countryinfos select:eq(0)').each(function () {
		jQuery(this).find('option').each(function () {
			countryTabs += '<li id="li_' + jQuery(this).val() + '"><a href="javascript:void(0);">' + jQuery(this).text() + '</a></li>';
	    });
		//jQuery(this).replaceWith('<ul id="ciNavi" class="neustateaserscrollermenu">' + countryTabs + '</ul>');
		jQuery(this).css('display', 'none');
		jQuery('#countryinfos h1').after('<ul id="ciNavi" class="neustateaserscrollermenu">' + countryTabs + '</ul>');
    });
	jQuery('#mapimage h3').hide();
	jQuery('#li_mapimage').addClass('active');
	jQuery('#countryinfos li').each(function () {
		jQuery(this).click(function (){
			jQuery(this).parent().find('li').removeClass('active');
			jQuery(this).addClass('active');
			var id = jQuery(this).attr('id');
			id = '#' + id.substr(3);
			jQuery(this).parent().nextAll('.countrysection').hide();
			jQuery(this).parent().nextAll('.climateFlash').hide();
			jQuery(id + ' h3').hide();
			jQuery(id).show();
		})
	});
	jQuery('#ciNavi').after('<div class="separator"></div>');
	jQuery('.countrysection .liSubjectTitle').each(function (i) {
		jQuery(this).replaceWith('<h2 class="accordionTextClosed wrap_' + i + '">' + jQuery(this).text() + '</h2>');
	});
	jQuery('.countrysection .liSubjectInfo').each(function (i) {
		jQuery(this).replaceWith('<div class="accordionTriggerClass wrap_' + i + '"><div class="accordionBodyText">' + jQuery(this).html() + '</div></div>');
	});

	jQuery('.countrysection').contents().filter('div').each(function (i) {
		jQuery('.wrap_' + i).wrapAll('<div class="accordiontext"></div>').removeClass('wrap_' + i);
	})
	jQuery('#countryinfos div.liTable').each(function (i) {
		jQuery(this).wrap('<div class="accordiontext"></div>');
	})
	jQuery('#mapimage img').each(function (i) {
		jQuery(this).wrap('<div class="accordiontext"></div>');
	})

	jQuery('.countrysection').addClass('accordion');

	jQuery('.accordion').each(function() {accordionBuild(jQuery(this))});

	jQuery('#waitOverlay').css('display', 'none');
}

/*****************/
/*  accordion  **/
/***************/
function accordionBuild(accordion) {
	accordion.find('.accordionTriggerClass').css('width', accordion.find('h2:first').width()+parseInt(accordion.find('h2:first').css('paddingLeft'))).hide()
	accordion.find('.accordionTriggerClass:first').show();
	accordion.find('.accordiontext').contents().filter('h2:first').removeClass('accordionTextClosed').addClass('accordionTextOpen');
	accordion.find('.accordiontext').contents().filter('h2').click(function() {
		if(!jQuery(this).hasClass('accordionTextOpen')) {
			accordion.find('.accordionTriggerClass').slideUp();
			accordion.find('.accordiontext').contents().filter('h2').removeClass('accordionTextOpen').removeClass('accordionTextHover').addClass('accordionTextClosed');
			jQuery(this).removeClass('accordionTextClosed').addClass('accordionTextOpen');
			jQuery(this).next('.accordionTriggerClass').slideDown(function() {
				if(accordion.height() > jQuery('#left').outerHeight()) {
					jQuery('#left').css('height', accordion.height());
				}
			});
		}
	}).mouseover(function() {
		if(!jQuery(this).hasClass('accordionTextOpen')) {
			jQuery(this).removeClass('accordionTextClosed').addClass('accordionTextHover');
		}
	}).mouseout(function() {
		if(!jQuery(this).hasClass('accordionTextOpen')) {
			jQuery(this).removeClass('accordionTextHover').addClass('accordionTextClosed');
		}
	});
}

/******************************/
/*  highlightSearchKeyword  **/
/****************************/
function highlightSearchKeyword() {
	jQuery('#contentContainer').each(function() {
		var sword = decodeURI(get('sword'));
		if(sword && sword != 'null') {
			jQuery.highlight(this, sword.toUpperCase());
			jQuery('.highlight:first');
			jQuery('.highlight:first').parents().each(function() {
				if(jQuery(this).prev('a').length) {
					jQuery('html,body').animate({scrollTop: jQuery(this).offset().top}, 2000, 'easeOutExpo');
					return false;
				}
			});
		}
	});
	//jQuery('.highlight').parents().show()

}


/******************/
/*  headerfade  **/
/****************/
function headerFadeBuild(loading) {
	headerFadeBind(true);
	if(headerFadeCurrent < 0) {
		headerFadeCurrent = dataCount - 1;
		headerFadeBuild(loading);
	} else if(headerFadeCurrent >= dataCount) {
		headerFadeCurrent = 0;
		headerFadeBuild(loading);
	} else {
		if(headerFadeCache[headerFadeCurrent]) {
			headerFadeChange();
		} else {
			if(loading) {
				jQuery('#stage').after('<div class="loader"><img src="fileadmin/tui/pics/img/loader.gif"></div>');
				jQuery('#stage').next('.loader').css({'position': 'absolute', 'left': jQuery('#stage').width()/2-110 + 'px', 'top': jQuery('#stage').height()/2-10 + 'px'});
			}
			jQuery.get('index.php', {'id': 2641, 'tx_tuiheaderchanger_pi1[offset]': headerFadeCurrent, 'type': 100}, function(data){
				headerFadeCache[headerFadeCurrent] = data.replace(/\|\|\|(.*?)\|\|\|/g, '');
				headerFadeChange();
				jQuery('#stage').next('.loader').remove();
			});
		}
	}
}

function headerFadeChange() {
	jQuery('#stage').append('<div class="stageinnertmp">' + headerFadeCache[headerFadeCurrent] + '</div>');
	
	var innerHeight = jQuery('.stageinnertmp').contents().filter('img').height()
	if(!innerHeight) {
		innerHeight = jQuery('.stageinnertmp').contents().filter('a').find('img').height()
	}
	jQuery('#stage').css({'position':'relative', 'height': innerHeight});
	jQuery('.stageinner .headeroffer .bg').animate({'opacity': '0.1'}, 500, 'easeOutExpo', function() {
		jQuery('.stageinner').fadeOut(1000);
		jQuery(this).hide();
	});
	jQuery('.stageinnertmp').css('left', '-10000');
	jQuery('.stageinnertmp .headeroffer').html('<div class="bg"></div><h2 class="' + jQuery('.stageinnertmp .headeroffer h2').attr('class') + '">' + jQuery('.stageinnertmp .headeroffer h2').html() + '</h2><div class="headeroffercontent">' + jQuery('.stageinnertmp .headeroffer').html() + '</div>');
	jQuery('.stageinnertmp .headeroffer .headeroffercontent h2').remove();
	jQuery('.stageinnertmp .headeroffer .bg').css({'width': jQuery('.stageinnertmp .headeroffer').width(), 'height': jQuery('.stageinnertmp .headeroffer').height()});
	jQuery('#mainMenu').css('top', jQuery('.stageinnertmp img').height()-jQuery('#mainMenu').height());
	jQuery('.stageinnertmp').css({'left': '0', 'display': 'none'});
	jQuery('.stageinnertmp .headeroffer').hide();
	jQuery('.stageinnertmp').fadeIn(1000, function() {
		jQuery('.stageinner').remove();
		jQuery(this).find('.headeroffer .bg').css({'background': '#FFFFFF', 'opacity': '0.1'});
		jQuery(this).find('.headeroffer .bg').animate({'opacity': '0.8'}, 500, 'easeOutExpo');
		jQuery(this).find('.headeroffer').show();
		jQuery(this).attr('class', 'stageinner');
		headerFadeBind();
	});
}

function headerFadeStart(){
	jQuery('#headerNavi .play').hide();
	jQuery('#headerNavi .pause').show();
	headerFadeInterval = window.setInterval(function() {headerFadeCurrent++; headerFadeBuild();}, 12000);
}

function headerFadeStop(){
	jQuery('#headerNavi .pause').hide();
	jQuery('#headerNavi .play').show();
	clearInterval(headerFadeInterval);
}

function headerFadeBind(unbind){
	if(unbind) {
		jQuery('#headerNavi .play, #headerNavi .pause, #headerNavi .down, #headerNavi .up').unbind('click');
	} else {
		jQuery('#headerNavi .play').click(headerFadeStart);
		jQuery('#headerNavi .pause').click(headerFadeStop);
		jQuery('#headerNavi .down').click(function(){
			headerFadeCurrent++;
			headerFadeStop();
			headerFadeBuild(true);
		});
		jQuery('#headerNavi .up').click(function(){
			headerFadeCurrent--;
			headerFadeStop();
			headerFadeBuild(true);
		});
	}
}

/************************/
/*  vacationcalendar  **/
/**********************/
function vacationCalendarBuild(calendar) {
	jQuery('.tx-holydaycalendar-pi1').each(function() {
		calendar = jQuery(this);
		var calenderList = calendar.find('.vacationTable');
		calenderList.find('.vacationRow').click(function() {
			calendarSelectedState = jQuery(this);
			calenderList.find('.vacationRow').removeClass('active');
			calendarSelectedState.addClass('active');
			if(!calenderList.next('.calenderView').length) {
				calenderList.before('<div class="calenderSwitchBtn calenderViewBtn">zur Kalenderansicht wechseln</div>');
				calenderList.after('<div class="calenderView"></div>');
			}
			calenderList.prev('.calenderSwitchBtn').unbind('click');
			calenderList.prev('.calenderSwitchBtn').click(function() {
				calenderView = calenderList.next('.calenderView');
				calenderView.html('');
				if(calenderView.css('display') == 'none') {
					calenderList.prev('.calenderSwitchBtn').addClass('calenderListBtn').removeClass('calenderViewBtn').html('zur Listenansicht wechseln >');
					calenderList.find('.vacationRow').hide();
					calendarSelectedState.show();
					calenderView.show();
				} else {
					calenderList.prev('.calenderSwitchBtn').addClass('calenderViewBtn').removeClass('calenderListBtn').html('zur Kalenderansicht wechseln >');
					calenderList.find('.vacationRow').show();
					calenderView.hide();
				}
				calenderVac = new Array();
				calendarSelectedState.find('.js').each(function() {
					calenderVac.push(jQuery(this).html().split('-'));
				});
				for(var i=0; i<12; i++) {
					calenderView.append('<div class="calenderView' + i + '"></div>');
					calenderView.find('.calenderView' + i).datepicker({beforeShowDay: vacationCalendarMarkVac, defaultDate: new Date(new Date().getFullYear(), new Date().getMonth()+i, 1), changeMonth: false, changeYear: false});
				}
			});
		});
		calenderList.find('.vacationRow:first').click();
	});
}

function vacationCalendarMarkVac(dateElm) {
	for(var i=0; i<calenderVac.length; i++) {
		var dpFromParts = calenderVac[i][0].split('.');
		var dpFrom = new Date(dpFromParts[2], dpFromParts[1]-1, dpFromParts[0]).getTime();
		if(calenderVac[i].length == 2) {
			var dpToParts = calenderVac[i][1].split('.');
			var dpTo = new Date(dpToParts[2], dpToParts[1]-1, dpToParts[0]).getTime();
			if(dateElm.getTime() >= dpFrom && dateElm.getTime() <= dpTo) {
				return [true, 'ui-datepicker-vacation'];
			}
		}
		if(dateElm.getTime() == dpFrom) {
			return [true, 'ui-datepicker-vacation'];
		}
	}
	return [true, ''];
}

/*******************/
/*  quicksearch  **/
/*****************/

function searchContToggleCallback(container) {
	if(container.css('display') == 'none') {
		jQuery('#leftFirstTeaser').slideUp();
		jQuery('#subMenu').animate({marginTop: container.height()+10}, 500, 'easeOutExpo');
		jQuery('html,body').animate({scrollTop: jQuery('#contentContainer').offset().top}, 500, 'easeOutExpo');
	} else {
		jQuery('#leftFirstTeaser').slideDown();
		jQuery('#subMenu').animate({marginTop: 0}, 500, 'easeOutExpo');
	}

}

function searchHelpToggleCallback(container) {
	var helpBtn = container.prev('.helpopen');
	var topPos = helpBtn.position().top + parseInt(helpBtn.css('marginTop'));
	var leftPos = helpBtn.position().left + helpBtn.width() + parseInt(helpBtn.css('marginLeft')) + 5;
	container.css({'top':topPos, 'left':leftPos})
}

function searchSubmitCallbackBrand() {
	jQuery('#input_crs').val(jQuery('#input_crs').val() != "z.B. PMI43064" ? jQuery('#input_crs').val() : '');
	jQuery('#shotel').val(jQuery('#shotel').val() != "eingeben" ? jQuery('#shotel').val() : '');

	if (jQuery('.toppricefinderCell').length){
		jQuery('.toppricefinderCell').parent().find('input[name=ruecktermin]').val(Date.fromString(jQuery('#termin').val()).addMonths(1).asString());
	}

	if (jQuery('.toppricefinderCell').length){
		var traveler = jQuery('#erwachseneSelect').val();
		var childCount = 0;
		if (traveler.indexOf('|') != -1){
		    adult = traveler.split('|')[0];
			jQuery('form input[name=erwachsene]').val(adult);
		    childCount = parseInt(traveler.split('|')[1]);
			for (i = 1; i < childCount+1; i++){
				jQuery('form input[name=alter'+i+']').val('4');
			}
		} else {
			jQuery('form input[name=erwachsene]').val(traveler);
		}
	}

	return true;
}

function flyMoreQuickSearchBuild() {
	if(jQuery('.famap').length && jQuery('.fammap').length) {
		jQuery('.famap input[type=text]').each(function(i) {
			var input = jQuery(this);
			jQuery.get('index.php', {eID:'tx_tuiflightlist_ajax', method:'option', group:1, sec:i, sel:input.val()}, function(data) {
				input.after('<select name="' + input.attr('name') +'">' + data + '</select>');
				input.nextAll('select').bind('change', {count:i}, function(e) {
					jQuery('.fammap .' + (i ? 'to' : 'from')).text(jQuery(this).find('option:selected').text().replace(' - ', '') + (jQuery(this).find('option:selected').val() ? ' (' + jQuery(this).find('option:selected').val() + ')' : ''));
					jQuery('.famap select').data('selected', get(jQuery('.famap select:first').attr('name')) ? 1 : jQuery('.famap select').data('selected') ? jQuery('.famap select').data('selected') : e.data.count+1);
					if(jQuery('.famap select').data('selected') == e.data.count+1) {
						jQuery.get('index.php', {eID:'tx_tuiflightlist_ajax', method:'option', group:1, sec:e.data.count?0:1, sel:jQuery('.famap select:eq(' + (e.data.count?0:1) + ')').val(), code:jQuery(this).find('option:selected').val()}, function(data) {
							jQuery('.famap select:eq(' + (e.data.count?0:1) + ')').html(data);
						});
					}
				});
				input.remove();
			});
		});
		setTimeout(function() {get(jQuery('.famap select:first').attr('name')) ? jQuery('.famap select:first').change() : ''}, 5000);
	}
}

function setSeasonDate(){
	if(jQuery('#page_3429').length || jQuery('#page_3432').length){
		window.setTimeout(function (){
			if (get('season') != null){
				var seasonName = get('season');
				var hotelSeason = seasonName.substr(0,1);
				var now = new Date();
				var currentMonth = now.getMonth();
				if(currentMonth < 4 || currentMonth == 11){
					currentSeason = "W";
				} else {
					currentSeason = "S";
				}
				var endDate = new Date();
				now.addDays(+14);

				if(currentSeason == "W") {
					endDate.setMonth(2);
					endDate.setDate(17);
					if(currentSeason == hotelSeason){
						if(Math.round(now.getTime()/1000) < Math.round(endDate.getTime()/1000)) {
							// Winter and in time
							var firstDay = now.asString()
							var lastDay = '24.03.' + now.getFullYear()
						} else {
							// Winter and not in time
							var firstDay = (now.getDay() + 14) + '.' + (now.getMonth() + 1) + now.getFullYear()
							var lastDay = '24.11.' + now.getFullYear()
						}
					} else {
						// No winter
						var firstDay = '01.05.' + new Date().getFullYear()
						var lastDay = '31.10.' + new Date().getFullYear()
					}
				} else if(currentSeason == "S") {
					endDate.setMonth(9);
					endDate.setDate(24);
					if(currentSeason == hotelSeason){
						if (Math.round(now.getTime()/1000) < Math.round(endDate.getTime()/1000)){
							// Summer and in time
							var firstDay = now.asString()
							var lastDay = '31.10.' + now.getFullYear()
						} else {
							// Summer and not in time
							var firstDay = (now.getDay() + 14) + '.' + (now.getMonth() + 1) + now.getFullYear()
							var lastDay = '24.03.' + now.getFullYear()
						}
					} else {
						// No summer
						var firstDay = '01.12.' + new Date().getFullYear()
						var lastDay = '24.03.' + new Date().getFullYear()
					}
				}

				jQuery('#termin').val(firstDay);
				jQuery('#ruecktermin').val(lastDay);

			}
		}, 2000);
	}
}

/*********************/
/*  leftheight  *****/
/*******************/
function setLeftHeight() {
	if(jQuery('#mainContent').height() > jQuery('#outerLeft').height()) {
		jQuery('#left').css('height', jQuery('#mainContent').outerHeight() - jQuery('#leftFirstTeaser').outerHeight());
	}
	setTimeout(function() {
		if(jQuery('#mainContent').height() > jQuery('#outerLeft').height()) {
			setLeftHeight();
		}
	}, 3000);
}

/*********************/
/*  blackoverlays  **/
/*******************/
function blackOverlayBuild() {
	jQuery('.blackOverlay').each(function() {
		var overlayText = jQuery(this).find('.blackOverlayText');
		var overlayImg = overlayText.prev('img');
		if(overlayImg.length) {
			overlayText.css({'width': overlayImg.width() - parseInt(overlayText.css('paddingLeft')) - parseInt(overlayText.css('paddingRight')), 'height': overlayImg.height() - parseInt(overlayText.css('paddingTop')) - parseInt(overlayText.css('paddingBottom'))});
		}
	});
}

/*************/
/* Flugsuche */
/*************/
function ltfly_toggle_tt(value) {
	if (value=='OW') {
		jQuery('.returnDate').hide();
	} else {
		jQuery('.returnDate').show();
	}
}

/**
 * TUI Golf
 */
function addStartingTimeLine(){
    addGenericStartingTimeLine('startTimeTableFirstLine', 'startTimeTableAddLineLine');
}

function addIndivualStartingTimeLine(){
	addGenericStartingTimeLine('individualStartTimeTableFirstLine', 'individualStartTimeTableAddLineLine');
}

function addGenericStartingTimeLine(lineId, buttonLineId){

	var line = jQuery('#' + lineId);
	var clonedLine = line.clone();
	var id = line.parent().find('tr').size();

	clonedLine.removeAttr('id');
	clonedLine.find('input').each(function() {
		var currentInput = jQuery(this);
		var oldId = currentInput.attr('id');

		currentInput.attr('id', oldId + '_' + id);
		currentInput.val('');

		if (oldId == 'startTimeDate' || oldId == 'individualStartTimeDate') {
			currentInput.focus(golfStartTimeFormCalendarInit);
		}

		if(currentInput.attr('name') == 'individualStartTimeGolfCourse[]') {
			currentInput.blur(golfStartTimeReservationFormCheckForIndividualTime);
		}

	});


	line.parent().find('#' + buttonLineId).before(clonedLine);


}

function golfStartTimeReservationForm() {
	var formBodyDiv = jQuery('#startTimeReservation');

	if (formBodyDiv[0]) {

		var requiredFlag = '*';
		var conditionalFlag = '**';

		// enable submit button
		formBodyDiv.find('#submit').removeAttr('disabled');
		// hide credit card form
		formBodyDiv.find('#creditCardFieldSet').hide();

		// mark required fields
		formBodyDiv.find('form :input').filter('.required').prev('label').append(requiredFlag);
		formBodyDiv.find('form :input').filter('.conditional').prev('label').append(conditionalFlag);

		// hide error list
		formBodyDiv.find('.error-messages').hide().children('ul').children('li').hide();

		var focussed = null;

		// add hooks
		formBodyDiv.find('form :input').each(function() {
			if (jQuery(this).attr('id') == 'submit') {
				jQuery(this).bind("mouseenter", function() {
					if (focussed != null) {
						focussed.blur();
					}
				});
			} else {
				jQuery(this).blur(function() {
					golfStartTimeReservationFormValidation(jQuery(this));
				});
			}
			jQuery(this).focus(function(){
				focussed = jQuery(this);
			});
		});

		formBodyDiv.find('input[@name="individualStartTimeGolfCourse[]"]').blur(golfStartTimeReservationFormCheckForIndividualTime);

		formBodyDiv.append('<div class="dplayer" style="display:none;"></div><iframe class="dplayeriframe" frameborder="0"></iframe>');
		formBodyDiv.find('.dplayeriframe').hide();


		jQuery('#startTimeReservation .datepicker').focus(golfStartTimeFormCalendarInit);

	}
}

function golfStartTimeFormCalendarInit()  {

	var formBodyDiv = jQuery('#startTimeReservation');
	var dplayer = formBodyDiv.find('.dplayer');
    var inputField = jQuery(this);
    var iframe = formBodyDiv.find('.dplayeriframe');

	var oldDate = null;

	if (inputField.val() != '') {
		oldDate = Date.fromString(inputField.val());
	}

    dplayer.datepicker('destroy')
    dplayer.datepicker({
        onSelect: function(){
			iframe.hide();
            dplayer.hide();
            inputField.removeAttr('disabled');
            golfStartTimeReservationFormValidation(inputField);
        },
        altField: '#' + inputField.attr('id'),
        altFormat: 'dd.mm.yy',
		defaultDate: oldDate
    });

    inputField.attr('disabled', 'disabled');
	dplayer.css('cssText', 'left: ' + inputField.offset().left + 'px !important; top: ' + inputField.offset().top + 'px;');
	iframe.css('cssText', 'left: ' + inputField.offset().left + 'px !important; top: ' + inputField.offset().top + 'px;');
	iframe.show();
    dplayer.show();

}

function golfStartTimeReservationFormValidation(formField){


	var errorMessagesDiv = formField.parents('fieldset').find('.error-messages');
	var error = false;

	// show or hide the error message for the field depending on its validation
	// status
	if (formField.attr('type') == 'checkbox') {

		if (formField.parent().find('input[@name="' + formField.attr('name') + '"]:checked').size() == 0) {
			error = true;
		}
	} else if ((formField.hasClass('required') && formField.val() == '') ||
			   (!isElementHidden(formField) && ((formField.hasClass('conditional') && formField.val() == '')  || !golfStartTimeReservationFormFieldValueValidation(formField)))
			  ) {
		error = true;
	}

	if (error) {
		formField.addClass('form-error');
		errorMessagesDiv.find('#' + formField.attr('id') + 'Error').show();
	} else {
		formField.removeClass('form-error');
		errorMessagesDiv.find('#' + formField.attr('id') + 'Error').hide();
	}

	// show the error message header if there are visible error messages
	if ((error && errorMessagesDiv.find('ul').size() == 0) || errorMessagesDiv.find('li:visible').size() > 0) {
		errorMessagesDiv.show();
	} else {
		errorMessagesDiv.hide();
	}

}

function golfStartTimeReservationFormFieldValueValidation(formField) {

	switch (formField.attr('id')) {
		case 'email':
			// http://www.regular-expressions.info/email.html
			return /^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/.test(formField.val());
		default:
			// no value validation
			return true;
	}

}

function golfStartTimeReservationFormValidateAll() {

	var formBodyDiv = jQuery('#startTimeReservation');

	formBodyDiv.find(':input').each(function() {
		jQuery(this).blur();
	});

	if (formBodyDiv.find('.error-messages:visible').size() > 0) {
		return false;
	} else {
		return true;
	}
}

function golfStartTimeReservationFormCheckForIndividualTime() {

	var formBodyDiv = jQuery('#startTimeReservation');
	var names = '';

	formBodyDiv.find('input[@name="individualStartTimeGolfCourse[]"]').each(function() {
		names = names + jQuery(this).val();
	});

	if (names == '') {
		formBodyDiv.find('#creditCardFieldSet').hide();
	} else {
		formBodyDiv.find('#creditCardFieldSet').show();
	}

}

function isElementHidden(element) {
	return element.css('display') == 'none' || element.parents(':hidden').size() > 0
}

function toggleDepartureSelect(){
	jQuery('input[name=flextime]').each(function(i){
		if (i == 0 && this.checked == true){
			jQuery('#abflughafen').show();
			return false;
		} else {
			jQuery('#abflughafen').hide();
			jQuery('#abflughafen').val('-1');
		}
	});
}

