function onDocumentLoad() {

    try {
        new CookieManager();
    }
    catch (e) {
    }

    if (typeof(hotelCategory) == 'undefined') {
        hotelCategory = "";
    }
    try {
        if ($('mylightbox')) {
            myLightbox = new Lightbox();
        }
    }
    catch (e) {
    }

    if ($('languages') != null) {
        var languages = new dropDown($('languages'));
    }

    if ($('requesttyp') != null) {
        var requesttyp = new dropDown($('requesttyp'));
    }

    if ($('requestdestination') != null) {
        var requestdestination = new dropDown($('requestdestination'));
    }

    switch (hotelCategory) {
        case 'wellness':
            var sujetColor = "05b1a3";
            break;

        case 'city':
            var sujetColor = "b6030e";
            break;

        case 'family':
            var sujetColor = "f48f00";
            break;

        case 'residences':
            var sujetColor = "755d88";
            break;

        default:
            var sujetColor = "00468e";
            break;

    }
    /*
     try {
     text2image($$('#portal .portalarea .teaserbox .themeteaser.neutral p a.headline'), {
     font: 'StoneSerITCStd-Medium.ttf',
     width: '179',
     height: '23',
     color: '00498D',
     size: '14',
     positionx: 0,
     positiony: 15,
     replaceElement: {
     tagName: "a",
     className: "headline"
     },
     addImage: {
     tagName: "a",
     className: "headdone",
     top: 0
     }
     });
     text2image($$('#portal .portalarea .teaserbox .themeteaser.wellness p a.headline'), {
     font: 'StoneSerITCStd-Medium.ttf',
     width: '159',
     height: '23',
     color: '05b1a3',
     size: '14',
     positionx: 0,
     positiony: 15,
     replaceElement: {
     tagName: "a",
     className: "headline"
     },
     addImage: {
     tagName: "a",
     className: "headdone",
     top: 0
     }
     });
     text2image($$('#portal .portalarea .teaserbox .themeteaser.city p a.headline'), {
     font: 'StoneSerITCStd-Medium.ttf',
     width: '180',
     height: '23',
     color: 'b6030e',
     size: '14',
     positionx: 0,
     positiony: 15,
     replaceElement: {
     tagName: "a",
     className: "headline"
     },
     addImage: {
     tagName: "a",
     className: "headdone",
     top: 0
     }
     });
     text2image($$('#portal .portalarea .teaserbox .themeteaser.family p a.headline'), {
     font: 'StoneSerITCStd-Medium.ttf',
     width: '179',
     height: '23',
     color: 'f48f00',
     size: '14',
     positionx: 0,
     positiony: 15,
     replaceElement: {
     tagName: "a",
     className: "headline"
     },
     addImage: {
     tagName: "a",
     className: "headdone",
     top: 0
     }
     });



     }
     catch (e) {
     }
     */

    var hotelTypes = new Array({
        key: 'wellness',
        color: '05b1a3'
    }, {
        key: 'city',
        color: 'b6030e'
    }, {
        key: 'family',
        color: 'f48f00'
    });

    new classSwitcher([ $$('#topnav li'), $$('#topnav li ul li'), $$('#topnav li ul li ul li') ]);
    new classPicSwitcher([ $$('#topnav li.main') ]);


    /**Initialisierung fuer Hotelkategorien wenn vorhanden */
    var categories = document.getElementsByClassName('categories');
    if (categories.length > 0) {
        for (j = 0; j < categories.length; j++) {
            cats = categories[j].getElementsByClassName('category');
            new catSlider(cats);
        }
    }

    /** Initialisierung fuer Angebote wenn vorhanden */
    if ($('packagescroll')) {
        var offerBlock = document.getElementsByClassName('packages');
        if (offerBlock.length > 0) {
            for (j = 0; j < offerBlock.length; j++) {
                offers = offerBlock[j].getElementsByClassName('entry');
                new offerSlider(offers);
            }
        }
    }

    /**  Fade Headerimages */
    if ($('slideheaderimages')) {
        /**  headerimages */
        animBackgroundHelper = null;
        var animBackground = Class.create();
        animBackground.prototype = {
            initialize : function (element) {
                this.images = $('slideheaderimages').getElementsByTagName('img');
                for (i = 0; i < this.images.length; i++) {
                    if (i != 0) {
                        $(this.images[i]).setOpacity(0);
                        this.images[i].style.zIndex = 2;
                    }
                    else {
                        $(this.images[i]).setOpacity(100);
                        this.images[i].style.zIndex = 3;
                        this.images[i].style.display = "block";
                    }
                }
                this.actual = 0;
                if (this.images.length != 1) {
                    new PeriodicalExecuter(this.changeImage, 4);
                }
                animBackgroundHelper = this;
            },
            changeImage : function () {
                images = animBackgroundHelper.images;
                if (animBackgroundHelper.actual == images.length - 1) {
                    animBackgroundHelper.images[0].style.display = "block";
                    animBackgroundHelper.images[animBackgroundHelper.actual].style.zIndex = 2;
                    animBackgroundHelper.images[0].style.zIndex = 3;
                    ex9 = new Animator({
                        transition: Animator.makeEaseOut(3),
                        duration: 4000
                    });
                    ex9.addSubject(new NumericalStyleSubject(animBackgroundHelper.images[animBackgroundHelper.actual], 'opacity', 1, 0));
                    ex9.addSubject(new NumericalStyleSubject(animBackgroundHelper.images[0], 'opacity', 0, 1));
                    ex9.play();
                    animBackgroundHelper.actual = 0;
                }
                else {
                    animBackgroundHelper.images[animBackgroundHelper.actual + 1].style.display = "block";
                    animBackgroundHelper.images[animBackgroundHelper.actual].style.zIndex = 2;
                    animBackgroundHelper.images[animBackgroundHelper.actual + 1].style.zIndex = 3;
                    ex9 = new Animator({
                        transition: Animator.makeEaseOut(3),
                        duration: 4000
                    });
                    ex9.addSubject(new NumericalStyleSubject(animBackgroundHelper.images[animBackgroundHelper.actual], 'opacity', 1, 0));
                    ex9.addSubject(new NumericalStyleSubject(animBackgroundHelper.images[animBackgroundHelper.actual + 1], 'opacity', 0, 1));
                    ex9.play();
                    animBackgroundHelper.actual ++;
                }
            }
        };
        new animBackground();
    }
    /**  Fade Portalimages */
    if ($('slideportalimages')) {

        animBackgroundHelper = null;
        var animBackground = Class.create();
        animBackground.prototype = {
            initialize : function (element) {
                this.images = $('slideportalimages').getElementsByTagName('img');
                for (i = 0; i < this.images.length; i++) {
                    if (i != 0) {
                        $(this.images[i]).setOpacity(0);
                        this.images[i].style.zIndex = 2;
                    }
                    else {
                        $(this.images[i]).setOpacity(100);
                        this.images[i].style.zIndex = 3;
                        this.images[i].style.display = "block";
                    }
                }
                this.actual = 0;
                if (this.images.length != 1) {
                    new PeriodicalExecuter(this.changeImage, 4);
                }
                animBackgroundHelper = this;
            },
            changeImage : function () {
                images = animBackgroundHelper.images;
                if (animBackgroundHelper.actual == images.length - 1) {
                    animBackgroundHelper.images[0].style.display = "block";
                    animBackgroundHelper.images[animBackgroundHelper.actual].style.zIndex = 2;
                    animBackgroundHelper.images[0].style.zIndex = 3;
                    ex9 = new Animator({
                        transition: Animator.makeEaseOut(3),
                        duration: 4000
                    });
                    ex9.addSubject(new NumericalStyleSubject(animBackgroundHelper.images[animBackgroundHelper.actual], 'opacity', 1, 0));
                    ex9.addSubject(new NumericalStyleSubject(animBackgroundHelper.images[0], 'opacity', 0, 1));
                    ex9.play();
                    /* $('teaser').getElementsBySelector("h2").getElementsBySelector("a"); */
                    links = $('teaser').getElementsBySelector("a");
                    for (i = 0; i < links.length; i++) {
                        switch (i) {
                            case 0:
                                links[i].update(animBackgroundHelper.images[0].name);
                                break;
                            case 1:
                                links[i].update(animBackgroundHelper.images[0].alt);
                                break;
                        }
                        links[i].href = getUrl(animBackgroundHelper.images[0].longDesc.replace("http://www.falkensteiner.com", ""));
                    }
                    animBackgroundHelper.actual = 0;
                }
                else {
                    animBackgroundHelper.images[animBackgroundHelper.actual + 1].style.display = "block";
                    animBackgroundHelper.images[animBackgroundHelper.actual].style.zIndex = 2;
                    animBackgroundHelper.images[animBackgroundHelper.actual + 1].style.zIndex = 3;
                    ex9 = new Animator({
                        transition: Animator.makeEaseOut(3),
                        duration: 4000
                    });
                    ex9.addSubject(new NumericalStyleSubject(animBackgroundHelper.images[animBackgroundHelper.actual], 'opacity', 1, 0));
                    ex9.addSubject(new NumericalStyleSubject(animBackgroundHelper.images[animBackgroundHelper.actual + 1], 'opacity', 0, 1));
                    ex9.play();
                    links = $('teaser').getElementsBySelector("a");
                    for (i = 0; i < links.length; i++) {
                        switch (i) {
                            case 0:
                                links[i].update(animBackgroundHelper.images[animBackgroundHelper.actual + 1].name);
                                break;
                            case 1:
                                links[i].update(animBackgroundHelper.images[animBackgroundHelper.actual + 1].alt);
                                break;
                        }
                        links[i].href = getUrl(animBackgroundHelper.images[animBackgroundHelper.actual + 1].longDesc.replace("http://www.falkensteiner.com", ""));
                    }
                    animBackgroundHelper.actual ++;
                }
            }
        };
        new animBackground();
    }
    if ($('youtubeheaderlayer')) {
        var youtubeheaderlayer = Class.create();
        youtubeheaderlayer.prototype = {
            started : false,
            initialize : function () {

                var ani = new Animator({
                    transition: Animator.makeEaseOut(3),
                    duration: 1
                });
                /* ani.addSubject(new NumericalStyleSubject($('youtubeheaderstart'), 'opacity', 0, 1)); */
                ani.addSubject(new NumericalStyleSubject($('youtubeheaderend'), 'opacity', 1, 0));
                ani.play();

                /**
                 * Auto Play Settings
                 */
                if (youtubeheaderparams.autoplay || (youtubeheaderparams.autoplay == 0)) {
                    var youtubeheadertimeout = ((parseInt(youtubeheaderparams.autoplay) * 1000) + 100);
                    var youtubeheaderautoint = window.setInterval(function () {
                        youtubeheader.start();
                        if (youtubeheader.started) {
                            clearInterval(youtubeheaderautoint);
                        }
                    }, youtubeheadertimeout);
                }

                /**
                 * Check for End
                 */

                var playerinterval = window.setInterval(function() {
                    try {

                        var player = $("myythplayer");
                        var started = youtubeheader.started;

                        if ((player.getPlayerState() == 0) && started) {
                            player.stopVideo();
                            player.seekTo(0);
                            if (player.getCurrentTime() == 0) {
                                youtubeheader.stop();
                            }
                        }
                    }
                    catch (e) {
                    }
                }, 1000);
            },
            click : function (state) {
                switch (state) {
                    case 0:
                        this.end();
                        break;
                    case 1:
                        this.start();
                        break;
                    default:
                        break;
                }
            },
            start : function () {
                if (!this.started) {
                    if (ytuse) {
                        var ani = new Animator({
                            transition: Animator.makeEaseOut(3),
                            duration: 2000
                        });


                        ani.addSubject(new NumericalStyleSubject($$('#content .header'), 'height', 255, 465));
                        ani.addSubject(new NumericalStyleSubject($$('#content .header #youtubeheaderlayer'), 'height', 255, 465));
                        ani.addSubject(new NumericalStyleSubject($$('#content .header #youtubeheaderlayer .youtubeheader'), 'top', -105, 0));
                        ani.addSubject(new NumericalStyleSubject($('youtubeheaderstart'), 'opacity', 1, 0));
                        ani.addSubject(new NumericalStyleSubject($('youtubeheaderend'), 'opacity', 0, 1));

                        ani.play();
                        $$('#content .header #youtubeheaderlayer .youtubeplay')[0].hide();

                        try {
                            $$('.holidaycheck')[0].hide();
                        }
                        catch (e) {

                        }

                        var ytplayer = $("myythplayer");
                        ytplayer.playVideo();

                        this.started = true;
                    }
                }
            },
            stop : function () {
                if (this.started) {

                    if (ytuse) {
                        var ytplayer = $("myythplayer");
                        ytplayer.stopVideo();

                        var ani = new Animator({
                            transition: Animator.makeEaseOut(3),
                            duration: 2000,
                            onComplete: function() {
                                try {
                                    $$('.holidaycheck')[0].show();
                                }
                                catch (e) {
                                }
                            }
                        });
                        ani.addSubject(new NumericalStyleSubject($$('#content .header'), 'height', 465, 255));
                        ani.addSubject(new NumericalStyleSubject($$('#content .header #youtubeheaderlayer'), 'height', 465, 255));
                        ani.addSubject(new NumericalStyleSubject($$('#content .header #youtubeheaderlayer .youtubeheader'), 'top', 0, -105));
                        ani.addSubject(new NumericalStyleSubject($('youtubeheaderstart'), 'opacity', 0, 1));
                        ani.addSubject(new NumericalStyleSubject($('youtubeheaderend'), 'opacity', 1, 0));
                        ani.play();
                        $$('#content .header #youtubeheaderlayer .youtubeplay')[0].show();
                        this.started = false;
                    }
                }
            }
        };
        youtubeheader = new youtubeheaderlayer();
    }
    /**
     * I-Frame Variante
     */
    if ($('iframe') != null) {
        links = document.getElementsByTagName("a");
        for (i = 0; i < links.length; i++) {
            links[i].target = "_blank";
        }
    }
}

ytuse = false;
function onYouTubePlayerReady(playerId) {
    var ytplayer = $(playerId);
    ytuse = true;
    if ($('youtubeheaderlayer')) {
        $("myythplayer").addEventListener("onStateChange", "youtubeheader.click");
    }
}

function startHeaderYoutube() {
    youtubeheader.start();
}

function onDocumentFmtgLoad() {
    try {
        if ($('mylightbox')) {
            myLightbox = new Lightbox();
        }
    }
    catch (e) {
    }

    if ($('language') != null) {
        new dropDown($('language'));
    }
}


function getLink(link) {
    if (link.substr(1, 13) == "falkensteiner") {
        link = link.replace(/\/falkensteiner/i, "");
    }
    if (window.document.location.host != "www.falkensteiner.com") {
        link = "http://www.falkensteiner.com" + link;
    }

    if ($('iframe') != null) {
        window._blank.location.href = link;
        return;
    }

    location.href = link;
}

function getBlankLink(link) {
    if (link.substr(1, 13) == "falkensteiner") {
        link = link.replace(/\/falkensteiner/i, "");
    }
    if (window.document.location.host != "www.falkensteiner.com") {
        link = "http://www.falkensteiner.com" + link;
    }
    blankwindow = window.open(link);
}


function getUrl(link) {
    if (link.substr(1, 13) == "falkensteiner") {
        link = link.replace(/\/falkensteiner/i, "");
    }
    return link;
}
function getLanguage() {
    return language;
}

function changeFontSize(id, isIncrease) {
    /**
     * 1 = increase
     * 0 = decrease
     */

    var $obj;
    var $size;
    var $line;

    $obj = $(id);

    if ($obj) {
        $size = $obj.getStyle('font-size');
        $line = $obj.getStyle('line-height');
        if (isIncrease) {
            $size = $size = parseFloat($size) + 1;
            $line = $line = parseFloat($line) + 2;
        }
        else {
            $size = $size = parseFloat($size) - 1;
            $line = $line = parseFloat($line) - 2;
        }
        if (($size < 10) || ($size > 16)) {
            return false;
        }
        $size = $size + "px";
        $line = $line + "px";
        $obj.setStyle("font-size: " + $size);
        $obj.setStyle("line-height: " + $line);
        return true;
    }
    else {
        return false;
    }
}
function JumpBottom() {
    window.scrollTo(0, 100000);
}

