$(document).ready(function() {

	$('.blockOverlay').attr('title','Click to unblock').click($.unblockUI);
	
    if (document.images)
    {
      preload_image = new Image(138,14);
      preload_image.src="images/default/top_rzecz_bg_2.gif";

      preload_image2 = new Image(138,1);
      preload_image2.src="images/default/top_rzecz_bg_2a.gif";
    }

    $("#my_stuff_trigger").mousedown(function(){
        $("#my_stuff").toggle();

    });

    $("#my_stuff_trigger").parent().hover(
      function () {

      },
      function () {
        $("#my_stuff").hide();
      }
    );

    $(".close").mousedown(function () {
//        $(this).parent().css("display", "none");
        $.unblockUI({});
    });

    $(".close_2").mousedown(function () {
//        $(this).parent().css("display", "none");
        $.unblockUI({});
    });

    $("span.passwd").mousedown(function () {
//        $(this).parent().css("display", "none");
//        $("#passwd_form").css("display","block");
         $.blockUI({
            message:  $("#passwd_form"),
            css: {
            },

            baseZ: 1000,
            centerX: true, // <-- only effects element blocking (page block controlled via css above)
            centerY: true,
            allowBodyStretch: true,
            constrainTabKey: true,
            fadeOut:  400,
            applyPlatformOpacityRules: true
        });
    });


    $('#passwd_remind').click(function (){
        var email = $('#content-text_element').val();

        if (! isValidEmail(email)) {
            alert("Podałeś/aś błędny adres e-mail");
            return false;
        }
                $.post(
                    'default/auth/ajax-passwd-remind',
                    {email: email},
                    function(response) {
                        if(response.send == true) {
	                        $.blockUI({
					            message: $("#passwd_sent"),
					            css: {
					            },

					            baseZ: 1000,
					            centerX: true, // <-- only effects element blocking (page block controlled via css above)
					            centerY: true,
					            allowBodyStretch: true,
					            constrainTabKey: true,
					            fadeOut:  400,
					            applyPlatformOpacityRules: true
					        });
                        }
                        else {
                            window.location = '/nie-poznajemy-cie.html';
                        }
                    },
                    'json'
                );

    });

    $("input#login-passwd").keypress(function (e) {
        if (e.which == 13) {
            $("input#login-button").click();
        }
    });

    
if (!_ni_cart) {

    $(".top-secret").click(function() {
         $.blockUI({
            message:  $("#login_form"),
            css: {
            },

            baseZ: 1000,
            centerX: true, // <-- only effects element blocking (page block controlled via css above)
            centerY: true,
            allowBodyStretch: true,
            constrainTabKey: true,
            fadeOut:  400,
            applyPlatformOpacityRules: true
        });

        var url = $(this).attr("href");
        // wyświetlenie panelu logowania
//        $("#login_form").css("display", "block");
        $("input#login-button").click(function() {
            var email = $("#login-email").val();
            var passwd = $("#login-passwd").val();
            var action = $("#action-login").attr('checked');

            if(action == true) {

                $.post(
                    'default/auth/ajax-login',
                    {email: email, passwd: passwd},
                    function(response) {
                        if(response.is_logged == true) {
                            window.location = url;
                        }
                        else {
                            window.location = '/nie-poznajemy-cie.html';

                        }
                    },
                    'json'
                );
            }
            else {
                window.location = '/jestem-tu-nowy.html';
            }
        });

        return false;
    });
}

});

