﻿


function loadImages(arrImages, forceClear, relAdd) {
    var piTime = 400;
    var firstImagePath = ""

    if (forceClear) {
        $("#supersize img").remove();
    }

    for (var i = 0; i < arrImages.length; i++) {
        // Bilder
        var url = getURL();
        var img = $("<img></img>");
        img.attr("id", "img" + i);
        img.attr("src", arrImages[i]);
        img.css("display", "none");


        // Pfad der aktuellen Seite
        // alle anderen Bilder werden später entfernt
        img.attr("rel", url + relAdd);
     
        // erstes Bild onload einblenden
        if (i == 0) {
            img.bind("load", function () {
                $(this).fadeIn(800, function () {
                    // Bilder, die nicht zur aktuellen Seiten gehören, werden gelöscht
                    $("#supersize img").each(function () {
                        if ($(this).attr("rel") != url + relAdd) {
                            $(this).remove();
                        }
                    });
                });
            });
        }
        $("#supersize").append(img);
        fitBackground(); 
    }

    if (arrImages.length < 2) {
        $(".lnkNext,.lnkPrev").hide();
    } else {
        $(".lnkNext,.lnkPrev").show();
    }
}


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);
}

function GetNextImageIndex() {
    var index = 0;
    if (GetCurrentImageIndex() == ($("#supersize img").length - 1)) {
        index = 0;
    } else {
        index = GetCurrentImageIndex() + 1;
    }
    return parseInt(index);
}

function GetPrevImageIndex() {
    var index = 0;
    if (GetCurrentImageIndex() == 0) {
        index = $("#supersize img").length - 1;
    } else {
        index = GetCurrentImageIndex() - 1;
    }
    return parseInt(index);
}


// Hintergrundbild anpassen
function fitBackground() {
    
    $("#supersize").height($(window).height());
    $("#supersize").width($(window).width());
    /**/
    var defWidth = 1264;
    var defHeigth = 935;
    var defQuot = defWidth / defHeigth;

    // $(".logo").html($(document).height());
    /* */
    if ($(document).height() / $(document).width() > defHeigth / defWidth) {
        $("#supersize img, .imgBackground").each(function () {
            $(this).height($(document).height());
            $(this).width(parseInt($(document).height() * defQuot));
            $.cookie("imgHeight", $(document).height());
            $.cookie("imgWidth", parseInt($(document).height() * defQuot));
        });
    } else {
        $("#supersize img, .imgBackground").each(function () {
            $(this).width($(document).width());
            $(this).height(parseInt($(document).width() / defQuot));
            $.cookie("imgHeight", parseInt($(document).width() / defQuot));
            $.cookie("imgWidth", $(document).width());
        });
    }
   
}

function getURL() {
    return document.location.hash.replace(/#/g, "");
}

var isSafari = false;
if ($.browser.safari) { isSafari = true; }

var isMobile = false;
if (navigator.userAgent.match(/iPhone/i)) { isMobile = true; }
if (navigator.userAgent.match(/iPod/i)) { isMobile = true; }
if (navigator.userAgent.match(/iPad/i)) { isMobile = true; }
if (navigator.userAgent.match(/Android/i)) { isMobile = true; }
