﻿function isIphone() {
    var detected = false;
    if (navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i) || navigator.userAgent.match(/iPad/i)) {
        detected = true;
    }
    return detected;
}
function fancyIframe(element, width, height) {
    if (isIphone()) {
        $(element).click(function () {
            window.open($(this).attr("href"));
            return false;
        });
    } else {
        $(document).ready(function () {
            $(element).fancybox({
                'zoomSpeedIn': 0,
                'zoomSpeedOut': 0,
                'overlayShow': true,
                'overlayColor': "#000",
                'padding': 1,
                'frameWidth': width,
                'frameHeight': height,
                'hideOnContentClick': false
            });
        });
   } 
}


// Bilder in Fancybox öffnen -> container = umgebender Frames
function fancyImages(container) {
    $(document).ready(function() {
        $(container + " a").fancybox({
            'zoomSpeedIn': 100,
            'zoomSpeedOut': 100,
            'overlayShow': true,
            'overlayOpacity': 0.5,
            'hideOnContentClick': true
        });
    });
}

// Animation-Time
var time = 500;

function loadImage(id) {
    // Unsichtbares Bild mit übergebener ID einblenden
    if ($(".genImages img:eq(" + id + "):hidden").length > 0) { 
        $(".genImages img").fadeOut();
        $(".genImages img:eq(" + id + ")").fadeIn(time);
        $(".thumbs a.active").removeClass("active");
        $(".thumbs a:eq(" + id + ")").addClass("active");
    }
}

$(document).ready(function () {
    var autoWidth = ($(window).width() < 1200 ? $(window).width() : 1200);
    var autoHeight = parseInt((autoWidth / 100) * 70);

    $(".thumbs").each(function () {
        var visibleLinks = 0;
        $(this).find("a").each(function (idx) {
            if (!($(this).attr("flash") == "true" && isIphone())) {
                $(this).delay(idx * 200).fadeIn(400);
                visibleLinks++;
            }
        });
        if (visibleLinks == 0) {
            $(this).parent().hide();
        }
    });

    $("a.lnkPopUpLarge[flash=='true']").css({ "hidden": "true" });

    fancyIframe(".lnkPopUpLarge", 800, 600);
    fancyIframe(".lnkPopUp", 500, 400);
    fancyIframe(".routenplaner a", 500, 190);
    fancyImages(".lageplan", 500, 190);
});
