// Reverse Funktion in jQuery
jQuery.fn.reverse = [].reverse

/**
 * Setzt die Sprache (oder einen anderen Wert) f�r die angegebene Select-Box
 **/
setLanguage = function(id_from, id_to, url, replaceString )
{
        var val=$('#' + id_from).val();
        var load_url=encodeURI(url.replace(replaceString, val));
        $.get(load_url, function(data){
            $('#' + id_to + ' option[value='+ data +']').attr('selected', true);
        });
}

$(document).ready(function(){

    /**
     * Hide alls Elements with class jshide
     * These should be elements (like links or buttons, who helps user without javascript
     */
    $(".jshide, .hiddenContent").hide()

    /**
     * Hide some white Boxes, if JavaScript is activated.
     */
    if(!($.browser.msie && parseInt($.browser.version)<8)) {
        $(".outlineBox .hidden").toggleClass("hidden hiddenJS")
        $(".direction").toggleClass("direction directionJS")
    }
    /**
     * Show all elements with class jsshow
     * These should be elements, which have javascript functions
     */
    $(".jsshow").show()

    /**
     * Show all child-elements with class tooltip by hovering the object with class hover_tooltip
     */
    $(".hover_tooltip").live('mouseenter', function(eventObj){
        tooltip = $("body > #tooltip_elem");
        if(tooltip.size() == 0)
        {
            $("body").append('<div id="tooltip_elem" class="tooltip"></div>');
            tooltip = $("body > #tooltip_elem");
        }
        html = $(this).children(".tooltip").html();
        if(html != null && html.length > 0)
        {
            tooltip.html(html)
                .css({'top': eventObj.pageY + 20, 'left': eventObj.pageX + 20})
                .show();
        }
    })
    .live('mouseleave', function()
    {
        $("body #tooltip_elem").hide()
    })

    $("#toggleOutline").click(function(){
    	$("#outline").toggle();
    	$("#toggleOutline").toggleClass("outlineHidden");
    })

    $(".autocompleter").each(function(){
        thisObj = $(this);
        thisObj
            .autocomplete(thisObj.attr('href'));
    });

    $(".toggleBox .beigeBoxContent .headline").live('click', function(){
        $(this)
            .find('.arrow')
                .toggleClass('up down')
                .end()
            .siblings()
                .toggle()
        return false;
    })

    $(".outlineBox .whiteBoxContent .headline").live('click', function(){
    if(!($.browser.msie && parseInt($.browser.version)<8)) {
        $(this)
            .parents('.whiteBoxContent')
                .toggleClass('hiddenJS show')
    }
    })

})