
(function($){
     $.fn.extend({
          center: function () {
                return this.each(function() {
                        var top = ($(window).height() - $(this).outerHeight()) / 2 + $(window).scrollTop();
                        var left = ($(window).width() - $(this).outerWidth()) / 2 + $(window).scrollLeft();
                        $(this).css({position:'absolute', margin:0, top: (top > 0 ? top : 0)+'px', left: (left > 0 ? left : 0)+'px'});
                });
        }
     });
})(jQuery);

jQuery.fn.vcenter = function() 
{
	var w = $(window);
    this.css("top",(w.height()-this.height())/2+w.scrollTop() + "px");
	return this;
}

function fon(){
    $("#opaco").toggle();
}

function loader(){
    $("#loader").center().toggle();
}

$(document).ready(function(){
    
    $("#opaco").height($(document).height());
    
    //кнопка закрытия окна сообщения
    $("#popup img").click(function(){
        $("#popup").toggleClass('hidden');
        fon();
    });
    
    
    //увеличение фотки
    $("img.bigbox").click(function(){
        fon();
        var wrapf = $("#bigfoto");
        var image = wrapf.find("img");
        image.attr('src','');
        image.attr('src', '/fgoods/'+$(this).attr('name')).load(function(){
            wrapf.center().show();
        });
    });
    $("#bigfoto").click(function(){
        fon();
        $(this).hide();
    });
    
    
    //Форма отправки отзыва
    $("#form_add_feedbacks").submit(function(){
        $("#form_add_feedbacks #message").hide();
        var options = {
            dataType: "json",
            success: function(data) {
                loader();
                if (data.result == false){
                    $("#form_add_feedbacks #message").html(data.errors).show();
                }else{
                    document.location.href = '/feedbacks';
                }
            }
        }; 
        loader();
        $(this).ajaxSubmit(options);
        return false;
    });

});

