jQuery.fn.defuscate = function( settings ) {
    settings = jQuery.extend({
        link: true
    }, settings);
    var regex = /\b([A-Z0-9._%-]+)\([^)]+\)((?:[A-Z0-9-]+\.)+[A-Z]{2,6})\b/gi;
    return this.each(function() {
        if ( $(this).is('a[@href]') ) {
            // If it's an <a> element, defuscate the href attribute
            $(this).attr('href', $(this).attr('href').replace(regex, '$1@$2'));
            // Make sure that the element's contents is not made into a link
            var is_link = true;
            //alert($(this).attr('href'));
        }
        // Defuscate the element's contents
        $(this).html($(this).html().replace(regex, (settings.link && !is_link ? '<a href="mailto:$1@$2">$1@$2</a>' : '$1@$2')));
  });
}


$(document).ready(function(){
  $('span.email').defuscate();
  
  var $nL = 0;
  
  $('a').attr('title','');
  $('img').attr('title','');
  
  $('#nav li').children().each(function(){
    ++$nL;
    $oT = $(this).text();
    $c = $nL;
    if($nL < 10) {
      $c = '0'+$c;
    }
    $(this).html('<span>'+$c+'. </span>'+$oT);
  });
  
  $i = 0;
  
  $('#nav li a').each(function(){
    
    if($run == 0) {
      $(this).css({'opacity': '0'});

      $(this).delay($i*100).animate({
        opacity: '1',
        paddingLeft: '60px',
        paddingRight: '0px'
      }, 300).animate({
          paddingLeft: '20px',
          paddingRight: '20px'
        }, 400);

      $i++;
    }
    
    $(this).bind('mouseover',function(){
      $(this).stop().animate({
        paddingLeft: '30px',
        paddingRight: '10px'
      }, 200);
    });
    $(this).bind('mouseout',function(){
      $(this).stop().animate({
        paddingLeft: '20px',
        paddingRight: '20px'
      }, 200);
    });
  });
  
  $('#knowledge').clone().appendTo('#site');
  $('#site #knowledge').removeClass('outer');
  $('.outer').remove();
  
  var $k = 1;
  var $klen = $('#knowledge li').children().length;
  
  $('#knowledge li').children().each(function(){

    if($k < $klen) {
       $(this).after(',&nbsp;');
     }
     $k++;
  });
  
  $('.last').append(' <span class="know">Wissen</span>');
  
  if($('.know').length > 0) {
    $('.know').bind('mouseover',function(){
      if($('#knowledge').hasClass('on')) {
        $('#knowledge').fadeOut();
        $('#knowledge').removeClass('on');
      }
      else {
        $('#knowledge').fadeIn();
        $('#knowledge').addClass('on');
      }
    });
  }
  
  $('#knowledge').bind('mouseleave',function(){
    $(this).fadeOut();
    $('#knowledge').removeClass('on');
  });
  
  if($('fieldset.opt').length > 0) {
    $('fieldset.opt legend').addClass('clickable');
    $('fieldset.opt p').each(function(){
      $(this).hide();
    });
    
    $('fieldset.opt legend').bind('click',function(){
      $(this).toggleClass('act');
      $('fieldset.opt p').slideToggle();
    })
  }
  
  
});
