$(function () {
    var adjustImgTitleWidths = function () {
        /* bildtitel-breite an bild anpassen */
        $(".galerie_bild_titel").each(function () {
            var imgWidth = $(this).siblings("img").width();
            $(this).css({width: imgWidth});
        });
        return true;
    }

    /* fix ltie7 png */
    $("img[@src$=.png]").pngfix();
    
    /* navigation */
    $("#navi").show().find(".level2")
            .each(function(){
              tmp = $(this).parent().width();
              tmp2 = $(this).width();
              $(this).width(tmp2 + 24);
              if (tmp > tmp2 + 24) {
                  $(this).width(tmp);
/*
              } else if (tmp2 > tmp) {
                  $(this).width(tmp2).parent().width(tmp2);
*/
              }
            })
            .add(".level3").hide()
                .end()
            .end()
        .find(".level1>li").hover(function(){
            $(this).addClass("active");
            $(".level2", this).show();
        },function(){
            $(".level2", this).hide();
            $(this).removeClass("active");
        })
        .find(".level2>li").toggle(function(){
            if (!$(".level3", this).length) {
                $(this).parent().animate({height: 'toggle', opacity: 'toggle'}, "fast");
                link = $(this).children("a").attr("href");
                window.location = link;
            } else {
                $(".level3", this).each(function(){
                    $(this).show();
                }).parent().blur().addClass("active");
            }
/*
            $(this).blur().addClass("active")/*.children(".bullet").addClass("active")*;
            $(".level3", this).show();
*/
        },function(){
            $(this).blur().removeClass("active")/*.children(".bullet").removeClass("active")*/;
            $(".level3", this).hide();
        })
        .find(".level3>li").click(function(){
            $(this).siblings()
                    .removeClass("active")
                    .end()
                .addClass("active")
                .parent().parent().parent().animate({height: 'toggle', opacity: 'toggle'}, "fast");
            //alert($(this).parent().parent().parent().html());
            //return false;
            link = $(this).children("a").attr("href");
            window.location = link;
        })
        .end().end().end();
    
    /* shadows */
/** 
 * no shadows lt ie7 - they just won't get it right, esp. w/tabs
 */
if(! /MSIE\s(5\.5|6\.)/.test(navigator.userAgent)) {
    $(".shadow")
        /* main shadow */
        .wrap('<div class="shadow-main">')
//.wrap("<div/>").parent().addClass("shadow-main").end()
        .before('<div class="shadow-main-l"><!-- --><\/div><div class="shadow-main-r"><!-- --><\/div>')
//.before('<div/><div/>').prev().addClass("shadow-main-l").css({border: '1px green solid'}).prev().addClass("shadow-main-l").end().end()
        .parent()
            .before('<div class="shadow-top"><div class="shadow-top-l"><!-- --><\/div><div class="shadow-top-r"><!-- --><\/div><div class="shadow-top-m"><!-- --><\/div><\/div>')
//.before("<div/>").prev().addClass("shadow-top").append("<div/>").children().addClass("shadow-top-l").after("<div/>").next().addClass("shadow-top-r").after("<div/>").next().addClass("shadow-top-m").end().end().end().end()
            .after('<div class="shadow-bottom"><div class="shadow-bottom-l"><!-- --><\/div><div class="shadow-bottom-r"><!-- --><\/div><div class="shadow-bottom-m"><!-- --><\/div><\/div>');
    /* ie6 needs A LOT of fixes */
    if (/MSIE\s(5\.5|6\.)/.test(navigator.userAgent) && false) {
        $("#content").each(function(){
            nHeight = $("#header-holder").height() + $("#navi-holder").height() + $("#footer-holder").height();
            sHeight = $(this).parent().height() - nHeight;
            $(this).css({height: sHeight});
        });
        $("#content-main .shadow-main")
                .children().each(function(){
                    sHeight = $(this).height() + 20;
                    $(this).css({height: sHeight});
                })
                .end()
            .siblings(".shadow-top, .shadow-bottom").each(function(){
                sWidth = $(this).width() - 1;
                $(this).css({width: sWidth});
            });
        $(".shadow-main-l, .shadow-main-r").each(function(){
            sHeight = $(this).parent().height();
            $(this).css({height: sHeight});
        });
        /* even more, if we have a headline image 
        $(".shadow>.headline-img").each(function(){
            $(this).parent().siblings(".shadow-main-l, .shadow-main-r").each(function(){
                sHeight = $(this).height() - 18;
                $(this).css({height: sHeight});
            })
            .end().parent().siblings(".shadow-bottom, .shadow-top").each(function(){
                sWidth = $(this).width() + 12;
                $(this).css({width: sWidth});
            });
        });
        */
        $(".shadow>.headline-img, .shadow>.img-full").each(function(){
            $(this).parent().parent().siblings(".shadow-bottom, .shadow-top").children(".shadow-bottom-r, .shadow-top-r").css({right: "-1px"});
        });
        $(".shadow-top-l, .shadow-top-m, .shadow-top-r, .shadow-main-l, .shadow-main-r, .shadow-bottom-l, .shadow-bottom-r, .shadow-bottom-m, #content, .service-button").pngfix();
    }
}

    /* bildergalerie */
    $("#galerie_detail.hidden").hide();
    $("a.galerie_uebersicht").click(function () {
        $("#galerie_detail").find(".box").html('<img src="/media/bilder/_layout/landblick-ajax-loader.gif" class="ajax_loader"/>').end().show();
        var myHref, lastParam;

        myHref = this.href;
        lastParam = myHref.lastIndexOf("=") + 1;
        myHref = myHref.substring(lastParam);
        $("#galerie_detail").find(".box").load(myHref, {ajax: true}, function () {
            adjustImgTitleWidths();
        });
        return false;
    });
    adjustImgTitleWidths();

    //$("#content").pngfix();
if (/MSIE\s(5\.5|6\.)/.test(navigator.userAgent) && false) {
    sHeight = $("#content").parent().height() - 200;
    $("#content").css({height: sHeight});
}
});
