﻿

function loadImage(id) {
    // The code for the image to load
    if ($("#image img:eq(" + id + "):visible").length == 0) {
        $("#image img").fadeOut(500);
        $("#image img:eq(" + id + ")").fadeIn(500);
    }
}

var time = 1;


function onClickShowArchiv(button, showElement, jahre) {
    $(document).ready(function () {
        $(button).click(function () {
            $("#Archivbox > div.active").hide(time, function () {
                $("#Archivbox > div.active").removeClass("active");
                $("#jahre a").removeClass("active");
                $(showElement).show(time, function () {
                    $(showElement).addClass("active");
                    $(button).addClass("active");
                });
                // Aktives Element in Cookie speichern
                $.cookie('jahre', jahre, { path: '/', expires: 10 });
            });
        });
    });
}

function showArchiv(button, showElement, jahre) {
    $(document).ready(function () {
        $("#Archivbox > div.active").hide(time, function () {
            $("#Archivbox > div.active").removeClass("active");
            $("#jahre a").removeClass("active");
            $(showElement).show(time, function () {
                $(showElement).addClass("active");
                $(button).addClass("active");
            });
        });
    });
}


// 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();
    // Postion GW-Suche
    var mTop = 133;
    if (!isIE6) { 
        if (getScroll() > mTop) {
            $("#frmGWsearch").css("position", "fixed");
            $("#frmGWsearch").css("top", "0");
        } else {
            $("#frmGWsearch").css("position", "relative");
        }
    }
    
});

$(document).ready(function () {
    //setScroll();

    // Archiv
    if ($.cookie('jahre') != null) {
        $("#jahre a").removeClass("active");
        $("#lnk" + $.cookie('jahre')).addClass("active");
        $("#Archivbox > div").removeClass("active");
        $("#lnkContent" + $.cookie('jahre')).addClass("active");
    }



});

function doAfterAjaxUpdate() {    

    prepareDropdowns();
    $('.gw,#imgHeaderGW').fadeIn(300, function () {
        $("#imgLoading").fadeOut(500);
    });
    

    // Aktives Bild
    $("#repThumbs a").click(function () {
        $("#repThumbs a").removeClass("active");
        $(this).addClass("active");
    });

    // Hover Thumbs
    $("#repThumbs a").hover(
      function () {
          $(this).stop(true, true).fadeTo("fast", 1.0);
      },
      function () {
          if ($(this).attr("class") == "") {
              $(this).stop(true, true).fadeTo("fast", 0.5);
          }
      }
    );

    // Thumb Active
    $("#repThumbs a").click(function () {
        $("#repThumbs a").removeClass("active");
        $("#repThumbs a").not(this).fadeTo("fast", 0.5);
        $(this).addClass("active");
        $(this).fadeTo("fast", 1.0);
    });

}


function prepareDropdowns() {
    $("#drpOuterFrame select").each(function () {
        $(this).unbind("change");
        $(this).change(function () {
            $(".gw,#imgHeaderGW").fadeOut(300);
            __doPostBack($(this).attr("name"), '');
        });
    });
}

var isIE6 = false;
if ($.browser.msie && parseInt($.browser.version, 10) == 6) { isIE6 = true; }
