    $(document).ready(function(){
      var from = $.color(255, 255, 255);
      var to = $.color(0, 0, 0);
      var grad = $.colorgrad(from, to, 9);
      
      $("#preview #gradient a").each(function(i) {
        $(this).click(function() {
          $(".back").css("background-color", $(this).css("background-color"))
          return false;
        })
        if (i != 9) $(this).css("background-color", grad.grad(i).hexHTML());
        else $(this).css("background-color", to.hexHTML());
      });

      $("#mozgallery #all a").click(function(e){
        $("#mozgallery #all").hide();
        $("#mozgallery #preview").show();
        $("#mozgallery #preview .image img").attr("src", this);
        $("#mozgallery #preview .image img").attr("id", "full_" + this.id);
        $(".back").css("background-color", "rgb(85, 85, 85)")
        return false;
      });
      
      $("#close a").click(function(){
        $("#mozgallery #preview").hide();
        $("#mozgallery #all").show();
        $(".back").css("background-color", "#D5C6A6");
        return false;
      });
      
      $("#prev a").click(function(){
        curid = $("#mozgallery #preview img").attr("id").replace("full_image_", "");
        var previd = parseInt(curid) + 1;

        if(previd >= $("#mozgallery #all a").length) {
          alert('конец');
          return false;
        }
        newsrc = $("#mozgallery #all a[id=image_"+ previd +"]").attr("href");
        $("#mozgallery #preview .image img").attr("src", newsrc);
        $("#mozgallery #preview .image img").attr("id", "full_image_"+previd);
        
        return false;
      });

      $("#next a").click(function(){
        curid = $("#mozgallery #preview img").attr("id").replace("full_image_", "");
        var nextid = parseInt(curid) - 1;

        if(nextid < 0) {
          alert('начало');
          return false;
        }
        newsrc = $("#mozgallery #all a[id=image_"+ nextid +"]").attr("href");
        $("#mozgallery #preview .image img").attr("src", newsrc);
        $("#mozgallery #preview .image img").attr("id", "full_image_"+nextid);
        
        return false;
      });
    });

