$J(document).ready(function() {
    $J("#nav-sub li:first-child").addClass('firstChild');
    $J("#nav-sub li:last-child").addClass('lastChild');
    $J("#mainNavigation li").hover(function(){
        $J(this).find(".dropdownbox").show();
    },function(){
        $J(this).find(".dropdownbox").hide();
    });
    $J('#nav-sub li.level_3 a').each(function(){
        if($J(this).hasClass('active')){
            $J('#nav-sub li.level_2 a').removeClass('active');
        }
    });
});
$J(window).load(function() { 
    var aNotSupportedBrowsers
    = "MSIE 5,MSIE 6,Netscape".split(",");
    var sSiteRelPath
    = "../../";
    var iLanguageID
    = "2";
    var bCanFadeOpacity
    = (window.navigator.userAgent.indexOf("MSIE 8") === -1 && window.navigator.userAgent.indexOf("MSIE 7") === -1);
    // Settings
    var iBrowserWarningSlideDownDuration	= 1000;
    var iBrowserWarningSlideDownDelay
    = 1000;
    var iBrowserWarningSlideUpDuration
    = 300;
    var iOverlayFadeInDuration
    = 300;
    // Overlay fadein duration (ms)
    var iOverlayFadeOutDuration
    = 100;
    // Overlay fadeout duration (ms)
    var iSwisshotelsIframeWidth
    = 1050;
    var iSwisshotelsIframeHeight
    = 580;
    var iLoginBoxSliderDuration
    = 300;
    var sLoginBoxSliderEasing
    = "swing";
    var iLSTVTeaserSlideDuration
    = 300;
    var iLSTVTeaserCounterDuration
    = 1000;
    var iLSTVTeaserCounterEasing
    = "easeOutExpo";
    // Shuffle array
    var shuffleArray
    = function(oldArray) {
        var newArray = oldArray.slice();
        var len = newArray.length;
        var i = len;
        while (i--) {
            var p = parseInt(Math.random()*len);
            var t = newArray[i];
            newArray[i] = newArray[p];
            newArray[p] = t;
        }
        return newArray;
    };
    // Check browser-support
    for(var iBrowser = 0; iBrowser < aNotSupportedBrowsers.length; iBrowser++) {
        if(window.navigator.userAgent.indexOf(aNotSupportedBrowsers[iBrowser]) !== -1) {
            $J("div#browserwarning").delay(iBrowserWarningSlideDownDelay).animate({
                height:
                $J("div#browserwarning div.warningcontent").outerHeight() + "px"
            }, {
                duration:
                iBrowserWarningSlideDownDuration
            });
            $J("div#browserwarning").one("click", function() {
                $J("div#browserwarning").animate({
                    height:
                    "0px"
                }, {
                    duration:
                    iBrowserWarningSlideUpDuration,
                    complete:
                    function() {
                        $J(this).remove();
                    }
                });
            });
            break;
        }
    }
    if($J("div.teaser-488-middle table##news").length > 0) {
        var iHeight
        = $J("div.teaser-488-middle table##news").height();
        if(iHeight > $J("div.teaser-488-middle").innerHeight()) {
            $J("table##news tr").last().remove();
        }
    }
    // Regionalassociations map, mouseover effect
    $J("div.map-tooltip-container").bind("mouseenter", function() {
        $J("div.map-tooltip", this).css({
            display:	"block"
        });
        $J(this).one("mouseleave", function() {
            $J("div.map-tooltip", this).css({
                display:	"none"
            });
        });
    });
    // Settings
    var iNavSlideDuration
    = 20;	// Milliseconds
    var iNavSlideDelay
    = 100;	// Milliseconds
    // ONLOAD
    $J("div.nav").bind("mouseenter", function() {
        if(!$J(this).is(".over")) {
            var self
            = this;
            var iContentHeight
            = 0;
            var iStartHeight
            = $J("div.subnav", this).outerHeight();
            $J("div.nav.over").unbind("mouseleave").removeClass("over").find("div.subnav").stop().css("height", iStartHeight + "px");
            $J(this).addClass("over");
            if(!$J(this).is(".nosubnav")) {
                // Calculate subnav-container-height
                $J("div.subnav", this).children().each(function() {
                    iContentHeight
                    += $J(this).outerHeight();
                });
                // Animate subnav-container
                $J("div.subnav", this).delay(iNavSlideDelay).animate({
                    height:
                    iContentHeight + "px"
                }, {
                    duration:	iNavSlideDuration
                });
                // Bind single mouseleave-event
                $J(this).one("mouseleave", function() {
                    $J("div.subnav", this).stop().animate({
                        height:
                        iStartHeight + "px"
                    }, {
                        duration:	iNavSlideDuration,
                        complete:	function() {
                            $J(self).removeClass("over");
                        }
                    });
                });
            } else {
                $J(this).one("mouseleave", function() {
                    $J(this).removeClass("over");
                });
            }
        }
    });
    // Settings
    var iMoodFadeInDuration
    = 800;
    var iMoodFadeDuration
    = 800;
    var iMoodFadeTimeout
    = 5000;
    // Global variables
    var oMoodFadeTimeout
    = 0;
    if($J("img.mood-image").length > 1) {
        var aImages	= shuffleArray($J.makeArray($J("img.mood-image")));
        $J("div#mood-images").html("");
        $J(aImages).appendTo($J("div#mood-images"));
        $J("img.mood-image").eq(0).addClass("top").end().eq(1).addClass("bottom");
        var iStartZIndex
        = parseInt($J("#mood-images").css("z-index"));
        $J("a.point").live("click", function(oEvent){
            oEvent.preventDefault();
            fadeMood($J(this).index("a.point"));
        });
        $J("img.mood-image").each(function(iImageIndex) {
            var oPointContainer
            = $J('<a class="point" />');
            if(iImageIndex === 0) {
                oPointContainer.addClass("active");
            }
            $J("div#mood-points").append(oPointContainer);
        });
    }
    // Prepare mood-images for fadein
    $J("div#mood-images,").css({
        opacity:	0,
        display:	"block"
    });
    if(bCanFadeOpacity) {
        $J("div#mood-points, div#mood.homepage div.black-teaser").css({
            opacity:	0,
            display:	"block"
        });
    } else {
        $J("div#mood-points, div#mood.homepage div.black-teaser").css({
            display:	"block"
        });
    }
    // Preload first mood-image before fadein
    var oImage
    = new Image();
    oImage.onload	= function() {
        $J("div#mood-images").animate({
            opacity:	1
        }, {
            duration:	iMoodFadeInDuration,
            complete:	function() {
                $J("img.mood-image", this).not(".top").css("display", "block");
                if(bCanFadeOpacity) {
                    $J("div#mood-points").delay(iMoodFadeInDuration).animate({
                        opacity:	1
                    }, {
                        duration:	iMoodFadeInDuration,
                        complete:	function() {
                            startAutoFadeMood();
                        }
                    });
                    $J("div#mood.homepage div.black-teaser").delay(iMoodFadeInDuration).animate({
                        opacity:	1
                    }, {
                        duration:	iMoodFadeInDuration
                    });
                } else {
                    $J("div#mood-points, div#mood.homepage div.black-teaser").css({
                        display:
                        "block"
                    });
                    startAutoFadeMood();
                }
            }
        });
    }
    oImage.src
    = $J("img.mood-image.top").attr("src");
    var resizeMood
    = function() {
        $J("div#mood-images img.mood-image").each(function(i) {
            // Check width for Image
            if($J(this).width() != $J(window).width()){
                $J(this).attr("width", $J(window).width());
                $J(this).removeAttr("height");
            }
            // Check height for Image
            if($J(this).height() < $J("div#mood-images").height()) {
                $J(this).attr("height", $J("div#mood-images").height());
                $J(this).removeAttr("width");
            }
        });
    };
    var fadeMood
    = function(iIndex) {
        stopAutoFadeMood();
        if($J("img.mood-image:animated").length === 0) {
            $J("img.mood-image").removeClass("bottom");
            $J("img.mood-image").eq(iIndex).addClass("bottom");
            $J("a.point").removeClass("active").eq(iIndex).addClass("active");
            $J("img.mood-image.top").animate({
                opacity:
                0
            }, {
                duration:
                iMoodFadeDuration,
                complete:
                function() {
                    $J("img.mood-image.bottom").addClass("top").removeClass("bottom");
                    $J(this).removeClass("top").css("opacity", 1);
                    startAutoFadeMood();
                }
            });
        }
    };
    var startAutoFadeMood
    = function() {
        oMoodFadeTimeout
        = setTimeout(function() {
            var iNextIndex
            = $J("img.mood-image.top").index("img.mood-image") + 1;
            if($J("img.mood-image").eq(iNextIndex).length === 0) {
                iNextIndex
                = 0;
            }
            fadeMood(iNextIndex);
        }, iMoodFadeTimeout);
    };
    var stopAutoFadeMood
    = function() {
        clearTimeout(oMoodFadeTimeout);
    };
    // Init functions
    resizeMood();
    $J(window).resize(function() {
        resizeMood();
    }); // Settings
    var iTeaserFadeDuration
    = 1500;
    var iTeaserFadeTimeout
    = 4000;
    // Global variables
    var oTeaserFadeTimeout
    = null;
    var iNextFadeTeaserIndex
    = 0;
    var iTotalTeasers
    = $J("div.teaser-slider div.teaser-228-image").length;
    var fadeTeaser
    = function(iIndex) {
        $J("div.teaser-slider div.teaser-228-image.teaser" + iIndex).animate({
            opacity:	0
        }, {
            duration:	iTeaserFadeDuration,
            complete:	function() {
                var oNewParent
                = $J(this).parent();
                var oThisParent
                = oNewParent;
                if(iTotalTeasers % 2 == 1) {
                    oNewParent
                    = $J("div.teaser-slider div." + (oNewParent.hasClass("left") ? "right" : "left"));
                }
                $J(this).removeClass("top").css("opacity", 1).appendTo(oNewParent);
                if($J("a", oNewParent).length === 2) {
                    $J("a", oNewParent).last().addClass("bottom");
                }
                $J("a.bottom", oThisParent).removeClass("bottom").addClass("top");
                $J("a", oThisParent).eq(1).addClass("bottom");
                oTeaserFadeTimeout
                = null;
                startAutoFadeTeaser();
            }
        });
    };
    var startAutoFadeTeaser
    = function() {
        if(oTeaserFadeTimeout === null) {
            oTeaserFadeTimeout
            = setTimeout(function() {
                iNextFadeTeaserIndex
                = (iNextFadeTeaserIndex + 1 > iTotalTeasers) ? 1 : iNextFadeTeaserIndex + 1;
                fadeTeaser(iNextFadeTeaserIndex);
            }, iTeaserFadeTimeout);
        }
    };
    var stopAutoFadeTeaser
    = function() {
        clearTimeout(oTeaserFadeTimeout);
        oTeaserFadeTimeout
        = null;
    };
    if(iTotalTeasers > 2) {
        $J("div.teaser-slider div.teaser-228-image").bind("mouseenter", function() {
            stopAutoFadeTeaser();
            $J(this).one("mouseleave", function() {
                startAutoFadeTeaser();
            });
        });
        startAutoFadeTeaser();
    } // Check login
});
