window.onload = function() {
    if (typeof(interfaceLoad)=='function') {
        interfaceLoad();
    }
}
function showPhoto(el)
{
var id = el.getAttribute('photo_id');
var w = el.getAttribute('width')*1+40;
var h = el.getAttribute('height')*1+20+100;
var x = Math.floor((screen.width - w - 10)/2);
var y = Math.floor((screen.height - h - 60)/2);
var win = window.open('/picture/?id='+id, 'IMAGE_WINDOW', 'dependent=yes, disrectories=no, width='+w+', height='+h+', innerWidth='+w+', innerHeight='+h+', location=no, menubar=no, resizable=no, screenX='+x+', screenY='+y+', scrollbars=yes, titlebar=no, toolbar=no');
win.focus();
}

function deleteFileInput(btnEl) {
    btnEl.parentNode.parentNode.removeChild(btnEl.parentNode);
}

function appendFileInput(btnEl) {
    var cnt = btnEl.parentNode;
    var inputs = cnt.getElementsByTagName('input');
    if (!inputs[ inputs.length - 1 ].value)
        return;
    var d = document.createElement('div');
    d.className = 'file';
    var i = document.createElement('input');
    i.type = 'file';
    i.name = 'files';
    d.appendChild(i);
    var s = document.createElement('span');
    s.className = 'btn';
    s.innerHTML = 'удалить';
    s.onclick  = function() { deleteFileInput(this); }
    d.appendChild(s);
    cnt.insertBefore(d, btnEl);
}

function multipleGalleries(){
    this.name = "MultiGallery";
    this.gallery = null;
    this.start();
}

/* Каталог галерей */
multipleGalleries.prototype = {
    start: function(){
        var self = this;
        $(".galleries .g-item").each(function(){
            var links = $(this).find("a.shg");
            if(links.length>0){
                $(links[0]).click(function(){
                    var gallery_id = this.href.split("?")[1].split("=")[1];
                    if(self.gallery){ self.gallery = null };
                    self.gallery = new FBox({
                            animation: true,
                            imagesList: true,
                            imagesListWidth: 150,
                            useLoaderAnim: true,
                            loaderParams: {
                                animatioLength: 400,
                                animationStep: 50,
                                animationTime: 100
                            },
                            showOverlay: true,
                            navigationButtons: true,
                            navigationButtonsHover: false,
                            ajax: {
                                url: '/ajax/',
                                iface: 'gallery',
                                gallery_id: gallery_id
                            },
                            constraints: {
                                minWidth: 470,
                                minHeight: 465,
                                maxWidth: 900,
                                maxHeight: 700
                            }
                        });
                    self.gallery.show();
                    return false;
                });
                $(links[1]).click(function(){
                    $(links[0]).trigger('click');
                    return false;
                })
            }
        });
    }
}

