jQuery.fn.autoEllipsis = function(options) {
    var get_AutoEllipsisScroller = function(id) {
        var aeScrollerId = "WingooliAutoEllipsisScroller_" + id
        if (!document.getElementById(aeScrollerId)) {
            var div = document.createElement("div");
            div.id = aeScrollerId + "_Container";
            div.innerHTML = "<span id=\"" + aeScrollerId + "\" style=\"overflow: visible; position: absolute; top: -2000px; color: orange\"></span>";
            document.body.appendChild(div);
        }
        return document.getElementById(aeScrollerId);
    };

    var StringEllipsesByMaxLetters = function(element, originalText, maxLettersAllowed) {
        element.title = "";
        var langText = "legga tutta la info";
        if (window.location.href.match(/\/de\//)) langText = "lesen Sie mehr";
        var text = originalText;
        if (text == null || text == "") text = element.innerHTML;
        var maxAllowedLatterIndex = text.length - maxLettersAllowed;
        if (maxAllowedLatterIndex > 0) {
            element.title = text;
            if (originalText == null)
                originalText = text;
            element.innerHTML = text.substr(0, maxLettersAllowed - 18) + " &hellip; <strong>" + langText + "</strong>";
        } else {
            element.innerHTML = text;
        }
    };

    var _this = this;

    var settings = jQuery.extend({}, options);
    this.each(function(a) {
        var aeScroller = get_AutoEllipsisScroller(i);
        var langText = "legga tutta la info";
        if (window.location.href.match(/\/de\//)) langText = "lesen Sie mehr";
        saeScroller = $(aeScroller);
        sthis = $(this);
        saeScroller.text(sthis.text());

        var origText = sthis.text();

        var element = this;
        var elementBounds = { width: element.offsetWidth, height: element.offsetHeight };

        var jElement = $(element);

        var props = ["font-size", "font-weight", "font-family", "font-style", "padding"];

        for (var i = 0; i < props.length; i++) {
            try {
                var jAeScroller = $(aeScroller);
                jAeScroller.css(props[i], jElement.css(props[i]));
            } catch (ex) { }
        }
        jElement.css("overflow", "visible");


        jAeScroller.width(jElement.width());

        var isIe = (document.all != undefined);
        var scrollerWidth = jAeScroller.width();
        var scrollerHeight = jAeScroller.height();
        var fitText = saeScroller.html();

        while (scrollerHeight > elementBounds.height && fitText != "") {
            fitText = fitText.substr(0, fitText.length - 8);
            var autoScrollerInnerHTML = fitText + " &hellip; <strong>" + langText + "</strong>";
            saeScroller.html(autoScrollerInnerHTML);
            scrollerHeight = jAeScroller.height();
        }
        if (fitText == "") {
            fitText = origText;
            saeScroller.html(fitText);
            jElement.css("whiteSpace", "nowrap");
            jAeScroller.width("");
            var scrollerWidth = jAeScroller.width();
        }
        while (scrollerWidth > elementBounds.width && fitText != "") {
            fitText = fitText.substr(0, fitText.length - 8);
            var autoScrollerInnerHTML = fitText + " &hellip; <strong>" + langText + "</strong>";
            saeScroller.html(autoScrollerInnerHTML);
            scrollerWidth = jAeScroller.width();
        }
        var scrollerHeight = aeScroller.offsetHeight;
        var r = (Math.ceil(elementBounds.height / scrollerHeight) - 1);
        r += (r == 0) ? 1 : 0;
        var maxLettersAllowed = fitText.length * r;

        StringEllipsesByMaxLetters(element, origText, maxLettersAllowed + (r + 1));
    });
}
jQuery(document).ready(function() {
    if (jQuery('.plist_title') && jQuery('#plist_box').length == 0) {
        jQuery('.plist_title').click(function() {
            if (jQuery(this).hasClass('refopen')) {
                jQuery(this).removeClass('refopen');
                jQuery(this).next().hide('slow');
                jQuery(this).next().next().hide();
            }
            else {
                //close all
                jQuery('.plist_title').removeClass('refopen');
                jQuery('.ref_item').hide();
                jQuery('.spacergif').hide();
                jQuery(this).addClass('refopen');
                jQuery(this).next().show('slow');
                jQuery(this).next().next().show();
            }
        });
        jQuery('.plist_title:first').click();
    }
    if (jQuery.browser.msie && jQuery.browser.version < 8) {
        var size = 573;
        if (jQuery('#content_unternehmen').length > 0) size = jQuery('#content_unternehmen').height();
        if (jQuery('#content_text').length > 0) size = jQuery('#content_text').height();
        jQuery('#container').height(size + 180);
        window.setTimeout(placeFooter, 1000);
    }
    jQuery("#content_bottom2 .csc-default").autoEllipsis();
    jQuery("#content_bottom2 .csc-default").tooltip({offset: [-50, -35]});
    jQuery(".plist_item_note").autoEllipsis();
    jQuery("#content_start_bottom1_bottom .bodytext").autoEllipsis();
    jQuery("#content_start_bottom1_bottom .bodytext").tooltip({offset: [-50, -35]});
    
});

function placeFooter() {
    if (jQuery.browser.msie && jQuery.browser.version < 8) {
        size = jQuery('#content_text').height();
        if (size > 300) jQuery('#container').height(size + 180);
    }
}

