if (!LubinoGal) var LubinoGal = {
        onload: true,
        HIDDEN: document.layers ? "hide" : "hidden",
        VISIBLE: document.layers ? "show" : "visible",
        pictures: [],
        initialize: function () {
                LubinoGal.walkElementsForGallery(document.body.childNodes[0], 1);
        },
        nodeOperation: function(node) {
                var gi = 0;
                if (node.src && (gi = node.src.indexOf('/gallery/')) >= 0) {
                        node.className = 'pointer';
                        node.border = '0';
                        var t = node.nextSibling;
                        if (t) {
                                t=t.nextSibling;
                                if (t) t = t.innerHTML;
                        }
                        var name = !t || t=='' ? node.title ? node.title : node.alt : t;
                        if (name == '') name = null;
                        var index = LubinoGal.pictures.length;
                        LubinoGal.pictures.push([node.src.replace('.160.jpg', '.800.jpg'), name])
                        node.onclick = function () {
                                LubinoGal.showGalleryDiv(index);
                        };
                        return true;
                }
                return false;
        },
        walkElementsForGallery: function(node, depth) {
                var skipre = /^(script|style|textarea|iframe)/i;
                var count = 0;
                var add = false;
                while (node && depth > 0) {
                        count ++;
                        if (count >= 3000) {
                                var handler = function() {
                                        walkElementsForGallery(node, depth);
                                };
                                setTimeout(handler, 50);
                                return;
                        }

                //if (node.src.substring(0,12)=='rs/3/gallery') s += ','+node.nodeType+node.src;
                        if (node.nodeType == 1) { // ELEMENT_NODE
                                if (!skipre.test(node.tagName)) {
                                        if (node.childNodes.length > 0) {
                                                node = node.childNodes[0];
                                                depth ++;
                                                continue;
                                        } else {
                                                if (LubinoGal.nodeOperation(node)) add = true;
                                        }
                                }
                        }
                        if (node.nextSibling) {
                                node = node.nextSibling;
                        } else {
                                while (depth > 0) {
                                        node = node.parentNode;
                                        depth --;
                                //nodestemp+=" )";
                                        if (node.nextSibling) {
                                                node = node.nextSibling;
                                                break;
                                        }
                                }
                        }
                }

                if (add && !document.getElementById("gallery_div_id")) LubinoGal.addGalleryDivToBody();
        },

        showGalleryDivNow: function() {
                var div = document.getElementById("gallery_div_id");
                var ifrm = document.getElementById("gallery_frame_id");
                var img = div.childNodes[0];
                if (img.width < 29 || img.height < 31) {
                        window.setTimeout(LubinoGal.showGalleryDivNow, 100);
                        return;
                }
                div.style.visibility = LubinoGal.VISIBLE;
                ifrm.style.visibility = LubinoGal.VISIBLE;
                var w = window.innerHeight ? window.innerWidth : document.documentElement.clientWidth;
                var h = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight;
                ifrm.style.left = div.style.left = Math.max(0, Math.max(document.documentElement.scrollLeft, document.body.scrollLeft) + Math.round(((w - img.width) / 2 - 15))) + 'px';
                ifrm.style.top = div.style.top = Math.max(0, Math.max(document.documentElement.scrollTop, document.body.scrollTop) + Math.round(((h - img.height) / 2 - 33))) + 'px';
                ifrm.style.width = div.style.width = (img.width + 30) + "px"
                ifrm.style.height = div.style.height = (img.height + 66) + "px";
        },
        showGalleryDiv: function(index) {
                var div = document.getElementById("gallery_div_id");
                div.style.visibility = LubinoGal.HIDDEN;
                var ifrm = document.getElementById("gallery_frame_id");
                ifrm.style.visibility = LubinoGal.HIDDEN;
                var pic = LubinoGal.pictures[index];
                var url = pic[0];
                var name = pic[1];
                if (name == null) name = '<a href="' + url + '" target="_blank">' + url + '</a>';
                div.innerHTML = '<img onclick="LubinoGal.hideGalleryDiv()" style="margin:15px" src="' + url + '" /><br />' + name;
                window.setTimeout(LubinoGal.showGalleryDivNow, 100);
        },
        hideGalleryDiv: function() {
                var div = document.getElementById("gallery_div_id");
                div.style.visibility = LubinoGal.HIDDEN;
                var ifrm = document.getElementById("gallery_frame_id");
                ifrm.style.visibility = LubinoGal.HIDDEN;
        },
        addGalleryDivToBody: function() {
                var ifrm = document.createElement("iframe");
                ifrm.setAttribute("id", "gallery_frame_id");
                //ifrm.setAttribute("src","javascript:false");
                ifrm.setAttribute("frameborder", "0");
                ifrm.setAttribute("allowtransparency", "true");
                ifrm.setAttribute("scrolling", "no");
                ifrm.setAttribute("marginwidth", "0");
                ifrm.setAttribute("marginheight", "0");
                ifrm.setAttribute("style", "position:absolute;display: block width:400px;z-index:998;top:10px;left:10px;filter:alpha(opacity=0);");
                if (document.all) {
                        //"position:absolute; left:0; top:0px; display:block; filter:alpha(opacity=0);"
                        ifrm.style.display = "block";
                        ifrm.style.position = "absolute";
                        ifrm.style.width = "400px";
                        ifrm.style.zIndex = "998";
                        ifrm.style.top = "10px";
                        ifrm.style.left = "10px";
                        ifrm.style.filter = "alpha(opacity=0)";
                        ifrm.style.opacity = "0";
                }
                document.body.appendChild(ifrm);

                var newdiv = document.createElement("div");//div
                newdiv.setAttribute("id", "gallery_div_id");
                newdiv.setAttribute("style", "text-align: center;font-size: 13px;font-weight: bold;display: block;visibility:hidden;position:absolute; width:400px;z-index:999;background-color: #ffffff;border: 1px solid #DBDBDB;");
                if (document.all) {
                        newdiv.style.fontSize = "13px";
                        newdiv.style.fontWeight = "bold";
                        newdiv.style.display = "block";
                        newdiv.style.visibility = LubinoGal.HIDDEN;
                        newdiv.style.position = "absolute";
                        newdiv.style.width = "400px";
                        newdiv.style.backgroundColor = "#ffffff";
                        newdiv.style.borderStyle = "solid";
                        newdiv.style.borderColor = "#DBDBDB";
                        newdiv.style.borderWidth = "1px";
                        newdiv.style.textAlign = "center";
                        newdiv.style.zIndex = "999";
                }
                newdiv.innerHTML = '&nbsp;';
                document.body.appendChild(newdiv);

        }
};

if (LubinoGal.onload) {
        LubinoGal.onload = false;
        if (window.attachEvent) {
                window.attachEvent('onload', LubinoGal.initialize);
        } else if (window.addEventListener) {
                window.addEventListener('load', LubinoGal.initialize, false);
        } else {
                var __onload = window.onload;
                window.onload = function(e) {
                        if (__onload) __onload(e);
                        LubinoGal.initialize();
                };
        }
}
