﻿function fancyIframe(element, width, height){
    $(document).ready(function() {
        $(element).fancybox({ 
            'padding': 0,
            'speedIn': 200,
            'speedOut': 200,
            'overlayShow': true,
            'overlayOpacity' : 0.5,
            'titleShow': false,
            'width': width,
            'height': height,
            'hideOnContentClick': false,
            'type': 'iframe'
            });
    });
}

function formatTitle(title, currentArray, currentIndex, currentOpts) {
    return '<div id="tip7-title" style="text-align:left;">' + (title && title.length ? '<b>' + title + '</b><br />' : '') + 'Bild ' + (currentIndex + 1) + ' / ' + currentArray.length + '</div>';
}

// Bilder in Fancybox öffnen -> container = umgebender Frames
function fancyImages(container) {
    $(document).ready(function() {
        $(container + " a").fancybox({
            'transitionIn': 'elastic',
            'transitionOut': 'elastic',
            'speedIn': 600,
            'speedOut': 200,
            'overlayShow': true,
            'titlePosition': 'inside',
            'titleFormat': formatTitle
        });
    });
}



function loadImage(id) {
    // Cookie Options
    var options = { path: '/', expires: 10 };
    if (parseInt($.cookie("lastSelection")) != id) {
        $.cookie("lastSelection", id, options);
        $("#imgFrame img").fadeOut();
        $("#imgFrame img:eq(" + id + ")").fadeIn(500);
    }
}





// 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 });
    // alert($.cookie('scrollPos'));
}

function setScroll() {
    window.scrollTo(0, parseInt($.cookie('scrollPos')));
}

$(window).scroll(function () {
    saveScroll();
});

$(document).ready(function () {

    setScroll();
});
