/*** dsv5-JS (C) Stefan Mateescu / Taurus IT GmbH <stm@taurus-it.de> ***/

var dsv_globalHideLayerTimeout = 250;

function dsv_initTabElement(rel) {
    jQuery('DIV.dsv_appcontent_reiter A.tab_'+rel+'').each(function(i) {
        jQuery(this).attr('dsvreiterpos', i);
        // IE6-Umbruch FIX
        var temp = jQuery(this).children("SPAN").html().replace(/\s+/g, "&nbsp;");
        jQuery(this).children("SPAN").html(temp);
    });
    jQuery('DIV.dsv_appcontent_reiter_unten A.tab_'+rel+'').each(function(i) {
        jQuery(this).attr('dsvreiterpos', i);
    });
    jQuery('DIV.dsv_appcontent_tabPane.blatt_'+rel+'').each(function(i) {
        jQuery(this).attr('dsvreiterpos', i);
        if (jQuery(this).attr('id')=="")
            jQuery(this).attr('id', "_autoId_dsv5reiterTool_pane_"+rel+"_"+i);
    });
    jQuery('DIV.dsv_appcontent_reiter A.tab_'+rel+', DIV.dsv_appcontent_reiter_unten A.tab_'+rel+'').bind('click', function() {
        var clickedTab = jQuery(this);
        var activeTab = false;
        var clickedLowtab = false;
        var activeLowtab = false;
        if (jQuery(clickedTab).is('DIV.dsv_appcontent_reiter A')) {
            activeTab = jQuery('DIV.dsv_appcontent_reiter A.tab_'+rel+'.aktiv');
            clickedLowtab = jQuery('DIV.dsv_appcontent_reiter_unten A[dsvreiterpos='+jQuery(clickedTab).attr('dsvreiterpos')+'].tab_'+rel+'');
            activeLowtab = jQuery('DIV.dsv_appcontent_reiter_unten A.tab_'+rel+'.aktiv');
        }
        else {
            clickedLowtab = clickedTab;
            activeLowtab = jQuery('DIV.dsv_appcontent_reiter_unten A.tab_'+rel+'.aktiv');
            clickedTab = jQuery('DIV.dsv_appcontent_reiter A[dsvreiterpos='+jQuery(clickedLowtab).attr('dsvreiterpos')+'].tab_'+rel+'');
            activeTab = jQuery('DIV.dsv_appcontent_reiter A.tab_'+rel+'.aktiv');
        }
        var clickedPane = jQuery('DIV[dsvreiterpos='+jQuery(clickedTab).attr('dsvreiterpos')+'].dsv_appcontent_tabPane.blatt_'+rel+'');
        var activePane = jQuery('DIV[dsvreiterpos='+jQuery(activeTab).attr('dsvreiterpos')+'].dsv_appcontent_tabPane.blatt_'+rel+'');
        jQuery(activeTab).removeClass('aktiv');
        jQuery(clickedTab).addClass('aktiv');
        jQuery(activeLowtab).removeClass('aktiv');
        jQuery(clickedLowtab).addClass('aktiv');
        jQuery(activePane).fadeOut(200, function() {
            jQuery(clickedPane).fadeIn(200, function() {});
        });
    });
}

function dsv_toggleNavigation() {
    var actStateBig = jQuery('#dsv_appmenu_navi_gross').css('display');
    if (actStateBig=="block") {
        document.cookie = 'dsv5NaviState=closed';
        jQuery('#dsv_appmenu_navi_gross').fadeOut('fast', function() {
            jQuery('#dsv_appmenu_navi_klein').fadeIn('fast', function() {
                jQuery('#dsv_appcontent_untererContent').animate({width: '985px'}, 'fast');
            });
        });
    }
    else {
        document.cookie = 'dsv5NaviState=open';
        if (jQuery('#dsv_appcontent_untererContent').length>0) {
            jQuery('#dsv_appcontent_untererContent').animate({width: '765px'}, 'fast', function() {
                jQuery('#dsv_appmenu_navi_klein').fadeOut('fast', function() {
                    jQuery('#dsv_appmenu_navi_gross').fadeIn('fast');
                });
            });
        }
        else {
            jQuery('#dsv_appmenu_navi_klein').fadeOut('fast', function() {
                jQuery('#dsv_appmenu_navi_gross').fadeIn('fast');
            });
        }
    }
}

function dsv_toggleNavigationKompakt() {
    jQuery('div#dsv_appmenu_navi_popup_container').animate({
        height: "toggle",
        opacity: "toggle"
    }, "fast");
}

function dsv_popupOpen(popupId, _this) {
    var $popup = jQuery("#" + popupId),
        $popupHeader = $popup.find("div.dsv_appcontent_popup_header"),
        position = jQuery(_this).position();

    $popupHeader.hover(function() {jQuery(this).addClass("dsv_appcontent_popup_inner3_mouseover")}, function() {jQuery(this).removeClass("dsv_appcontent_popup_inner3_mouseover")});

    $popup.css({
        top: position.top,
        left: position.left
    }).draggable({
        cursor: "move",
        handle: "div.dsv_appcontent_popup_header"
    });

    $popup.fadeIn("fast");
    $popup.find(".dsv_appcontent_popup_close").click(function() {
        $popup.fadeOut("fast");
    });
    return false;
}

function dsv_showAppnamebox(id, opener) {
    jQuery(id).appendTo(document);
    // determine position
    var GRACE = 5;
    var oPos = jQuery(opener).offset();
    var oWidth = jQuery(opener).outerWidth();
    var oHeight = jQuery(opener).outerHeight();
    var boxWidth = jQuery('#'+id).outerWidth();
    var boxHeight = jQuery('#'+id).outerHeight();
    var idealX = 0;
    var idealY = jQuery("#dsv_apphead_breadcrumbAussen").position().top + 35;
    jQuery('#'+id).appendTo('body');
    // iefixclass
    if (jQuery.browser.msie) {
        jQuery('#'+id).addClass('dsv_general_floatingbox_iefix');
    }
    // show
    jQuery('#'+id).css({
        position: 'absolute',
        top: idealY+'px',
        left: idealX+'px',
        zIndex: 9999,
        width: 220+'px',
        height: 70+'px',
        opacity: 0.01,
        display: 'block',
        overflow: 'hidden',
        zoom: 1
    });
    jQuery('#'+id).animate({
        width: boxWidth,
        height: boxHeight,
        opacity: 1
    }, 'fast', function() {
        if (jQuery.browser.msie) {
            jQuery('#'+id).css('opacity', 'auto')
            jQuery('#'+id).removeClass('dsv_general_floatingbox_iefix');
        }
    });
}

function dsv_showFloatingbox(id, opener) {
    // hide all others
    jQuery('DIV.dsv_general_floatingbox_outer').hide();
    // determine position
    var GRACE = 5;
    var oPos = jQuery(opener).offset();
    var oWidth = jQuery(opener).outerWidth();
    var oHeight = jQuery(opener).outerHeight();
    var boxWidth = jQuery('#'+id).outerWidth();
    var boxHeight = jQuery('#'+id).outerHeight();
    var idealX = parseInt(oPos.left + oWidth/2 - boxWidth/2);
    var idealY = parseInt(oPos.top + oHeight/2 - boxHeight/2) - 120;
    var windowWidth = jQuery(window).width();
    var windowHeight = jQuery(window).height();
    // fix determined position
    if (idealX<GRACE)
        idealX = GRACE;
    if (idealX+boxWidth+GRACE>windowWidth)
        idealX = windowWidth-boxWidth-GRACE;
    if (idealY<GRACE)
        idealY = GRACE;
    if (idealY+boxHeight+GRACE>windowHeight-120+jQuery(document).scrollTop())
        idealY = windowHeight-120+jQuery(document).scrollTop()-boxHeight-GRACE;
    // iefixclass
    if (jQuery.browser.msie) {
        jQuery('#'+id).addClass('dsv_general_floatingbox_iefix');
    }
    // moving
    jQuery('#'+id).attr('moving', '1');
    // show
    jQuery('#'+id).css({
        top: idealY+'px',
        left: idealX+'px'
    });
    jQuery('#'+id).fadeIn(function() {
        if (jQuery.browser.msie) {
            jQuery('#'+id).removeClass('dsv_general_floatingbox_iefix');
        }
        jQuery('#'+id).attr('moving', '0');
    });
}

function dsv_mouseoverFloatingbox(boxElement) {
    if (jQuery(boxElement).attr('moving')=="1")
        return;
    if (typeof jQuery(boxElement).attr('hidetimeout') == "undefined")
        jQuery(boxElement).attr('hidetimeout', '-1');
    if (jQuery(boxElement).attr('hidetimeout')!='-1') {
        clearTimeout(jQuery(boxElement).attr('hidetimeout'));
        jQuery(boxElement).attr('hidetimeout', '-1');
    }
}

function dsv_mouseoutFloatingbox(boxElement) {
    if (jQuery(boxElement).attr('moving')=="1")
        return;
    if (typeof jQuery(boxElement).attr('hidetimeout') == "undefined")
        jQuery(boxElement).attr('hidetimeout', '-1');
    if (jQuery(boxElement).attr('hidetimeout')!='-1')
        return;
    jQuery(boxElement).attr('hidetimeout', setTimeout(function() { dsv_hideFloatingbox(boxElement); }, dsv_globalHideLayerTimeout));
}

function dsv_hideFloatingbox(boxElement) {
    if (jQuery(boxElement).attr('moving')=="1")
        return;
    jQuery(boxElement).attr('hidetimeout', '-1');
    jQuery(boxElement).attr('moving', '1');
    // iefixclass
    if (jQuery.browser.msie) {
        jQuery(boxElement).addClass('dsv_general_floatingbox_iefix');
    }
    jQuery(boxElement).fadeOut(function() {
        if (jQuery.browser.msie) {
            jQuery(boxElement).removeClass('dsv_general_floatingbox_iefix');
        }
        jQuery(boxElement).attr('moving', '0');
    });
}

function dsv_toggleSitemapElement(id, stopRecursion) {
    if (typeof stopRecursion == "undefined")
        stopRecursion = false;
    var lth = lts = "";
    if (jQuery("#dsv5sitemap__"+id+"__closed").css("display")=="block") {
        lth = "dsv5sitemap__"+id+"__closed";
        lts = "dsv5sitemap__"+id+"__open";
    }
    else {
        lth = "dsv5sitemap__"+id+"__open";
        lts = "dsv5sitemap__"+id+"__closed";
    }
    dsv_switchLayersJQ(lth, lts, 200, false, true, function () {
        jQuery('#'+lth).css('display', 'none');
        // hide another one?
        if (!stopRecursion && jQuery('#'+lts).is('DIV.dsv_appcontent_sitemap_leafElement')) {
            jQuery("DIV.dsv_appcontent_sitemap_leafElement:visible").each(function() {
                var localid = jQuery(this).children('.sitemapid').html();
                if (parseInt(localid)!=parseInt(id))
                    dsv_toggleSitemapElement(localid, true);
            });
        }
    });
}

var dsv_globalScrollToTimeout = -1;
var dsv_globalScrollNoChange = 0;

function dsv_switchLayersJQ(layerToHideName, layerToShowName, duration, overflowParent, repairWidthHeightAfterAnim, callbackWhenDone) {
    // default params
    if (typeof duration == "undefined" || duration==false)
        duration = 300;
    if (typeof callbackWhenDone == "undefined")
        callbackWhenDone = false;
    if (typeof overflowParent == "undefined" || overflowParent==false)
        overflowParent = window;
    else if    (typeof overflowParent == "string")
        overflowParent = document.getElementById(overflowParent);
    if (typeof repairWidthHeightAfterAnim == "undefined")
        repairWidthHeightAfterAnim = true;
    // check+set avtivity
    if (jQuery("#"+layerToHideName).attr("stmShowHideActive")==1 || jQuery("#"+layerToShowName).attr("stmShowHideActive")==1) {
        setTimeout(function () { dsv_switchLayersJQ(layerToHideName, layerToShowName, duration, overflowParent, repairWidthHeightAfterAnim, callbackWhenDone); }, 500);
        return;
    }
    if (jQuery("#"+layerToShowName).css("display")!="none" || jQuery("#"+layerToHideName).css("display")=="none") {
        return false;
    }
    jQuery("#"+layerToHideName).attr("stmShowHideActive", "1");
    jQuery("#"+layerToShowName).attr("stmShowHideActive", "1");
    // change order in DOM
    var copyOfToShow = jQuery("#"+layerToShowName).clone();
    jQuery("#"+layerToShowName).remove()
    copyOfToShow.insertAfter(jQuery("#"+layerToHideName));
    // get all relevant sizes
    var lthWidth = jQuery("#"+layerToHideName).width();
    var lthHeight = Math.max(1, jQuery("#"+layerToHideName).height());
    var lthTempPos = jQuery('#'+layerToHideName).position();
    var lthPosX = lthTempPos.left;
    var lthPosY = lthTempPos.top;
    if (overflowParent != window) {
        lthPosX = document.getElementById(layerToHideName).offsetLeft;
        lthPosY = document.getElementById(layerToHideName).offsetTop;
    }
    var lthOverflow = jQuery("#"+layerToHideName).css("overflow");
    // prepare lts
    jQuery("#"+layerToShowName).css({
        'width': lthWidth+'px',
        'display': 'block',
        'opacity': 0.1,
        'position': 'absolute',
        'top': lthPosY+'px',
        'left': lthPosX+'px'
    });
    var ltsWidth = jQuery("#"+layerToShowName).width();
    var ltsHeight = Math.max(1, jQuery("#"+layerToShowName).height());
    var ltsOverflow = jQuery("#"+layerToShowName).css("overflow");
    dsv_initiateScrollingJQ(layerToShowName, overflowParent);
    // do the anims
    jQuery("#"+layerToHideName).css({
        'height': lthHeight+'px',
        'width': lthWidth+'px',
        'display': 'block',
        'overflow': 'hidden'
    });
    jQuery("#"+layerToShowName).css({
        'width': ltsWidth+'px',
        'height': lthHeight+'px',
        'overflow': 'hidden'
    });
    jQuery("#"+layerToHideName).animate({
        'height':ltsHeight,
        'opacity':0
    }, duration * 0.99, "linear");
    jQuery("#"+layerToShowName).animate({
        'height':ltsHeight,
        'opacity':0.99
    }, duration, "linear", function () {
        jQuery("#"+layerToHideName).css({
            'height': lthHeight+'px',
            'display': 'none',
            'overflow': lthOverflow
        });
        jQuery("#"+layerToShowName).css({
            'position': 'static',
            'display': 'block',
            'overflow': ltsOverflow,
            'opacity': 1.0
        });
        if (repairWidthHeightAfterAnim)
            dsv_repairWidthAndHeightJQ(layerToShowName);
        jQuery("#"+layerToHideName).attr("stmShowHideActive", "0");
        jQuery("#"+layerToShowName).attr("stmShowHideActive", "0");
        if (typeof callbackWhenDone == "function") {
            callbackWhenDone();
        }
    });
    return true;
}

function dsv_initiateScrollingJQ(layername, overflowParent) {
    if (typeof overflowParent == "undefined" || overflowParent==false)
        overflowParent = window;
    else if    (typeof overflowParent == "string")
        overflowParent = document.getElementById(overflowParent);
    var tmp = jQuery('#'+layername).offset();
    var divTop = tmp.top;
    var divLeft = tmp.left;

    var divHeight = jQuery("#"+layername).height();
    var wndHeight = jQuery(overflowParent).height();
    var wndOffsetY = jQuery(overflowParent).scrollTop();
    var divWidth = jQuery("#"+layername).width();
    var wndWidth = jQuery(overflowParent).width();
    var wndOffsetX = jQuery(overflowParent).scrollLeft();

    var newScrollTop = wndOffsetY;
    var newScrollLeft = wndOffsetX;

    if (divHeight > wndHeight-20) {
        newScrollTop = divTop - 10;
    }
    else if (divTop < wndOffsetY-10) {
        newScrollTop = wndOffsetY - 10;
    }
    else if (divTop-wndOffsetY+divHeight > wndHeight) {
        var offOffset = divTop-wndOffsetY+divHeight - wndHeight + 10;
        newScrollTop = wndOffsetY+offOffset;
    }

    if (divWidth > wndWidth-20) {
        newScrollLeft = divLeft - 10;
    }
    else if (divLeft < wndOffsetX-10) {
        newScrollLeft = wndOffsetX - 10;
    }
    else if (divLeft-wndOffsetX+divWidth > wndWidth) {
        var offOffset = divLeft-wndOffsetX+divWidth - wndWidth + 10;
        newScrollLeft = wndOffsetX+offOffset;
    }

    if (newScrollTop!=wndOffsetY || newScrollLeft!=wndOffsetX) {
        dsv_scrollToJQ(newScrollLeft, newScrollTop, overflowParent);
    }
}

function dsv_scrollToJQ(x, y, overflowParent, oldX, oldY) {
    if (dsv_globalScrollToTimeout != -1) {
        clearTimeout(dsv_globalScrollToTimeout);
        dsv_globalScrollToTimeout = -1;
    }
    if (typeof overflowParent == "undefined" || overflowParent==false)
        overflowParent = window;
    else if    (typeof overflowParent == "string")
        overflowParent = document.getElementById(overflowParent);
    var wndStartX = jQuery(overflowParent).scrollLeft();
    var wndStartY = jQuery(overflowParent).scrollTop();
    var diffX = x-wndStartX;
    var diffY = y-wndStartY;
    if (typeof oldX != "undefined" && typeof oldY != "undefined") {
        if (oldX==wndStartX && oldY==wndStartY) {
            dsv_globalScrollNoChange++;
        }
    }
    if (dsv_globalScrollNoChange>20 || (diffX==0 && diffY==0)) {
        dsv_globalScrollNoChange = 0;
        dsv_globalScrollToTimeout = -1;
        return;
    }
    var stepX = dsv_getScrollStep(diffX);
    var stepY = dsv_getScrollStep(diffY);
    if (diffX!=0)
        jQuery(overflowParent).scrollLeft(wndStartX+stepX);
    if (diffY!=0)
        jQuery(overflowParent).scrollTop(wndStartY+stepY);

    if (dsv_globalScrollToTimeout != -1)
        clearTimeout(dsv_globalScrollToTimeout);
    dsv_globalScrollToTimeout = setTimeout(function() { dsv_scrollToJQ(x, y, overflowParent, wndStartX, wndStartY); }, 30);
}

function dsv_repairWidthAndHeightJQ(layername) {
    jQuery("#"+layername).css({
        'width': 'auto',
        'height': 'auto'
    });
}

function dsv_getScrollStep(diff) {
    var negative = (diff<0)?-1:1;
    if (diff==0)
        return 0;
    if (Math.abs(diff)<4)
        return 1*negative;
    if (Math.abs(diff)<8)
        return 2*negative;
    if (Math.abs(diff)<12)
        return 4*negative;
    if (Math.abs(diff)<25)
        return 6*negative;
    if (Math.abs(diff)<50)
        return 10*negative;
    return 20*negative;
}

function dsv_readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function dsv_initApplicationNavigation() {
    if (dsv_readCookie("dsv5NaviState")=="closed") {
        document.getElementById('dsv_appmenu_navi_gross').style.display = 'none';
        document.getElementById('dsv_appmenu_navi_klein').style.display = 'block';
        document.getElementById('dsv_appcontent_untererContent').style.width = '985px';
    }
    else {
        document.getElementById('dsv_appmenu_navi_gross').style.display = 'block';
        document.getElementById('dsv_appmenu_navi_klein').style.display = 'none';
        document.getElementById('dsv_appcontent_untererContent').style.width = '765px';
    }

}

function dsv_checkIE6warning() {
    if (jQuery.browser.msie && jQuery.browser.version>=6 && jQuery.browser.version<7 && dsv_readCookie('noIE6warning')!='1') {
        jQuery('#dsv_errorhead_ie6warning_inner').html('<a href="#" onclick="dsv_closeIE6warning()" style="color:red; font-weight:bold;border:1px solid red; padding:0px 4px; float:right">X</a>Sie nutzen den Internet Explorer 6 oder &auml;lter. Um diese Internetseite bestm&ouml;glichst darzustellen, empfehlen wir Ihnen eine aktuellere Browserversion zu verwenden (Internet Explorer 8 bzw. Mozilla Firefox).');
        jQuery('#dsv_errorhead_ie6warning').css('display', 'block');
    }
}

function dsv_closeIE6warning() {
    jQuery('#dsv_errorhead_ie6warning').animate({height:'1px', opacity:0}, 500, function() {
        jQuery('#dsv_errorhead_ie6warning').css('display', 'none');
        document.cookie = 'noIE6warning=1';
    });
}


// Funktionen für Wissenspool
function dsv_initToolbar() {
jQuery(function($) {
    var msie6 = ($.browser.msie && $.browser.version < 7);
    var    $dsv_appcontent_toolbar = $("div#dsv_appcontent_toolbar_container"),
        $window    = $(window),
        top = $dsv_appcontent_toolbar.offset().top - parseFloat($dsv_appcontent_toolbar.css("margin-top").replace(/auto/, 0));

    $window.scroll(function(event) {
        var y = $window.scrollTop();

        if (y >= top) {
            if (msie6) $dsv_appcontent_toolbar.stop().animate({marginTop: y - top});
            else {
                $dsv_appcontent_toolbar.addClass("fixed");
                if (!$dsv_appcontent_toolbar.hasClass("closed")) $dsv_appcontent_toolbar.css("left", "10px");
                else $dsv_appcontent_toolbar.css("left", "0");
            }
        }
        else {
            if (msie6) $dsv_appcontent_toolbar.stop().animate({marginTop: 0});
            else {
                $dsv_appcontent_toolbar.removeClass("fixed");
                if (!$dsv_appcontent_toolbar.hasClass("closed")) $dsv_appcontent_toolbar.css("left", "0");
                else $dsv_appcontent_toolbar.css("left", "-10px");
            }
        }
    });

    $("div#dsv_appcontent_toolbar_aufzu > a").click(function() {
        var $dsv_appcontent_toolbar_container = $("div#dsv_appcontent_toolbar_container"),
            left = "0";

        if ($dsv_appcontent_toolbar_container.hasClass("closed")) {
            if ($dsv_appcontent_toolbar_container.hasClass("fixed")) left = "10px";
            $dsv_appcontent_toolbar_container.animate({
                left: left
            }, "fast", function() {

                $("div#dsv_appcontent_toolbar_aufzu > a > img").attr("src", $("div#dsv_appcontent_toolbar_aufzu > a > img").attr("src").replace("-open.png", "-close.png"));
                $("div#dsv_appcontent_toolbar_aufzu").animate({
                    left: "1px"
                }, "fast", function() {
                    $("div#dsv_appcontent_toolbar").animate({
                        width: "985px"
                    }, "slow", function() {
                        $("div#dsv_appcontent_bookmarks").slideDown("fast");
                    });
                });
            }).removeClass("closed");
        }
        else {
            if (!$dsv_appcontent_toolbar_container.hasClass("fixed")) left = "-10px";
            $("div#dsv_appcontent_bookmarks > ul > li").removeClass("dsv_appcontent_bookmarks_over");
            $("div#dsv_appcontent_bookmarks_box_container").slideUp("fast", function() {
                $("div#dsv_appcontent_index_box_container").slideUp("fast", function() {
                    $("div#dsv_appcontent_bookmarks").slideUp("fast", function() {
                        $("div#dsv_appcontent_toolbar").animate({
                            width: "40px"
                        }, "slow", function() {
                            $dsv_appcontent_toolbar_container.animate({
                                left: left
                            }, "fast", function() {
                                $("div#dsv_appcontent_toolbar_aufzu > a > img").attr("src", $("div#dsv_appcontent_toolbar_aufzu > a > img").attr("src").replace("-close.png", "-open.png"));
                                $("div#dsv_appcontent_toolbar_aufzu").animate({
                                    left: "8px"
                                }, "fast")
                            }).addClass("closed");
                        });
                    });
                });
            });
        }
    });

    $(".dsv_appcontent_toolbar_button").mouseover(function() {
            if (!$(this).hasClass("active")) {
                $(this).attr("src", $(this).attr("src").replace(".png", "-active.png"));
            }
            if ($(this).hasClass("zoomactive")) {
                $(this).attr("src", $(this).attr("src").replace(".png", "-zoom.png"));
            }
        }).mouseout(function() {
            if (!$(this).hasClass("active")) {
                $(this).attr("src", $(this).attr("src").replace("-active.png", ".png"));
            }
            if ($(this).hasClass("zoomactive")) {
                $(this).attr("src", $(this).attr("src").replace("-zoom.png", ".png"));
            }
        }
    );

    $("div#dsv_appcontent_bookmarks > ul > li").click(function() {
        var index = $(this).prevAll().length;
        $(this).prevAll().removeClass("dsv_appcontent_bookmarks_over");
        $(this).nextAll().removeClass("dsv_appcontent_bookmarks_over");
        $("div#dsv_appcontent_index_box_container").slideUp("fast");
        $("div#dsv_appcontent_bookmarks_box_container").slideDown("fast");
        $("div#dsv_appcontent_bookmarks").attr("class", function(i, c) {
            return c.replace(/\bdsv_appcontent_bookmarks_open_\S+/g, "");
        }).addClass("dsv_appcontent_bookmarks_open_" + index);
        return false;
    }).mouseover(function() {
        $(this).addClass("dsv_appcontent_bookmarks_over");
    }).mouseout(function() {
        var index = $(this).prevAll().length;
        if (!$("div#dsv_appcontent_bookmarks").hasClass("dsv_appcontent_bookmarks_open_" + index)) $(this).removeClass("dsv_appcontent_bookmarks_over");
    });

    $("a#dsv_appcontent_bookmarks_close").click(function() {
        $("div#dsv_appcontent_bookmarks_box_container").slideUp("fast");
        $("div#dsv_appcontent_bookmarks > ul > li").removeClass("dsv_appcontent_bookmarks_over");
        $("div#dsv_appcontent_bookmarks").attr("class", function(i, c) {
            return c.replace(/\bdsv_appcontent_bookmarks_open_\S+/g, "");
        });
    });

    $("a#dsv_appcontent_toolbar_button_index").click(function() {
        var $img = $(this).children(".dsv_appcontent_toolbar_button");

        //$("a#dsv_appcontent_bookmarks_close").click();
        //$("div#dsv_appcontent_bookmarks").slideToggle("fast");
        $("div#dsv_appcontent_index_box_container").slideToggle("fast", function() {
            $("div#dsv_appcontent_index_box").animate({
                scrollTop: $("a.dsv_appcontent_index_tree_active").offset().top
            }, 1000);
        });

        if (!$img.hasClass("active")) $img.addClass("active");
        else $img.removeClass("active");
    });

    $("div#dsv_appcontent_index_box_container").mouseleave(function() {
        var $img = $("a#dsv_appcontent_toolbar_button_index").children(".dsv_appcontent_toolbar_button");
        $img.attr("src", $img.attr("src").replace("-active.png", ".png"));
        $("a#dsv_appcontent_toolbar_button_index").click();
    });

    $("li.open").parents("li").addClass("open").children("a").addClass("open");
    $("#dsv_appcontent_index_tree").dsv_treeview({
        collapsed: true,
        animated: "fast"
    });

    $("a.dsv_appcontent_index_tree_link").click(function() {
        $.cookie("dsv_wissenspool_index_open", "true");
        $.cookie("dsv_wissenspool_index_position", $(window).scrollTop());
        return true;
    });

    if ($.cookie("dsv_wissenspool_index_open") == "true") {
        var $img = $("a#dsv_appcontent_toolbar_button_index").children(".dsv_appcontent_toolbar_button");
        $img.addClass("active").attr("src", $img.attr("src").replace(".png", "-active.png"));
        $(window).scrollTop($.cookie("dsv_wissenspool_index_position"));
        $.cookie("dsv_wissenspool_index_open", null);
        $.cookie("dsv_wissenspool_index_position", null);
    }
    else {
        $("div#dsv_appcontent_index_box_container").hide();
    }

});
}

function dsv_addBookmark(url, title) {
    var url = url || location.href;
    var title = title || document.title;

    if (document.all) {
        window.external.AddFavorite(url, title);
    }
    else if(window.sidebar) {
        window.sidebar.addPanel(title, url, '');
    }

    return false;
}

function dsv_wpEqualHeight() {
jQuery(function($) {
    var highestCol,
    $dsv_appcontent_page_left = $("div#dsv_appcontent_page_left"),
    $dsv_appcontent_page_right = $("div#dsv_appcontent_page_right"),
    $dsv_appcontent_page_left_new = $("div#dsv_appcontent_page_left_new"),
    $dsv_appcontent_page_right_new = $("div#dsv_appcontent_page_right_new");

    if ($dsv_appcontent_page_left.length != 0) {
        highestCol = Math.max($dsv_appcontent_page_left.height(), $dsv_appcontent_page_right.height());
        $dsv_appcontent_page_left.height(highestCol);
        $dsv_appcontent_page_right.height(highestCol);
    }
    else if ($dsv_appcontent_page_left_new.length != 0) {
        highestCol = Math.max($dsv_appcontent_page_left_new.height(), $dsv_appcontent_page_right_new.height());
        $dsv_appcontent_page_left_new.height(highestCol);
        $dsv_appcontent_page_right_new.height(highestCol);
    }
});
}

(function($) {
    $.extend($.fn, {
        swapClass: function(c1, c2) {
            var c1Elements = this.filter('.' + c1);
            this.filter('.' + c2).removeClass(c2).addClass(c1);
            c1Elements.removeClass(c1).addClass(c2);
            return this;
        },
        replaceClass: function(c1, c2) {
            return this.filter('.' + c1).removeClass(c1).addClass(c2).end();
        },
        hoverClass: function(className) {
            className = className || "hover";
            return this.hover(function() {
                $(this).addClass(className);
            }, function() {
                $(this).removeClass(className);
            });
        },
        heightToggle: function(animated, callback) {
            animated ?
                this.animate({ height: "toggle" }, animated, callback) :
                this.each(function(){
                    jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ]();
                    if(callback)
                        callback.apply(this, arguments);
                });
        },
        heightHide: function(animated, callback) {
            if (animated) {
                this.animate({ height: "hide" }, animated, callback);
            } else {
                this.hide();
                if (callback)
                    this.each(callback);
            }
        },
        prepareBranches: function(settings) {
            if (!settings.prerendered) {
                // mark last tree items
                this.filter(":last-child:not(ul)").addClass(CLASSES.last);
                // collapse whole tree, or only those marked as closed, anyway except those marked as open
                this.filter((settings.collapsed ? "" : "." + CLASSES.closed) + ":not(." + CLASSES.open + ")").find(">ul").hide();
            }
            // return all items with sublists
            return this.filter(":has(>ul)");
        },
        applyClasses: function(settings, toggler) {
            this.filter(":has(>ul):not(:has(>a))").find(">span").unbind("click.treeview").bind("click.treeview", function(event) {
                // don't handle click events on children, eg. checkboxes
                if ( this == event.target )
                    toggler.apply($(this).next());
            }).add( $("a", this) ).hoverClass();

            if (!settings.prerendered) {
                // handle closed ones first
                this.filter(":has(>ul:hidden)")
                        .addClass(CLASSES.expandable)
                        .replaceClass(CLASSES.last, CLASSES.lastExpandable);

                // handle open ones
                this.not(":has(>ul:hidden)")
                        .addClass(CLASSES.collapsable)
                        .replaceClass(CLASSES.last, CLASSES.lastCollapsable);

                // create hitarea if not present
                var hitarea = this.find("div." + CLASSES.hitarea);
                if (!hitarea.length)
                    hitarea = this.prepend("<div class=\"" + CLASSES.hitarea + "\"/>").find("div." + CLASSES.hitarea);
                hitarea.removeClass().addClass(CLASSES.hitarea).each(function() {
                    var classes = "";
                    $.each($(this).parent().attr("class").split(" "), function() {
                        classes += this + "-hitarea ";
                    });
                    $(this).addClass( classes );
                })
            }

            // apply event to hitarea
            this.find("div." + CLASSES.hitarea).click( toggler );
        },
        dsv_treeview: function(settings) {

            settings = $.extend({
                cookieId: "treeview"
            }, settings);

            if ( settings.toggle ) {
                var callback = settings.toggle;
                settings.toggle = function() {
                    return callback.apply($(this).parent()[0], arguments);
                };
            }

            // factory for treecontroller
            function treeController(tree, control) {
                // factory for click handlers
                function handler(filter) {
                    return function() {
                        // reuse toggle event handler, applying the elements to toggle
                        // start searching for all hitareas
                        toggler.apply( $("div." + CLASSES.hitarea, tree).filter(function() {
                            // for plain toggle, no filter is provided, otherwise we need to check the parent element
                            return filter ? $(this).parent("." + filter).length : true;
                        }) );
                        return false;
                    };
                }
                // click on first element to collapse tree
                $("a:eq(0)", control).click( handler(CLASSES.collapsable) );
                // click on second to expand tree
                $("a:eq(1)", control).click( handler(CLASSES.expandable) );
                // click on third to toggle tree
                $("a:eq(2)", control).click( handler() );
            }

            // handle toggle event
            function toggler() {
                $(this)
                    .parent()
                    // swap classes for hitarea
                    .find(">.hitarea")
                        .swapClass( CLASSES.collapsableHitarea, CLASSES.expandableHitarea )
                        .swapClass( CLASSES.lastCollapsableHitarea, CLASSES.lastExpandableHitarea )
                    .end()
                    // swap classes for parent li
                    .swapClass( CLASSES.collapsable, CLASSES.expandable )
                    .swapClass( CLASSES.lastCollapsable, CLASSES.lastExpandable )
                    // find child lists
                    .find( ">ul" )
                    // toggle them
                    .heightToggle( settings.animated, settings.toggle );
                if ( settings.unique ) {
                    $(this).parent()
                        .siblings()
                        // swap classes for hitarea
                        .find(">.hitarea")
                            .replaceClass( CLASSES.collapsableHitarea, CLASSES.expandableHitarea )
                            .replaceClass( CLASSES.lastCollapsableHitarea, CLASSES.lastExpandableHitarea )
                        .end()
                        .replaceClass( CLASSES.collapsable, CLASSES.expandable )
                        .replaceClass( CLASSES.lastCollapsable, CLASSES.lastExpandable )
                        .find( ">ul" )
                        .heightHide( settings.animated, settings.toggle );
                }
            }
            this.data("toggler", toggler);

            function serialize() {
                function binary(arg) {
                    return arg ? 1 : 0;
                }
                var data = [];
                branches.each(function(i, e) {
                    data[i] = $(e).is(":has(>ul:visible)") ? 1 : 0;
                });
                $.cookie(settings.cookieId, data.join(""), settings.cookieOptions );
            }

            function deserialize() {
                var stored = $.cookie(settings.cookieId);
                if ( stored ) {
                    var data = stored.split("");
                    branches.each(function(i, e) {
                        $(e).find(">ul")[ parseInt(data[i]) ? "show" : "hide" ]();
                    });
                }
            }

            // add treeview class to activate styles
            this.addClass("dsv_appcontent_treeview");

            // prepare branches and find all tree items with child lists
            var branches = this.find("li").prepareBranches(settings);

            switch(settings.persist) {
            case "cookie":
                var toggleCallback = settings.toggle;
                settings.toggle = function() {
                    serialize();
                    if (toggleCallback) {
                        toggleCallback.apply(this, arguments);
                    }
                };
                deserialize();
                break;
            case "location":
                var current = this.find("a").filter(function() {
                    return this.href.toLowerCase() == location.href.toLowerCase();
                });
                if ( current.length ) {
                    // TODO update the open/closed classes
                    var items = current.addClass("selected").parents("ul, li").add( current.next() ).show();
                    if (settings.prerendered) {
                        // if prerendered is on, replicate the basic class swapping
                        items.filter("li")
                            .swapClass( CLASSES.collapsable, CLASSES.expandable )
                            .swapClass( CLASSES.lastCollapsable, CLASSES.lastExpandable )
                            .find(">.hitarea")
                                .swapClass( CLASSES.collapsableHitarea, CLASSES.expandableHitarea )
                                .swapClass( CLASSES.lastCollapsableHitarea, CLASSES.lastExpandableHitarea );
                    }
                }
                break;
            }

            branches.applyClasses(settings, toggler);

            // if control option is set, create the treecontroller and show it
            if ( settings.control ) {
                treeController(this, settings.control);
                $(settings.control).show();
            }

            return this;
        }
    });

    $.treeview = {};
    var CLASSES = ($.treeview.classes = {
        open: "open",
        closed: "closed",
        expandable: "expandable",
        expandableHitarea: "expandable-hitarea",
        lastExpandableHitarea: "lastExpandable-hitarea",
        collapsable: "collapsable",
        collapsableHitarea: "collapsable-hitarea",
        lastCollapsableHitarea: "lastCollapsable-hitarea",
        lastCollapsable: "lastCollapsable",
        lastExpandable: "lastExpandable",
        last: "last",
        hitarea: "hitarea"
    });
})(jQuery);

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') {
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString();
        }
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else {
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};


