$(document).ready(function(){
    if ($.browser.msie && parseInt($.browser.version) < 8) {
        $("#content").height($("#wrap").height());
        $(".b100_dynamite").height($("#wrap").height() - 50);
        $("#bildwrap").height($("#wrap").height()-82);
    }
    adjust_image_dims();
    $("#prevLink,#nextLink").click(function(){show_img(this.rel); $("#produkt_texte").hide();});
    $("#produkt_info").click(function(){
        $("#produkt_texte").toggle();
    });
});

$(window).resize(function(){set_bild_nav();})

function adjust_image_dims() {
   $("img.produkt_bild").each(function() {
       hoehe = parseInt($(this).height());
       breite = parseInt(hoehe / bild_groessen[this.id]["h"] * bild_groessen[this.id]["b"]);
       if (breite > 840) {
           $(this).css("width", "840px");
           $(this).css("height", (840 / breite * hoehe) + "px");
       }
       else {
           $(this).css("height", "100%");
           $(this).css("width", "auto");
       }
   });
   set_bild_nav();
}
function set_bild_nav() {
   if ($("img.produkt_bild").length > 1) {
       hoehe = $("img.produkt_bild:visible").height();
       breite = breite > 840 ? 840 : parseInt(hoehe / bild_groessen[$("img.produkt_bild:visible")[0].id]["h"] * bild_groessen[$("img.produkt_bild:visible")[0].id]["b"]);
       $("#bildwechsler").css({"width":breite + "px", "height": hoehe + "px"});
       set_pager();
   }
   else {
       $("#bildwechsler").hide();
   }
}
function set_pager() {
    nr = parseInt($("img.produkt_bild:visible")[0].id.substr(1));
    $("#prevLink").attr("rel", nr - 1);
    $("#nextLink").attr("rel", nr + 1);
    $("#prevLink,#nextLink").show();
    if (nr == 0) {$("#prevLink").hide();}
    else if (nr == $("img.produkt_bild").length - 1) {$("#nextLink").hide();}
    $("#bildwechsler").show();
}
function show_img(nr) {
    $("img.produkt_bild").hide();
    $("#current_nr").html(1*nr+1);
    $("#b" + nr).show();
    set_bild_nav();
}