﻿
var PhotoContent = new Object();
PhotoContent = {
    fill:function(){
       PhotoContent.count = 0;
       PhotoContent.pages = 0;
       PhotoContent.items = new Array();
       var data = this.req.responseXML;
       if(data.childNodes.length>0){
           PhotoContent.area = document.getElementById("PhotoContent");
           PhotoContent.count = data.firstChild.getAttribute("count");
           PhotoContent.pages = Math.ceil(PhotoContent.count/20);
           PhotoContent.index = 0;
           if(parseInt(PhotoContent.count)>20)document.getElementById("prewNext").style.display = 'block';
           for(var i=0;i<data.documentElement.childNodes.length;i++)
           {
                var item = data.documentElement.childNodes[i];
                var el = new Object();
                if(item.nodeType==1)
                {
                    el.link = "/photo.aspx?id="+item.getAttribute("wid")+(item.getAttribute("aid")!=""?"&t="+item.getAttribute("aid"):"");
                    el.imgsrc = "/Admin/GetFile.ashx?prev=1&id="+item.getAttribute("id");
                    el.id = item.getAttribute("wid");
                    el.alt = item.getAttribute("wname");
                    el.type = item.getAttribute("aid");
                    el.pris = item.getAttribute("pr");
                    PhotoContent.items.push(el);
                    if(i<20) PhotoContent.dom(el);		
                }
            }
        }
    },
    prev:function(){
        PhotoContent.area.innerHTML = "";
        if(PhotoContent.index!=0)PhotoContent.index--;
        else PhotoContent.index = PhotoContent.pages-1;
        var start = PhotoContent.index*20;
        var end = (start+20)>PhotoContent.items.length?PhotoContent.items.length:start+20;;
        for(var i=start;i<end;i++){
            PhotoContent.dom(PhotoContent.items[i]);
        }
    },
    next:function(){
        PhotoContent.area.innerHTML = "";
        if(PhotoContent.index!=PhotoContent.pages-1)PhotoContent.index++;
        else PhotoContent.index = 0;
        var start = PhotoContent.index*20;
        var end = (start+20)>PhotoContent.items.length?PhotoContent.items.length:start+20;
        for(var i=start;i<end;i++){
            PhotoContent.dom(PhotoContent.items[i]);
        }
    },
    dom:function(el){
        if(el.pris!="coll"){
        var link = document.createElement("a");
        link.href = el.link;
        var img = document.createElement("img");
        img.src = el.imgsrc;
        img.alt = el.alt;
        link.appendChild(img);
        PhotoContent.area.appendChild(link);
        }else{
            var wr = document.createElement("div");
            wr.className = "CollectionDiv";
            wr.style.styleFloat = "left";
            var link = document.createElement("a");
            link.href = el.link;
            var img = document.createElement("img");
            img.src = el.imgsrc;
            img.alt = el.alt;
            img.style.display = "block";
            link.appendChild(img);
            wr.appendChild(link);
            var btn = document.createElement("img");
            btn.src = "/Images/dic_btn.gif";
            btn.alt = "удалить из коллекции";
            btn.className = "CollectionBtn";
            btn.onclick = function(){
                if(confirm("Вы уверенны?"))new net.ContentLoader("/GetPhoto.ashx",reload,null,"POST","cmd=delet&id="+el.id);
                else return;
            }
            wr.appendChild(btn);
            PhotoContent.area.appendChild(wr);
        }	
    }
}

function reload(){
    PhotoContent.area.innerHTML = "";
    new net.ContentLoader('/GetPhoto.ashx',PhotoContent.fill,null,'POST','collection=1')
}