﻿
// Hintergrundbild anpassen
function fitBackground() {
    $("#supersize").height($(window).height());
    $("#supersize").width($(window).width());
    var defWidth = 1280;
    var defHeigth = 960;
    var defQuot = defWidth / defHeigth;
    if ($(window).height() / $(window).width() > defHeigth / defWidth) {
        $("#supersize img, .imgBackground").each(function () {
            $(this).height($(window).height());
            $.cookie("imgHeight", $(window).height());
            $(this).width(parseInt($(window).height() * defQuot));
            $.cookie("imgWidth", parseInt($(window).height() * defQuot));
        });
    } else {
        $("#supersize img, .imgBackground").each(function () {
            $(this).height(parseInt($(window).width() / defQuot));
            $.cookie("imgHeight", parseInt($(window).width() / defQuot));
            $(this).width($(window).width());
            $.cookie("imgWidth", $(window).width());
        });
    }
}

$(window).resize(function () {
    fitBackground();
});

$(window).load(function () {
    fitBackground();
});

function isIe6() {
    return !$.browser.msie && /MSIE 6.0/.test(navigator.userAgent);
}
function isIe() {
    return ($.browser.msie == true)
}

// Cookie abfragen
function get_cookie(Name) {
    var search = Name + "="
    var returnvalue = "";
    if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search)
        // if cookie exists
        if (offset != -1) {
            offset += search.length
            // set index of beginning of value
            end = document.cookie.indexOf(";", offset);
            // set index of end of cookie value
            if (end == -1) end = document.cookie.length;
            returnvalue = unescape(document.cookie.substring(offset, end))
        }
    }
    return returnvalue;
}

function GetCurrentImageIndex() {
    var cImageSrc = $("#supersize img:visible:first").attr("src");
    var index = 0;
    for (var c = 0; c < $("#supersize img").length; c++) {
        if ($("#supersize img:eq(" + c + ")").attr("src") == cImageSrc) {
            index = c;
        }
    }
    return parseInt(index);
}


$(document).ready(function () {
//    $('ul.sf-menu').superfish({
//        pathClass: 'current' 
////        delay: 100,                                    // one second delay on mouseout 
////        animation: { opacity: 'show', height: 'show' }, // fade-in and slide-down animation 
////        speed: 100,                                     // faster animation speed 
////        autoArrows: false,                              // disable generation of arrow mark-up 
////        dropShadows: false                              // disable drop shadows 
//        //
//    });

    // Scroller Angebote auf Startseite
    $('#txtTeaser .repList').cycle({
        fx: 'scrollDown',
        speed: 1000,
        timeout: 5500,
        delay: 0
    });

    // Gallerie
    $('.frmImages')
    .after('<div id="galleryNav">')
    .cycle({
        fx: 'fade',
        speed: 600,
        timeout: 7000,
        pager: '#galleryNav',
        next: ".frmImages img",

        // callback fn that creates a thumbnail to use as pager anchor 
        pagerAnchorBuilder: function (idx, slide) {
            return '<a href="#"><span>' + (idx + 1) + '</span></a>';
        }
    });

    // Routenplaner
    $("a.fancy").fancybox({
        'zoomSpeedIn': 100,
        'zoomSpeedOut': 100,
        'width': 350,
        'height': 250,
        'overlayShow': true,
        'overlayOpacity': 0.5,
        'hideOnContentClick': false
    });

    /* Fading Seitenwechsel */
    isIe() ? $.cookie("fadingON", "false") : $.cookie("fadingON", "true");
    if ($.cookie("fadingON") == "true") {
        var piFadingTime = 300;
        $("#content, #frmFooter, .imgBackground").fadeIn(500);
        $("#header a").each(function () {
            $(this).attr("href", "#" + $(this).attr("href"));
            var nhref = $(this).attr("nhref");
            $(this).click(function () {
                $("#content, #frmFooter").fadeOut(300, function () {
                    window.location = nhref;
                });
            });
        });
    }

});

// Schließt fancybox
function fancyclose() {
    window.parent.$.fn.fancybox.close();
}


/* Effekte Updatepanel */
function showAfterLoad() {
    $(document).ready(function () {
        $('.hideOnLoad').slideDown(1000);
    });
}
function hideBeforeLoad() {
    $(document).ready(function () {
        $('.hideOnLoad').slideUp(1000);
    });
}

