﻿
function fancyIframe(element, width, height){
    $(document).ready(function() { 
        $(element).fancybox({ 
            'zoomSpeedIn': 100, 
            'zoomSpeedOut': 100, 
            'overlayShow': true,
            'overlayOpacity' : 0.5, 
            'frameWidth' : width,
            'frameHeight' : height,
            'hideOnContentClick': true
            });
    });
}

function isIe6() {
    return !$.browser.msie && /MSIE 6.0/.test(navigator.userAgent);
}

function isIe() {
    return($.browser.msie == true)
}

// 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
        });
    });
}


// Bild aus Übersicht heraus laden
function loadGalleryImage(index, path){
    cGalleryIdx = index;
    img = new Image();
    img.id = "img" + shownImages;
    shownImages++;
    img.src = path;
    $("#thumbFrame").hide(0, function () {
        $(img).attr("alt", "© www.arnoldi-design.com")
        $('#galleryGO').append(img);
        $("#imgFrame").show();
        $("#img" + shownImages).css("display", "block");
    });
    $("#main2").addClass("borderTop");
    $("#main2").css("padding-top", "16px");
    $("#caption").html(index + 1 + " / " + Bilder.length);

    shownImages++;

    $("#uebersicht").click(function() {
        $("#main2").removeClass("borderTop");
        $("#main2").css("padding-top", "0px");
        $("#imgFrame").hide();
        $("#thumbFrame").show();
        $("#galleryGO img").remove();
    });

}

/* Video Startseite */
function loadBGvideo() {
    
    var vHeight = 286;
    var vWidth = 380;
    var vQuot = 380 / 286;
    var fHeight = $(window).height();
    var fWidth = $(window).width();
    if (fHeight * vQuot > $(window).width()) {
        fWidth = fHeight * vQuot;
    } else {
        fHeight = fWidth / vQuot;
    }
    if (location.pathname == "/") {
        $('.bodybg').flash({
            src: '/App_Basics/Flash/bg.swf',
            width: fWidth,
            height: fHeight,
            wmode: "transparent"
        });
    }
}

// Webwars
function beginWar() {
    window.scrollTo(0, 0);
    $("body").append('<div id="frmMusik" style="position:absolute;top:-9999px;"><object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/-sLT-10RKb8&autoplay=1"></param><embed src="http://www.youtube.com/v/-sLT-10RKb8&autoplay=1" type="application/x-shockwave-flash" width="425" height="350"></embed></object></div>')
    $("#lnkWebWars").blur();
    $("body").append('<div id="frmBeschreibung" style="width:' + $(document).width() + 'px;height:' + $(document).height() + 'px;"></div>');
    $("body").css("overflow-x", "hidden");
}

// Nächstes Bild laden
function loadNextGalleryImage(){
    var wIndex = 0;
    if (cGalleryIdx < Bilder.length - 1){
        wIndex = cGalleryIdx + 1;
        cGalleryIdx = wIndex;
    }else{
        cGalleryIdx = 0;
    }    

    img = new Image();
    img.id = "imgBig" + shownImages;    
    img.src = Bilder[wIndex]; 
    img.className = "hidden";
    $('#galleryGO').append(img);
    $(img).attr("alt", "© www.arnoldi-design.com");

    $("#imgBig" + shownImages).css("zIndex", shownImages);
    $("#imgBig" + shownImages).fadeIn(200, function () {
        $('#galleryGO img').not(img).remove()
    });
    $("#caption").html(cGalleryIdx + 1 + " / " + Bilder.length);

    shownImages++;
}

// Vorheriges Bild laden
function loadPrevGalleryImage(){
    var wIndex = Bilder.length - 1;
    if (cGalleryIdx != 0){
        wIndex = cGalleryIdx - 1;
        cGalleryIdx = wIndex;
    }else{
        cGalleryIdx = Bilder.length - 1;
    }    

    img = new Image();
    img.id = "imgBig" + shownImages;    
    img.src = Bilder[wIndex];
    img.className = "hidden";
    $('#galleryGO').append(img);
    $(img).attr("alt", "© www.arnoldi-design.com");

    $("#imgBig" + shownImages).css("zIndex", shownImages);
    $("#imgBig" + shownImages).fadeIn(200, function () {
        $('#galleryGO img').not(img).remove()
    });
    $("#caption").html(cGalleryIdx + 1 + " / " + Bilder.length);

    shownImages++;
}

// 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;
}
/*
$(window).resize(function () {
    loadBGvideo();
});

$(window).load(function () {
    loadBGvideo();
});
*/
$(document).ready(function () {
    
    /* Fading Seitenwechsel */
    isIe() ? $.cookie("fadingON", "false") : $.cookie("fadingON", "true");
    if ($.cookie("fadingON") == "true") { 
        var piFadingTime = 300;
        $("#content,#footer").fadeIn(500);
        $("#header a.fading, .lnkNextProduct, .lnkPrevProduct, .repRef a").not(".repRef a[href^=http]").each(function () {
            $(this).attr("href", "#" + $(this).attr("href"));
            var nhref = $(this).attr("nhref");
            $(this).click(function () {
                $(".videoOverlay").html("");
                $("#content,#footer").fadeOut(300, function () {
                    location.replace(nhref);
                });
            });
        });
    }

    /* Video */
    // loadBGvideo();

    // BgFix für Mobile Safari
    var browser = navigator.userAgent.toLowerCase();
    if (browser.indexOf("ipad") > 0 || browser.indexOf("iphone") > 0 || browser.indexOf("ipod") > 0) {
        $("body").css({ "width": "200px" });
        var bgUrl = $("div.bodybg").css("background-image").replace("url(", "").replace(")", "");
        if (bgUrl.indexOf("_go.jpg") > 0) {
            $("body").append($("<img src=" + bgUrl + " style='position:absolute; height:100%; width:100%; z-index:-1;' />"));
            $("div.bodybg").hide();
        }
    }

    // BgFix IE6
    if (browser.indexOf("msie 6.0") > 0) {
        $("div.bodybg").css({ "height": $(document).height() + "px", "width": $(document).width() + "px" });
    }


    // JQuery Galerie Agentur
    $(".navDN .night").click(function () {
        $("#galleryDay").fadeOut(150, function () {
            $("#galleryNav").hide(0);
            $("#galleryNavNight").show(0);
            $("#galleryNight").fadeIn(200);
            $(".night").addClass("active");
            $(".day").removeClass("active");
        });
    });

    $(".navDN .day").click(function () {
        $("#galleryNight").fadeOut(150, function () {
            $("#galleryNavNight").hide(0);
            $("#galleryNav").show(0);
            $("#galleryDay").fadeIn(200);
            $(".day").addClass("active");
            $(".night").removeClass("active");
        });
    });

    $('#galleryDay').cycle({
        fx: 'fade',
        speed: 300,
        timeout: 0,
        prev: '#prev',
        next: '#next, #galleryDay img',
        pagerAnchorBuilder: pagerFactory,
        after: onAfter
    });

    $('#galleryNight').cycle({
        fx: 'fade',
        speed: 300,
        timeout: 0,
        prev: '#prevNight',
        next: '#nextNight, #galleryNight img',
        pagerAnchorBuilder: pagerFactory2,
        after: onAfter2
    });

    $('#frmImagesCycle').cycle({
        fx: 'fade',
        speed: 1900,
        timeout: 9000,
        prev: '.frmImgLeft',
        next: '.frmImgRight, #frmImagesShadow, #frmImagesCycle img',
        pagerAnchorBuilder: pagerFactory3,
        after: onAfter3
    });

    function pagerFactory(idx, slide) {
        return '<li><a href="#">' + (idx + 1) + '</a></li>';
    };

    function onAfter(curr, next, opts) {
        var caption = (opts.currSlide + 1) + ' / ' + opts.slideCount;
        $('#caption').html(caption);
    }

    function pagerFactory2(idx, slide) {
        return '<li><a href="#">' + (idx + 1) + '</a></li>';
    };

    function onAfter2(curr, next, opts) {
        var caption = (opts.currSlide + 1) + ' / ' + opts.slideCount;
        $('#captionNight').html(caption);
    }

    function pagerFactory3(idx, slide) {
        return '<li><a href="#">' + (idx + 1) + '</a></li>';
    };

    function onAfter3(curr, next, opts) {
        var caption = (opts.currSlide + 1) + ' / ' + opts.slideCount;
        $('#caption').html(caption);
    }

    // GoGallery
    $("#prev").live('click', function () {
        loadPrevGalleryImage();
    });

    $("#next, #galleryGO img").live('click', function () {
        loadNextGalleryImage();
    });

    // Snow

    if (!isIe6()) {
        var frost = $(".frost");
        frost.find("img[src*='.png']").each(function () {
            $(this).css({ "filter": "progid:DXImageTransform.Microsoft.AlphaImageLoader (src='" + $(this).attr("src") + "')" });
        });
        frost.find(".fpart").fadeIn(500);
    }
});

