function KeyvisualGlobe(globes){this.position=0;this.globes=globes;}
KeyvisualGlobe.prototype.addKeyvisualParent=function(keyvisualParent){this.keyvisualParent=keyvisualParent;}
KeyvisualGlobe.prototype.addLiveKeyvisual=function(liveKeyvisual){this.liveKeyvisual=liveKeyvisual;}
KeyvisualGlobe.prototype.addTeaserArea=function(teaserArea){this.teaserArea=teaserArea;}
KeyvisualGlobe.prototype.addGlobeIcons=function(globeIcons){this.globeIcons=globeIcons;}
KeyvisualGlobe.prototype.addGlobeWindows=function(globeWindows){this.globeWindows=globeWindows;this._createWindowOpener();}
KeyvisualGlobe.prototype.addLabels=function(labels){this.labels=labels;var that=this;labels.click(function(){var index=labels.index(this);that.switchGlobe(index);});}
KeyvisualGlobe.prototype.addLeftButton=function(button){var that=this;button.click(function(){var newPosition=that.position-1;if(newPosition>=0)that.switchGlobe(newPosition);});}
KeyvisualGlobe.prototype.addRightButton=function(button){var that=this;button.click(function(){var newPosition=that.position+1;if(newPosition<=that.maxPosition)that.switchGlobe(newPosition);});}
KeyvisualGlobe.prototype.addSlider=function(sliderOrigin,sliderContainer){sliderOrigin.hide();var value=sliderOrigin[0].selectedIndex+1;var minValue=1;var maxValue=sliderOrigin.children('option').length;this.maxPosition=maxValue-1;this.sliderOrigin=sliderOrigin;this.sliderObject=this._createSlider({value:value,minValue:minValue,maxValue:maxValue,object:sliderContainer,origin:sliderOrigin});}
KeyvisualGlobe.prototype._createSlider=function(options){var that=this;var response=options.object.slider({min:options.minValue,max:options.maxValue,value:options.value,animate:true,stop:function(event,ui){ui.handle.blur();that.switchGlobe(ui.value-1);}});return response;}
KeyvisualGlobe.prototype._isTouchDevice=function(){return jQuery('html.touch').length>0;}
KeyvisualGlobe.prototype._createWindowOpener=function(){var that=this;var closeWindow=function(window,clickTarget){if(clickTarget.parents('.window').length<=0||clickTarget.hasClass('closebutton')){if(that._isTouchDevice()){window.hide('fast',function(){that.globeWindows.children('.windowGroup').hide();that.globeWindows.hide();});}else{window.fadeOut('fast',function(){that.globeWindows.children('.windowGroup').hide();that.globeWindows.hide();});}
jQuery(document).unbind('click');}}
this.globeIcons.children('div').each(function(index,iconGroup){var windowGroup=that.globeWindows.children('.windowGroup:eq('+index+')');jQuery(iconGroup).children('a').each(function(iconIndex,icon){jQuery(icon).mouseover(function(){var windowToOpen=windowGroup.children('.window:eq('+iconIndex+')');if(windowToOpen.length>0){windowGroup.show();that.globeWindows.show();if(that._isTouchDevice()){windowToOpen.show();}else{windowToOpen.fadeIn();}
jQuery(document).bind('click',function(e){closeWindow(windowToOpen,jQuery(e.target));});}});});});}
KeyvisualGlobe.prototype.switchGlobe=function(position){if(!this.globes.children('.active').is(':animated')){this.sliderOrigin[0].selectedIndex=position;this.sliderObject.slider('value',position+1);this.labels.removeClass('active');jQuery(this.labels[position]).addClass('active');if(this.position!=position){var direction=(position<this.position)?'left':'right';this.position=position
this.globeWindows.find('.window:visible').fadeOut('fast',function(){jQuery(this).parent().hide();jQuery(this).parents('#globeWindows').hide();});var newTeaserPosition=(this.teaserArea.width()/5)*position*-1;this.teaserArea.animate({marginLeft:newTeaserPosition},'slow');if(jQuery(this.labels[position]).hasClass('dark'))keyvisualBg='dark';else keyvisualBg='light';this._switchKeyvisualBackground(keyvisualBg);this._animateGlobe(direction,position);}}}
KeyvisualGlobe.prototype.swipeLeft=function(){var newPosition=this.position+1;if(newPosition<5)
this.switchGlobe(newPosition);}
KeyvisualGlobe.prototype.swipeRight=function(){var newPosition=this.position-1;if(newPosition>=0)
this.switchGlobe(newPosition);}
KeyvisualGlobe.prototype._animateGlobe=function(direction,newPosition){var browser=jQuery.browser;var browserVersion=parseInt(jQuery.browser.version);if(browser.msie&&browserVersion<9)
this._dunkGlobe();else if(jQuery('html').hasClass('touch'))
this._slideGlobe(direction,newPosition);else
this._rotateGlobe(direction);}
KeyvisualGlobe.prototype._slideGlobe=function(direction,newPosition){var startPosition=Math.round(parseInt(this.globes.css('left'))/2000);var moveDirection=(direction=='left'?1:-1);var moveSteps=Math.abs(Math.abs(startPosition)-Math.abs(newPosition));var animatePosition=(startPosition+(moveDirection*moveSteps))*2000;var oldIconPosition=this.globeIcons.css('top');var that=this;this.sliderObject.slider('disable');this.globeIcons.fadeOut(100);this.globes.animate({left:animatePosition+'px'},'fast',false,function(){that.globeIcons.children('.active').removeClass('active');that.globeIcons.children('div:eq('+that.position+')').addClass('active');that.globeIcons.css('top',oldIconPosition);that.globeIcons.show();that.sliderObject.slider('enable');});};KeyvisualGlobe.prototype._dunkGlobe=function(){var startPosition=parseInt(this.globes.css('top'));var height=parseInt(this.globes.css('height'));var animatePosition=height-startPosition;var oldIconPosition=this.globeIcons.css('top');var that=this;this.sliderObject.slider('disable');this.globeIcons.animate({opacity:'toggle',top:'0'});this.globes.animate({top:animatePosition+'px'},'slow',false,function(){that.globes.children('.active').removeClass('active');that.globes.children('.globe:eq('+that.position+')').addClass('active');that.globes.animate({top:startPosition+'px'},'slow',false,function(){that.sliderObject.slider('enable');that.globeIcons.children('.active').removeClass('active');that.globeIcons.children('div:eq('+that.position+')').addClass('active');that.globeIcons.animate({opacity:'toggle',top:oldIconPosition});});});}
KeyvisualGlobe.prototype._rotateGlobe=function(direction){var deg=(direction=="left")?-360:360;var that=this;this.sliderObject.slider('disable');this.globes.rotate({angle:0,animateTo:deg,duration:2000,easing:$.easing.easeInOutBack,callback:function(){that.sliderObject.slider('enable');}});this.globes.children('.active').fadeOut(2000,function(){jQuery(this).removeClass('active')});this.globes.children('.globe:eq('+this.position+')').fadeIn(2000,function(){jQuery(this).addClass('active')});this.globeIcons.rotate({angle:0,animateTo:deg,duration:2150,easing:$.easing.easeInOutBack});this.globeIcons.children('.active').fadeOut(2000,function(){jQuery(this).removeClass('active')});this.globeIcons.children('div:eq('+this.position+')').fadeIn(2000,function(){jQuery(this).addClass('active')});}
KeyvisualGlobe.prototype._switchKeyvisualBackground=function(keyvisualBg){var speed='slow';if(this._isTouchDevice())
speed='fast';if(keyvisualBg=='dark'){this.keyvisualParent.addClass('live');this.liveKeyvisual.fadeIn(speed);}else{this.keyvisualParent.removeClass('live');this.liveKeyvisual.fadeOut(speed);}};jQuery(document).ready(function(){jQuery('#keyvisual').find('#globes').children('a').each(function(){var globeContainer=jQuery(this).parent();var imageURL=jQuery(this).attr('href');jQuery(this).remove();globeContainer.append(jQuery('<img />').attr('src',imageURL).attr('class','globe'));});keyvisualGlobe=new KeyvisualGlobe(jQuery('#globes'));keyvisualGlobe.addGlobeIcons(jQuery('#globeIcons'));keyvisualGlobe.addGlobeWindows(jQuery('#globeWindows'));keyvisualGlobe.addTeaserArea(jQuery('#CONT_frontdoorContent').find('.teaserArea').find('.mainTeaserCollection'));keyvisualGlobe.addLabels(jQuery('#KeyvisualTheme').parent().find('h4'));keyvisualGlobe.addSlider(jQuery('#KeyvisualTheme'),jQuery('#sliderKeyvisualTheme'));keyvisualGlobe.addLeftButton(jQuery('#CONT_frontdoorContent').find('.themeSlider').find('.button.left'));keyvisualGlobe.addRightButton(jQuery('#CONT_frontdoorContent').find('.themeSlider').find('.button.right'));keyvisualGlobe.addKeyvisualParent(jQuery('#keyvisual'));keyvisualGlobe.addLiveKeyvisual(jQuery('#skyForLiveKeyvisual'));jQuery('#CONT_frontdoorContent').find('.quickSearch').find('ul.tabs').find('li').each(function(index,that){var tabForms=jQuery(that).parents('.quickSearch').find('.formCollection');jQuery(that).click(function(){if(!jQuery(that).hasClass('active')){jQuery(that).parent().children('.active').removeClass('active');jQuery(that).addClass('active');tabForms.children('form:visible').slideUp();tabForms.children('form:eq('+index+')').slideDown();}});});jQuery("#CONT_frontdoorContent").find(".teaserArea").find('.teaserGroup').each(function(index,that){slideTarget=jQuery(that).find('.smallTeaser').find('.teaserCollection');var frontdoorSmallTeaserSlider=new StepSlider(slideTarget,{maxSteps:3});slideTarget.parents(".smallTeaser").find("a.moreTeaser.default").click(function(){if(!frontdoorSmallTeaserSlider.isAnimated()){var moreSlidesLeft=frontdoorSmallTeaserSlider.stepsLeft("right");if(moreSlidesLeft)frontdoorSmallTeaserSlider.slideRight();else frontdoorSmallTeaserSlider.slide(0);}
jQuery(this).blur();});jQuery("a.moreTeaser.flow.right").click(function(){if(!frontdoorSmallTeaserSlider.isAnimated()){var moreSlidesLeft=frontdoorSmallTeaserSlider.stepsLeft("right");if(moreSlidesLeft)frontdoorSmallTeaserSlider.slideRight();}
jQuery(this).blur();});jQuery("a.moreTeaser.flow.left").click(function(){if(!frontdoorSmallTeaserSlider.isAnimated()){var moreSlidesRight=frontdoorSmallTeaserSlider.stepsLeft("left");if(moreSlidesRight)frontdoorSmallTeaserSlider.slideLeft();}
jQuery(this).blur();});slideTarget=jQuery(that).find('.bigTeaser').find('.teaserCollection');var frontdoorLargeTeaserSlider=new PositionSlider(slideTarget);jQuery(that).find(".smallTeaser").find('.teaser').each(function(index,that){jQuery(that).click(function(){jQuery(that).blur();if(!jQuery(that).hasClass('active')){if(!frontdoorLargeTeaserSlider.isAnimated()){jQuery(that).parent().children('.active').removeClass('active');jQuery(that).addClass('active');frontdoorLargeTeaserSlider.slideTo(index);}}})});});initRangeDatepicker('quicksearch_hotel_arrival','quicksearch_hotel_departure',true,new Date(),new Date().addDays(1));initRangeDatepicker('quicksearch_event_arrival','quicksearch_event_departure',true,new Date(),new Date());});
