function gallery(galleryid, arrow, stringid, photo_number) { if (stringid == null && photo == null) { var gallery = galleryid.parentElement.parentElement.getElementsByTagName('*'); photo_number = 0; }else{ var gallery = document.getElementById(stringid).getElementsByTagName('*'); photo_number -= 1; } var type; for (var i = 0; i < gallery.length; i++) { if (gallery[i].id == "gallery_photo") { var photo = gallery[i]; var photo2 = gallery[i].getElementsByTagName('img')[0]; type = ""; if (photo.hasAttribute("type")) { type = photo.getAttribute("type"); } } if (gallery[i].id == "counter") { var counter = gallery[i]; } if (gallery[i].id == "counter_all") { var counter_all = gallery[i]; } if (gallery[i].id == "gallery_photos") { var gallery_photos = gallery[i]; } } var photos = gallery_photos.getElementsByTagName('img'); if (type == "" || type == "img") { photo.setAttribute("style", "background-image: url("+photos[photo_number].src+")"); } if (type == "doc") { photo2.setAttribute("src", photos[photo_number].src); } var photo_max = photos.length; if (stringid != null && photo != null) { counter.innerHTML = photo_number + 1; } var gallery_count = Number(counter.innerHTML) -1; if (arrow == "left") { gallery_count -= 1; } if (arrow == "right" && gallery_count != photo_max) { gallery_count += 1; } if (arrow == "left" && gallery_count == -1) { gallery_count = photo_max-1; } if (arrow == "right" && gallery_count == photo_max) { gallery_count = 0; } if (arrow == "left" && gallery_count != 0 || arrow == "right" && gallery_count != photo_max) { if (type == "" || type == "img") { photo.setAttribute("style", "background-image: url("+photos[gallery_count].src+")"); } if (type == "doc") { photo2.setAttribute("src", photos[gallery_count].src); } } counter_all.innerHTML = photo_max; counter.innerHTML = gallery_count+1; }