$(function(){
 
    $('.kolejnosc_fotek').submit(function(e){
        e.preventDefault();
        var formularz = $(this)
        var tagdata = $(this).serialize();
       
        
 
        $.ajax({
            data: tagdata,
            url: this.action,
            type: 'post',
            success: function(msg){
                if(msg == 'ok') { 
                    formularz.append("<br>Dodano");
                   
                }
            }
        })
    })

    $("a[rel^='prettyPhoto']").prettyPhoto({
        social_tools:false, 
        allow_resize: false,
        deeplinking: false,
        theme: 'dark_rounded'/* light_rounded */
    });

    $('a.contact').click(function(e) {
        var id = $(this).attr('id');
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();
     
        $('#mask').css({
            'width':maskWidth,
            'height':maskHeight
        });	
        $('#mask').fadeIn(1000);   
   
        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();
        var box = $('#contact-form');   
        box.find('input#topic').val(id);
        //Set the popup window to center
        $(box).css('top',  winH/2-$(box).height()/2);
        $(box).css('left', winW/2-$(box).width()/2);
        $(box).fadeIn(1000); 
        e.preventDefault();
    })
    $('#mask').click(function () {
        $(this).hide();
        $('#contact-form').hide();
    });  
    
    
    $(".mailme").validate({
        errorElement: "p",
        rules: {
            name: {
                required: true,
                minlength: 2
            },
            tel: {
                required: true,
                minlength: 8
            },
            email: {
                required: true,
                email: true
            },
            tresc: {
                required: true

            }
        },
        messages: {
            name:{
                required: "Proszę podać Nazwisko i Imię",
                minlength: "Minimalna długość nazwy to 4 znaki"
            },
            tel:{
                required: "Proszę podać numer telefonu",
                minlength: "Minimalna długość numeru to 8 znaków"
            },
            
            email:{
                required: "Wprowadź adres e-mail",
                email: "Wprowadź poprawny adres e-mail"
            },
            tresc:{
                required: "Proszę wprowadzić treść wiadomości"
                
            }
        },
        success: function(label) {
        //label.text("ok!").addClass("success");
        },
        submitHandler: function() {
            var serialized_form = $('.mailme').serialize();
            $.ajax({
                data: serialized_form,
                url: 'http://trojan.katowice.pl/index.php/oferta/wyslij_zapytanie',
                type: 'post',
                success: function(msg){
                    if(msg == 'success') { 
                        $('.contact-form').hide();
                        $('.tab.tab1').html('<div class="tenkju">Dziękujemy, wiadomość została wysłana</div>');
      
                    }
                }
            })
        
      
        }
    });
    $(".form-mail").validate({
        errorElement: "p",
        rules: {
            name: {
                required: true,
                minlength: 2
            },

            email: {
                required: true,
                email: true
            },
            tresc: {
                required: true

            }
        },
        messages: {
            name:{
                required: "Proszę podać Nazwisko i Imię",
                minlength: "Minimalna długość nazwy to 4 znaki"
            },
            tel:{
                required: "Proszę podać numer telefonu",
                minlength: "Minimalna długość numeru to 8 znaków"
            },
            
            email:{
                required: "Wprowadź adres e-mail",
                email: "Wprowadź poprawny adres e-mail"
            },
            tresc:{
                required: "Proszę wprowadzić treść wiadomości"
                
            }
        },
        success: function(label) {
        //label.text("ok!").addClass("success");
        },
        submitHandler: function() {
            var serialized_form = $('.form-mail').serialize();
            $.ajax({
                data: serialized_form,
                url: 'http://trojan.katowice.pl/index.php/oferta/wyslij_zapytanie_formularz',
                type: 'post',
                success: function(msg){
                    if(msg == 'success') { 
                        $('.form-mail').hide();
                        $('#side-form').html('<div class="tenkju">Dziękujemy, wiadomość została wysłana</div>');
      
                    }
                }
            })
        
      
        }
    });
   
});



