$(document).ready(function() {
    
    
    
    
    $('.specialTable tr:nth-child(n+2)').click(function(){
         window.location = "/download/"+$(this).attr('rel')+"/";
    });
    
    
    $('#slider').nivoSlider({
            effect: 'random', // Specify sets like: 'fold,fade,sliceDown'
            slices: 15, // For slice animations
            boxCols: 8, // For box animations
            boxRows: 4, // For box animations
            animSpeed: 500, // Slide transition speed
            pauseTime: 5000, // How long each slide will show
            controlNav: false, // 1,2,3... navigation
            captionOpacity: 0 // Universal caption opacity
          });
    
    
    $('#produktsub').hide();
    $('#produkty')
        .hover(function() {
            $('#produktsub').stop().show();
        }, function() {
            $('#produktsub').stop().hide();
        });
        
        $("#produktsub li").click(function(){
            window.location = $(this).find("a:first").attr('href');
        });
        
    $('#produktsub')
        .hover(function() {
            $(this).stop().stop().show();
             $('#produkty').removeClass('menu').addClass('active');
        }, function() {
            $(this).stop().hide();
            $('#produkty').removeClass('active').addClass('menu');
        });
        $("#produktsub ul li").find('ul:first').hide().animate({'left': +180, 'margin-top': -38}, 'fast');
        $("#produktsub ul li").hover(function(){
            $(this).find("a:first").css({'color':'#ff7800'});    
            $(this).find('ul:first').show().animate({'left': +180, 'margin-top': -38}, 'fast');
        },function(){
            $(this).find("a:first").css({'color':'grey'});
            $(this).find('ul:first').hide().animate({'left': +180, 'margin-top': -38}, 'fast');
        });
        
        
          $("#formularz input[type=text], #formularz textarea").each(function(){
              $(this).val($(this).attr('title'));
              $(this).removeClass("blad").addClass("normal").css({"color":"grey"});
          });                  
          $("#formularz input[type=text], #formularz textarea").focusin(function(){
              if( $(this).val() == $(this).attr('title')) {
              $(this).val('');
              $(this).css({'color':'black'});
              }
              $(this).removeClass("blad").addClass("normal").css({"color":"black"});
          });
          $("#formularz input[type=text], #formularz textarea").focusout(function(){
              if( $(this).val() == '') {
                  $(this).val($(this).attr('title'));
                  $(this).removeClass("blad").addClass("normal").css({"color":"grey"});
              }
          });
          $("#szukaj").each(function(){
              $(this).val($(this).attr('title')).css({"color":"grey"});
          });
          $("#szukaj").focusin(function(){
              if( $(this).val() == $(this).attr('title')) {
              $(this).val('').css({'color':'black'});
              }
          });
          $("#szukaj").focusout(function(){
              if( $(this).val() == '') {
                  $(this).val($(this).attr('title')).css({"color":"grey"});
              }
          });
            

          
            $("#errorForm, #errorForm2").click(function(){
                $(this).slideUp();
            });
          

            $("#formularz input[type=submit]").click(function(){
                sprawdz = 0;
                $("#formularz input[type=text]").each(function(){
                    if($(this).val() == $(this).attr("title")) {
                        $(this).removeClass("normal").addClass("blad").css({"color":"red"});
                        ++sprawdz;
                    } 
                });
                $("#formularz textarea").each(function(){
                    if($(this).val() == $(this).attr("title")) {
                        $(this).removeClass("normal").addClass("blad").css({"color":"red"});
                        ++sprawdz;
                    } 
                });
                if(sprawdz > 0) {
                    $("#errorForm").html('Liczba błędów w formularzu: <b style="color:white;">' + sprawdz + '</b><span style="float:right;margin-right: 3px;">×</span>').slideDown();
                    return false;
                } else {
                    return true;
                }
                return false;
            });
            
            $('.pokazGalerie').donutGallery();
});
