﻿var slideInterval = 6000;
var equaltabs = 0; var animation = 0; var iconline = 0;

function equalWidth() {
    var li = jQuery('.css-tabs li a');
    widest = 0;
    thisWidth = 0;
    setEqWidth = function (elem) {
        widest = 0;
        elem.each(function () {
            thisWidth = jQuery(this).outerWidth();
            if (thisWidth > widest) {
                widest = thisWidth;
            }
        });
        elem.css({ 'width': widest });
    }
    setEqWidth(li);
}
jQuery(document).ready(function () {
    Cufon.replace('.buehneTextWrap h1');
    Cufon.replace('.buehneTextWrap p');
    Cufon.refresh();
    jQuery('.jt-item').each(function (index) {
        if (iconline > 0) {
            jQuery(this).find(".buehneTxtLine" + iconline).append('<span class="buehneMore"><img src="/fileadmin/templates/_CORE_R/img/buttons/btn-buehnemore.png" alt="" /></span>');
        }
        var topOff = jQuery(this).find('.buehneTextWrap .posTop').html();
        if (topOff != 32) {
            jQuery(this).find('.buehneTextWrap').css('top', topOff + 'px');
        }
        var leftOff = jQuery(this).find('.buehneTextWrap .posLeft').html();
        if (leftOff != 26) {
            jQuery(this).find('.buehneTextWrap').css('left', leftOff + 'px');
        }
    });
    if (jQuery(".css-panes:first > div").size() == 1) {
        jQuery('.css-tabs').hide();
    } else {
        //center ul
        marginLeft = Math.floor(705 - jQuery('.css-tabs').width()) / 2;
        jQuery('.css-tabs').css('left', marginLeft);
    }
    // :first selector is optional if you have only one tabs on the page
    jQuery(".css-tabs:first").tabs(".css-panes:first > div", {
        event: 'click',
        effect: 'fade',
        fadeOutSpeed: "slow",
        rotate: true,
        onBeforeClick: function (event, tabIndex) {

            var pLines = 5;
            var delay = 800;
            var delayAdd = 800;
            target = this.getPanes().eq(tabIndex).find(".panemore").attr('href');
            this.getPanes().eq(tabIndex).bind('click', function (event) {
                window.location = target;
            });
            this.getTabs().unbind('click', function (event) {
                window.location = target;
            });
            this.getTabs().eq(tabIndex).bind('click', function (event) {
                window.location = target;
            });

            if (animation == 1) {
                jQuery(".buehneTextWrap h1").hide();
                jQuery(".buehneTextWrap p").hide();
                this.getPanes().eq(tabIndex).find("h1").fadeIn(500);
                for (i = 1; i <= 5; i++) {
                    if (this.getPanes().eq(tabIndex).find(".buehneTxtLine" + i).html() != '&nbsp;') {

                        this.getPanes().eq(tabIndex).find(".buehneTxtLine" + i).delay(delay).fadeIn(1200);
                        delay += delayAdd;
                    } else {
                        this.getPanes().eq(tabIndex).find(".buehneTxtLine" + i).show();
                        alert(i);
                    }
                }
            }
        }
    }).slideshow({ autoplay: true, interval: slideInterval, clickable: false });

    if (equaltabs == 1) {
        equalWidth();
    }

});  
