﻿
// Animation-Time
var time = 500;

function loadImage(id) {
    // Unsichtbares Bild mit übergebener ID einblenden
    if ($(".repImages img:eq(" + id + "):hidden").length > 0) {
        $("#frmBorder").remove();
        $(".repImages img").fadeOut();
        $(".repImages img:eq(" + id + ")").fadeIn(time);
        $(".repThumbs a.active").removeClass("active");
        $(".repThumbs a:eq(" + id + ")").addClass("active");
        $(".repThumbs a:eq(" + id + ")").prepend("<div id='frmBorder' class='frmBorder'></div>");
    }
}


//* NAVIGATION HOVER *//
function navHover() {
    $('#MainNav li').not('#MainNav li.active').hover(function () {
        $(this).find("a").not($(this).find("ul li a")).animate({ color: '#a51030' }, 140);
    }, function () {
        $(this).find("a").stop(true, false).animate({ color: '#868889' }, 140)
    });

    $('#SubNav li').not('#SubNav li.active').hover(function () {
        $(this).find("a").not($(this).find("ul li a")).animate({ backgroundColor: '#6f6143' }, 200);
    }, function () {
        $(this).find("a").stop(true, false).animate({ backgroundColor: '#8f8167' }, 200)
    });
}

// Dropdown Monate
function drpMonth() {

    /* SLIDE */
    $(".dropdown .selected a").click(function () {
        $(this).parent().parent().find("li.inactive").slideDown(200, function () {
            $('.scroll-pane').jScrollPane();           
        });
    });

    /* CLICK */
    $(document).bind('click', function (e) {
        var $clicked = $(e.target);
        if (!$clicked.parents().hasClass("dropdown"))
            $(".dropdown .inactive").hide();
    });

    /* HOVERs */
    $(".selected a").hover(
        function () {          
            $(this).css("background-position", "220px -21px").stop(true, false).animate({ backgroundColor: "#6f6143" }, 150);      
        },
        function () {
            $(this).css("background-position", "220px 13px").stop(true, false).animate({ backgroundColor: "#8f8167" }, 150);
        });
    
    $(".options li a").hover(
        function () {
            $(this).stop(true, false).animate({ backgroundColor: "#6f6143" }, 150);
        },
        function () {
            $(this).stop(true, false).animate({ backgroundColor: "#8f8167" }, 150);
        });

        var cCat;
        var cDate;
        var navTime = 200;

        $(".options li a").unbind("click").click(function () {

            var cLink = $(this);

            // Kategorie click
            if (cLink.attr("cat") != undefined) {
                cCat = cLink.attr("cat");
                cLink.parents().find("> .selected a").html(cLink.html());
                $.cookie("cat" + displayType, cCat);
                // Datum click
            } else if (cLink.attr("date") != undefined) {
                cDate = cLink.attr("date");
                cLink.parents().find("> .selected a").html(cLink.html());
                $.cookie("date" + displayType, cDate);
            }

            // Alle Daten wieder einblenden
            if (cLink.attr("date") == "") {
                $("#repKulCats li").show();
            }

            // Alle Kategorien wieder einblenden
            if (cLink.attr("cat") == "") {
                $("#repKulMonth li").show();
            }

            // Bei Datumauswahl nur passende Kategorien anzeigen
            if (cLink.attr("cats") != undefined) {
                // Array aller möglichen Kategorien
                $("#repKulCats li").hide();
                var ccCats = cLink.attr("cats").split(",");
                var ccLinks = $("#repKulCats li a");
                for (var i = 0; i < ccCats.length; i++) {
                    for (var j = 0; j < ccLinks.length; j++) {
                        if ($("#repKulCats li a:eq(" + j + ")").attr("cat") == ccCats[i] || $("#repKulCats li a:eq(" + j + ")").attr("cat") == "") {
                            $("#repKulCats li a:eq(" + j + ")").parent().show();
                        }
                    }
                }
            }

            // Bei Kategorieauswahl nur passende Daten anzeigen
            if (cLink.attr("dates") != undefined) {
                // Array aller möglichen Kategorien
                $("#repKulMonth li").hide();
                var ccMonth = cLink.attr("dates").split(",");
                var ccLinks = $("#repKulMonth li a");
                for (var i = 0; i < ccMonth.length; i++) {
                    for (var j = 0; j < ccLinks.length; j++) {                        
                        if ($("#repKulMonth li a:eq(" + j + ")").attr("date") == ccMonth[i] || $("#repKulMonth li a:eq(" + j + ")").attr("date") == "") {
                            $("#repKulMonth li a:eq(" + j + ")").parent().show();
                        }
                    }
                }
            }

            // $("h1").html("# " + cDate + " # " + cCat + " #")

            // Nur Kategorie definiert
            if ((cDate == undefined || cDate == "") && cCat != undefined && cCat != "") {
                var cLength = $(".frmNews").length;
                for (var i = 0; i < cLength; i++) {
                    var cItem = $(".frmNews:eq(" + i + ")");
                    if (cItem.attr("cat") == cCat) {
                        cItem.slideDown(navTime);
                    } else {
                        cItem.slideUp(navTime);
                    }
                }
            }

            // Nur Datum definiert
            if ((cCat == undefined || cCat == "") && cDate != undefined && cDate != "") {
                $(".frmNews").slideUp(150, function () {
                    $(".frmNews").each(function () {
                        if ($(this).find("span[date='" + cDate + "']").length > 0) {
                            $(this).slideDown(navTime);
                        } else {
                            $(this).hide(0);
                        }
                    });
                });
            }


            // Datum und Kategorie definiert
            if (cCat != undefined && cCat != "" && cDate != undefined && cDate != "") {
                var cLength = $(".frmNews").length;
                for (var i = 0; i < cLength; i++) {
                    var cItem = $(".frmNews:eq(" + i + ")");
                    if (cItem.attr("cat") == cCat && cItem.find("span[date='" + cDate + "']").length > 0) {
                        cItem.slideDown(navTime);
                    } else {
                        cItem.slideUp(navTime);
                    }
                }
            }
            
            // Nichts definiert
            if ((cCat == "" || cCat == undefined) && (cDate == "" || cDate == undefined)) {
                $(".frmNews").slideDown(150);
            }

            $(".dropdown .inactive").hide();

            // Aktive Daten anzeigen
            $("#content .frmNews .right span").hide(0, function () {
                if (cDate != undefined && cDate != "") {
                    $("span[date='" + cDate + "']").show(0);
                }
            });
        });

        // Gespeicherte Kategorien / Daten laden
        if ($.cookie("cat" + displayType) != null) {
            $("a[cat='" + $.cookie("cat" + displayType) + "']").trigger("click");
        }

        if ($.cookie("date" + displayType) != null) {
            $("a[date='" + $.cookie("date" + displayType) + "']").trigger("click");
        }

}


// Teaser Footer
function frmTeaser() {
    $(".boxOpen").css({ "display": "none" });
    $(".frmTeaser").each(function () {
        $(".frmTeaser").hover(function () {
            $(this).find(".boxOpen").fadeIn(400).css({ "margin-top": "-140px" });
        }, function () {
            $(this).find(".boxOpen").fadeOut(200).stop(true, true);
        });
    });

    // Link von Box
    $(".frmTeaser").click(function () {
        if ($(this).find("a:first").attr("href").length > 0) {
            location.href = $(this).find("a:first").attr("href");
        }
    });

    $(".frmTeaser").hover(function () {
        var attrHref = $(this).find("a:first").attr("href");
        if (!attrHref) {
            $(this).css("cursor", "default");
        }
    });
}

$(window).load(function () {

    saveScroll();

    $("#accordion").accordion({
        autoheight: false
    });
});


// Scrollposition speichern
function getScroll() {
    var scrOfY = 0;
    if (typeof (window.pageYOffset) == 'number') {
        //Netscape compliant   
        scrOfY = window.pageYOffset;
    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        //DOM compliant   
        scrOfY = document.body.scrollTop;
    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        //IE6 standards compliant mode   
        scrOfY = document.documentElement.scrollTop;
    }
    return scrOfY;
}


function saveScroll() {
    $.cookie('scrollPos', getScroll(), { path: '/', expires: 10 });
}

function setScroll() {
    window.scrollTo(0, parseInt($.cookie('scrollPos')));
}

$(window).scroll(function () {
    saveScroll();
});


/* Effekte Updatepanel */
function showAfterLoad() {
    $(document).ready(function () {
        $('.hideOnLoad').slideDown(1000);
    });
}
function hideBeforeLoad() {
    $(document).ready(function () {
        
    });
}

$(document).ready(function () {
    $('.hideOnLoad').slideUp(1000);
    // setScroll();

    $("#accordion").accordion({
        autoheight: false
    });

    $(".repThumbs li").each(function () {
        $(this).find("a.active").prepend("<div id='frmBorder' class='frmBorder'></div>");
    });


    frmTeaser();
    navHover();

    // Breite der Thumbnail-Box bestimmen
    var repWidth = ($(".repThumbs li").length);
    $(".repThumbs").css({ "width": (repWidth * 50) + (repWidth * 5) + "px" });


    var link = $('a.lnkSocial');
    var linkBtn = $('a.lnkBtn, .frmText a.lnkBtn ');
    link.append('<div class="lnkSocialHover" />');
    var linkHover = $('.lnkSocialHover');
    linkBtn.css('background', 'url(/images/construct/lnkBtn2.gif) no-repeat 15px 2px');
    linkBtn.css('background-color', '#8f8167');
    linkHover.css('opacity', '0');
    link.each(function () {
        $(this).hover(function () {
            $(this).find(linkHover).stop(true, false).animate({ "opacity": "1.0"}, 130);
        }, function () {
            $(this).find(linkHover).stop(true, false).animate({ "opacity": "0"}, 130);
        });
    });
    linkBtn.each(function () {
        $(this).hover(function () {
            $(this).stop(true, false).animate({ "background-color": "#a51030" }, 130);
        }, function () {
            $(this).stop(true, false).animate({ "background-color": "#8f8167" }, 130);
        });
    });


//    $("a.fancy, .fancyWL").fancybox({
//        'transitionIn': 'none',
//        'titlePosition': 'over',
//        'titleFormat': function (title, currentArray, currentIndex, currentOpts) {
//            return '<span id="fancybox-title-over">' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
//        }
//    });

    $('.fancy, .fancyWL').fancybox({
        closeBtn: true,
        arrows: false,
        nextClick: true,
        loop: false,
        prevEffect: 'none',
        nextEffect: 'none',

        helpers: {
            title: {
                type: 'inside'
            },
            overlay: {
                speedIn: 500,
                opacity: 0.73
            },
            thumbs: {
                width: 120,
                height: 80
            }
        }
    });

    $('.fancyBuchung').fancybox({
        type: 'iframe',
        width: 920,
        height: 620,
        openEffect: 'none',
        closeEffect: 'none'
    });

    // Einlbendung Header Bild
    $(".repImages img, img.imgHeader").css({ "display": "none" });
    $(".repImages img:first, img.imgHeader").delay(250).fadeIn(600);

    drpMonth();

    $(".showAll").click(function () {
        $(this).parent().find("span").fadeIn(800);
        $(this).hide();
    });

});


// Infinit Slider Loop
$(document).ready(function () {
    $(".one img:first").fadeIn(400, function () {
        $(".two img:first").fadeIn(400, function () {
            $(".three img:first").fadeIn(400, function () {
                startX(".one", 0);
                startX(".two", 1000);
                startX(".three", 2000);
            });
        });
    });    
});

function startX(container, cDelay) {
    $(container).cycle({ fx: 'fade', delay: cDelay, timeout: 5000 });
}

