$(document).ready(function(){
    $(".bigpic").addClass("bigpic_cut");
    
    if($(".bigpic img").size() > 1) {
        $(".bigpic img").not(":first-child").hide();
        $(".bigpic img").each(function() {
            var imgId = $(this).attr("rel");
            var src = $(this).attr("src");
            var smallCopy = $("<li><a href='#'><img /></a></li>");

            if(imgId) {
                $("img", smallCopy).attr("src", "http://www.cardplace.ru/newthumbs/thumbs_70/" + imgId);
                $("a", smallCopy).attr("rel", imgId);
            } else {
                $("img", smallCopy).attr("src", src);
            }
            $("a", smallCopy).attr("href", src);
            $(".smallpics").append(smallCopy);

        });

        $(".smallpics a").click(function() {
            var id = $(this).attr("rel");
            var href = $(this).attr("href");

                    $(".bigpic img").hide();

            if(id) {
                $(".bigpic img[rel=" + id + "]").show();
            } else {
                $(".bigpic img[src=" + href + "]").show();
            }
            return false;
        });
    }
    
    $('a.fancybox').fancybox();

});
