$(document).ready(function() {
    $("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;
        }
    });

    // slider

    $("#slider").easySlider({
        controlsShow:		false,
        controlsFade:		true,
        firstShow:		false,
        lastShow:		false,
        vertical:		false,
        speed:          2000,
        auto:			true,
        pause:			8000,
        continuous:		true,
        numeric: 		false
    });

    // strona główna slide

    var wysokosc = $("#main").height();
    var top = 360;
    var powieksz = 290;
    var licz = 0;

    $("#srodek").ready(
        function(){
                $("#main-dol").css({"height": wysokosc});
        }
    );

    $(".zobacz").click(
        function(){
            if(licz == 0){
                $("#main").animate({
                    "top": "-="+top+"px",
                    "height": "+="+powieksz+"px"
                }, 1500);
                $("#more").css({"display": "block"});
                $("#main-dol").animate({"height": powieksz-top+wysokosc+"px"}, 1500);
                licz = 1;
				return false;
            }else{
               /* $("#main").animate({
                    "top": "+="+top+"px",
                    "height": "-="+powieksz+"px"
                }, 1500);
                $("#more").css({"display": "none"});
                $("#main-dol").animate({"height": wysokosc+"px"}, 1500);
                licz = 0;*/
            }
        }
    );
});
