$('document').ready(function(){
  
  // Subnavi
  $('#subnavi, #subnavi .sublevel .inactive a').hide();
  $('#subnavi').show('slow',function(){
    $('#subnavi .inactive a').show();
  });
  
  $('#subnavi li').click(function(){
    $('#subnavi .sublevel .inactive a').hide();
    $('#subnavi').hide('slow');
  });
  
  // Rollover
  $('.csc-frame-frame1').hover(function(){
    var offDef = $('.csc-frame-frame1:first').offset().top;
    var hDef = $('.csc-frame-frame1:first .content').height();
    if($(this).position().left < 500) $(this).addClass('frame-left');
    else $(this).addClass('frame-right');
    var base = offDef - $(this).offset().top;
    var height = hDef + base;
    $(this).children('.content').height(height);
  });
  
  // Rollover 2{
    $('#inhalt .csc-textpic img').hover(
      function(){
        //alert($(this).children('img').attr('title'));
        $('#lcont').append('<p class="info"><strong>' + $(this).attr('alt') + '</strong></p>');
      },
      function(){
        $('p.info').detach();
      }
    );
  
  
  //Platzhalter
  $('dl dt img').each(function(){
    if($(this).attr('src').indexOf('Platzhalter')>0){
      //alert($(this).attr('src'));
      $(this).parents('dt').parents('dl').css('border', 0);
      $(this).parents('dt').parents('dl').children('dd').css('background', 'none');  
    }
  });
  
  // Team
  $('#c104, #c105, #c106').hide(); 
  
  $('.cb img').hover(
    function(){
      var src = $(this).attr('src');
      src = src.replace('sw','farbig');
      $(this).attr('src', src);
      
      var el = $(this).attr('class');
      $('#' + el).show();
    },
    function(){
      var src = $(this).attr('src');
      src = src.replace('farbig','sw');
      $(this).attr('src', src);
      
      var el = $(this).attr('class');
      $('#' + el).hide();
    }
  );
  
  // textpic carousel
  if($('#inhalt .csc-textpic').size() > 1){
    //$('#inhalt .csc-default:not(:first)').css('width', '0px');
    $('#inhalt').wrapInner('<div class="sliderWrapper"><div class="slider">');
    //$('#inhalt .csc-default:not(:first)').hide();    
    $('#inhalt').append('<a class="next"></a>');
    $('#inhalt').append('<a class="prev"></a>');
    var width = $('div.csc-textpic:first-child').width();
    var i = 1;
  }
  
  (function( $ ){  
    $.fn.sshow = function(dir){
      this.css('float', dir);
      return $(this).animate({
        'width': '656px',
        'display': 'block'
      },
      1000,
      'swing', 
      function(){
        $(this).show(0);
        $(this).css('float', 'none');
      });
    }
  })( jQuery );
    
  /*$('#inhalt a.next').click(function(){
    $('#inhalt .csc-default:visible').animate({'width': '0px'},1000,'swing',function(){
      $(this).hide(0);
      $(this).next('.csc-default').sshow('right');
      if($('#inhalt .csc-default:visible').size()==0){
        $('#inhalt .csc-default:first').sshow('right');
      }                    
    });
    return false;
  });
  
  
  
  $('#inhalt a.prev').click(function(){
    $('#inhalt .csc-default:visible').css('float', 'right');
    $('#inhalt .csc-default:visible').animate({'width': '0px'},function(){
      $(this).hide(0);
      $(this).css('float', 'none');
      $(this).prev('.csc-default').sshow('left');
      if($('#inhalt .csc-default:visible').size()==0){
        $('#inhalt .csc-default:last').sshow('left');
      }                  
    });
    return false;
  });*/
  
  $('#inhalt a.next').click(function(){
    if(i == $('#inhalt .csc-textpic').size()){
      $('div.slider').css('left', width + 'px');
      i=0;  
    }
    var pos = $('div.slider').position().left-width;
    //alert($('div.slider').position().left + ' - ' + width + ' = ' + pos);
    $('div.slider').animate({'left': pos + 'px'} ,1000, 'swing');
    i++;
  });
  
  $('#inhalt a.prev').click(function(){
    if(i == 1){
      $('div.slider').css('left', '-' + $('#inhalt .csc-textpic').size()*width + 'px');
      i=$('#inhalt .csc-textpic').size()+1;  
    }
    var pos = $('div.slider').position().left+width;
    $('div.slider').animate({'left': pos + 'px'} ,1000, 'swing');
    i--;
  });
  
  // Tröte
  $('#c101 img').hover(
    function(){    
      $(this).attr('src','/uploads/pics/SK_Neues_2.png');
    },
    function(){    
      $(this).attr('src','/uploads/pics/SK_Neues_1.png');
    }
  );
  
  // Lexikon
  $('#lexikon').jScrollPane({scrollbarWidth: 7});
  
  $('#s106 #c102 img').attr('src','/uploads/pics/SK_Werberlexikon_sw.png');
  $('#s106 #left h1 a').each(function(){
    $(this).attr('href', $(this).attr('href').replace('werberlexikon/', ''))
  });
  $('#s106 #left h1 a').click(function(){
    $('#s106 #left h1 a').css('color', '#646464');
    $(this).css('color', '#DF002A');    
  });
  // Erfolgsgarant
  $('#s50 #c103 img').attr('src','/uploads/pics/SK_Erfolgsgarant_sw.png');
  


});
