$(document).ready(function(){
    $('ul#banner').innerfade({
            animationtype: 'fade',
            speed: 2000,
            timeout: 7000,
            type: 'sequence',
            containerheight: '276px'
    });

    $("a[rel^='lightbox']").prettyPhoto({theme:'facebook'});

    //newsletter

    $('#mail').focus(function() {
        if (this.value == this.defaultValue){
                this.value = '';
        }
        if(this.value != this.defaultValue){
                this.select();
        }
    });
    
    $('#mail').blur(function() {
        if ($.trim(this.value) == ''){
                this.value = (this.defaultValue ? this.defaultValue : '');
        }
    });

    $("#newsletter form").submit(function(mail){
        var regex = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9_\.\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
        var mail = $("#mail").val();
        if (!regex.test(mail)){
            $("#k_newsletter").css({"opacity": "0.7"}).text("Wprowadź poprawnie adres e-mail.").fadeIn('slow').delay(3000).fadeOut('slow');
            return false;
        }else{
            $.ajax({
                url: "functions/newsletter.php",
                global: false,
                type: "POST",
                data: ({mail : $("#mail").val()}),
                dataType: "html",
                success: function(msg){
                    if(msg=="IN"){
                        $("#k_newsletter").css({"opacity": "0.7"}).text("Dziękujemy! Twój mail został zapisany.").fadeIn('slow').delay(5000).fadeOut('slow');
                    }else{
                        if(msg=="OUT"){
                            $("#k_newsletter").css({"opacity": "0.7"}).text("Dziękujemy! Twój mail został usunięty z bazy.").fadeIn('slow').delay(5000).fadeOut('slow');
                        }else{
                            $("#k_newsletter").css({"opacity": "0.7"}).text("UWAGA!!! Błąd. Spróbuj ponownie.").fadeIn('slow').delay(5000).fadeOut('slow');
                        }
                    }
                }
            });
        return false;
        }
    });
});
