$(document).ready(function() {

    // hide all bubbletext
    $('.bubble .csc-texttext').hide();
    $('.bubble .csc-header').addClass('js-pfeil');

  $('.bubble').each(function () {
    // options
    var distance = 10;
    var time = 250;
    var hideDelay = 500;

    var hideDelayTimer = null;


    // tracker
    var beingShown = false;
    var shown = false;
    
    
    var popup = $('.csc-texttext', this).css('opacity', 0);

    var trigger = $('.csc-header', this);
    trigger.clone().prependTo(popup).before('<div class="wrap" />').removeClass('js-pfeil');
    
    // set the mouseover and mouseout on both element
    $([trigger.get(0), popup.get(0)]).mouseover(function () {
      // stops the hide event if we move from the trigger to the popup element
      if (hideDelayTimer) clearTimeout(hideDelayTimer);

      // don't trigger the animation again if we're being shown, or already visible
      if (beingShown || shown) {
        return;
      } else {
        beingShown = true;
        
        popup.addClass('shown');
        var popupHeight = popup.height();
        // reset position of popup box
        

        popup.css({
          //bottom: -45,
          //left: 80,
          height: popupHeight + 'px',
          display: 'block' // brings the popup back in to view
        });

        if($.browser.msie || $.browser.safari){
          popup.css({
            marginTop: '-' + popupHeight + 'px'
          });
        }
                
        // (we're using chaining on the popup) now animate it's opacity and position
        popup.animate({
          top: '+=' + distance + 'px',
          opacity: 1
        }, time, 'swing', function() {
          // once the animation is complete, set the tracker variables
          beingShown = false;
          shown = true;
        });
      }
    }).mouseout(function () {
      // reset the timer if we get fired again - avoids double animations
      if (hideDelayTimer) clearTimeout(hideDelayTimer);
      
      // store the timer so that it can be cleared in the mouseover if required
      hideDelayTimer = setTimeout(function () {
        hideDelayTimer = null;
        popup.animate({
          top: '-=' + distance + 'px',
          opacity: 0
        }, time, 'swing', function () {
          // once the animate is complete, set the tracker variables
          shown = false;
          // hide the popup entirely after the effect (opacity alone doesn't do the job)
          popup.css({
              display: 'none'
          });
          popup.removeClass('shown');

          
        });
      }, hideDelay);
    });
  });
/**/

    // make da list icons orange:
    $('.csc-texttext ul, .csc-texttext ol, .csc-textpic-text ul, .csc-textpic-text ol').each(function(el){
        $(this).find('li').addClass('jsc-li').wrapInner('<span></span>')
    });


    $('#thumbnailDiv a').fancybox({
        'zoomSpeedIn': 300,
        'zoomSpeedOut': 300,
        'overlayShow': false
    }); 

    // der will es doch nicht anders
    if($.browser.msie){
        $('#navi2').css({height: "auto"});
    }
    
/*
    // add clearer before splitted line in contact form in IE
    if($.browser.msie){
        $('#content .tx-pilmailform-pi1 li.p20').before("<br class='clear' />");
    }
*/
/*
    // Slideshow
    $('#head').cycle({ slideExpr: 'span.slideshowimage' });
*/
/*
    $('#quicklinks .loginlist').hide();

    if ( $("a.extranet").parent().next('li:hidden').hasClass('loginlist') ) {
        $("a.extranet").bind("click", function(ev){
                ev.preventDefault();
                $('#quicklinks .loginlist').toggle();
            }
        );
    };
*/
/*
    // Aufklappliste / Akkordion
    $('#content .slide .csc-header').not('.csc-header-n1').css({cursor: "pointer"}).addClass('hidden');
    $('#content .slide .csc-header').not('.csc-header-n1').next('div').hide();
    $('#content .slide .csc-header').not('.csc-header-n1').click(
        function(){
            if($(this).next().css("display")=="none" ){
                $(this).addClass('shown').removeClass('hidden');
                $(this).next('div').slideDown("fast");
            }else{
                $(this).addClass('hidden').removeClass('shown');
                $(this).next('div').slideUp("fast");
            }
        }
    );
*/
/*    
    // callback: hide labels, set text as value
    // add to empty-on-click-list below
    var labelText = $('#footer form label').text();
    $('#footer form label').attr('style','position: absolute; left: -99em').next('input').attr('value',labelText);
*/
/*
    // empty input fields on click
    $('#search-input, #footer input').focus(function () {
        $(this).attr('value','');
    });
*/
});
