$(document).ready(function() {  
    jQuery("#slider").nivoSlider({
        effect:"fade",
        slices:15,
        boxCols:8,
        boxRows:4,
        animSpeed:800,
        pauseTime:4000,
        startSlide:0,
        directionNav:false,
        directionNavHide:false,
        controlNav:true,
        controlNavThumbs:true,
        controlNavThumbsFromRel:true,
        keyboardNav:true,
        pauseOnHover:false,
        manualAdvance:false,
        afterChange: function(){
         
        },
        afterLoad: function(){
          var slider = $("#slider");
          $('img', slider).each(function(i, el){
            var text = $(this).attr('alt').replace('#', '</span>');
            slider.find('.nivo-controlNav a').eq(i).append('<span><span class="intro">'+text+'</span>');
          });
        }         
    }); 
    jQuery('#slider').click( function( evt ) {
      // Make sure that the Nivo Controllers still work :)
      if( jQuery( evt.target ).hasClass( 'nivo-control' ) )
        return false;
        
      var bg_url = jQuery( evt.target ).css( 'backgroundImage' );
      
      if( bg_url.substr( 0, 5 ) == 'url("' || bg_url.substr( 0, 5 ) == "url('" ) {
          bg_url = bg_url.substr( 5 );
      }
      if( bg_url.substr( 0, 4 ) == 'url(' ) {
          bg_url = bg_url.substr( 4 );
      }
      if( bg_url.substr( bg_url.length - 2, bg_url.length ) == '")' || bg_url.substr( bg_url.length - 2, bg_url.length ) == "')" ) {
          bg_url = bg_url.substr( 0, bg_url.length - 2 );
      }
      if( bg_url.substr( bg_url.length - 1, bg_url.length ) == ')' ) {
          bg_url = bg_url.substr( 0, bg_url.length - 1 );
      }
      // Try to find the image item that has the attribute src the same as the background
      var img = jQuery( this ).find( 'img[src="' + bg_url + '"]' );
      // If the image is found follow the parent anchors URL
      if( img.length ) {
          window.location.href = img.parent().attr( 'href' );
      }
  } );
    
    
    var mn = $('#categoriemenu');
         
    if(mn) {
      $('> li', mn).each(function(i, el){
         var li_width =  $('> a',$(this)).outerWidth();
         $(this).hover(function(){
            $(this).toggleClass('open');
          },
          function(){
            $(this).toggleClass('open');
          });        
        $('> ul > li', $(this)).width(li_width);
      });    
   }
});
$(document).ready(function() {  

  $('#meta-top > li').click(function(){

    if (!$(this).hasClass('selected')) {    
      //$('#meta-top > li').removeClass('selected');
      //$(this).addClass('selected');
      $('.boxBody div').slideUp('1500');
      $('.boxBody div:eq(' + parseInt($('#meta-top > li').index(this) - 1) + ')').slideDown('1500');
  }
    
  }).mouseover(function() {
  
    $(this).addClass('mouseover');
    $(this).removeClass('mouseout');   
    
  }).mouseout(function() {
    
    $(this).addClass('mouseout');
    $(this).removeClass('mouseover');    
  });

  $('.boxBody #category li').click(function(){

    window.location = $(this).children().attr('href');
  }).mouseover(function() {

    $(this).css('backgroundColor','#888');
    $(this).children().animate({paddingLeft:"20px"}, {queue:false, duration:300});
  }).mouseout(function() {
    
    $(this).css('backgroundColor','');
    $(this).children().animate({paddingLeft:"0"}, {queue:false, duration:300});
  });  
  
  $('#.boxBody li').click(function(){
    window.location = $(this).children().attr('href');
  }).mouseover(function() {
    $(this).css('backgroundColor','#888');
  }).mouseout(function() {
    $(this).css('backgroundColor','');
  });
  
  $('a#closeMK').click(function(){
    $('#meinKonto').hide();
  })
  
  $('a#closeMZ').click(function(){
    $('#merkzettel').hide();
  })  
  
  $('a#closeWK').click(function(){
    $('#basket').hide();
  })
  
  $('#voucherField').focus(function(){
    if ($(this).val() == sVoucherMessage){
          $(this).val('');
        }
  });

  $('.removeByClick').focus(function(){
    if ($(this).val() == sLoginEmail || $(this).val() == sLoginPassword || $(this).val() == 'Suche'){
          $(this).val('');
        }
  }); 
  
  $('.resetSearch').blur(function(){
    if ($(this).val() == ''){
          $(this).val('Suche');
        }
  }); 
  
});
