    function picturesArchive ( val ){
        
        //arguments
        this.origData           = val.data;
        this.dataParsed         = val.dataParsed;
        this.chathostID         = val.chathostID;
        this.chathostNick       = val.chathostNick;
        this.chathostCategoryID = val.chathostCategoryID;
        this.pathPrefixNormal   = val.pathPrefNormal;
        this.pathPrefixOverlay  = val.pathPrefOverlay;
        this.pathPrefixBig      = val.pathPrefBig;
        this.pathPrefixHD       = val.pathPrefHD;
        this.isChathostOnline   = val.isChathostOnline;
        this.isDetachedChild    = val.isDetachedChild;
        this.debug              = val.debug;
        this.zoomSDFactor       = val.zoomSDFactor || 1.75;
        this.iconHDSrc          = val.iconHDSrc;
        this.zoomSD             = val.zoomSD;
        this._archiveSelect     = val.archiveSelectID && document.getElementById(val.archiveSelectID);
        this._archiveList       = val.archiveListID && document.getElementById(val.archiveListID);
        this._contentPage       = val.contentPageID && document.getElementById(val.contentPageID);
        this._archCurrentDate   = val.archCurrentDateID && document.getElementById(val.archCurrentDateID);
        this._archivePrev       = val.archivePrevID && document.getElementById(val.archivePrevID);
        this._archiveNext       = val.archiveNextID && document.getElementById(val.archiveNextID);
        this._photoCellUseDiv   = val.photoCellUseDiv;
        this._picContent        = val.contentID && document.getElementById(val.contentID);
        this._hasPicAccess      = val.hasPicAccess;
        this._oneRowOnly        = val.oneRowOnly;
        this._picEnlargeFunc    = val.picEnlargeFunc;
        this._onPicResize       = val.onPicResize;
        this._onPicDisplay      = val.onPicDisplay;
        this._imgSpacer         = val.imgSpacer || '/com/img/spacer.gif';
        this._imgOverlay        = val.imgOverlay || '/com/img/overlay.gif';
        this._logonLink         = val.logonLink || '/logon.html?ut=1&gotoURL=';
        this._popupTarget       = val.popupTarget || '[rel=galleryData] > [rel=galleryBody]';
        this._popupFooter       = val.popupFooter || '[rel=galleryData] > [rel=galleryFooter]';
        this._picDateFormat     = val.picDateFormat || 'E d NNN hh:mm:ss a';
        this._archDateFormat    = val.archDateFormat || 'dd NNN yyyy';
        this._popupPicDateFormat    = val.popupPicDateFormat || 'hh:mm:ss a';
        this._popupArchDateFormat   = val.popupArchDateFormat || 'E d NNN yyyy';
        this._cellWidth         = val.cellWidth || 126;
        this.dataRandomKeys    = typeof val.randomOrder != 'undefined' && val.randomOrder != null ? null : [];
        this._cookie            = interfaceCookieGet('photoarch');

        //variables
        //internal use
        this._curArchDate       = null;
        this._curArchName       = null;
        this._curPicSize        = {};
        this.currentPhotoIdx    = null;
        this.detachedWindow     = null;
        this.isDetachedParent   = false;
        this.easyBox            = null;
        this._hasJQuery         = false;
        this._oDates            = {};
        this._popupFooterData   = null;
        this._galleryTitle      = null;
        this._picTitle          = null;
        this._popupDefWidth     = 320;
        this._popupDefHeight    = 240;
        //external

        //locals
        var _xTime, _i, _j = 0, _lastVisibleIdx;

        if ( typeof formatDate == 'undefined' ) {
            includeResFileOnce('/com/js/date.js', 'js');
        }

        if (jQueryCheck()) {
            this._hasJQuery = true;
            if ( !$.easyBox ) {
                includeResFileOnce('/com/js/jquery.easybox.js', 'js');
            }
        }

        if (typeof this._cookie != 'object')
            this._cookie = {};

        if (typeof this.zoomSD == 'undefined' && 
            typeof this._cookie.zoomSD != 'undefined')
            this.zoomSD = this._cookie.zoomSD;

        if (this.origData) {
            _j = 0;
            this.dataParsed = [];
            for ( _i = 0; _i < this.origData.length; _i++ ){
                if (this.origData[_i] == '' ||
                    this.origData[_i][1] === null) {
                    continue;
                }
                this.dataParsed[_j] = {
                    idx: _j,
                    id: this.origData[_i][0],
                    time: this.origData[_i][1],
                    view: this.origData[_i][2],
                    path: this.origData[_i][3],
                    HDWidth: this.origData[_i][6],
                    HDHeight: this.origData[_i][7],
                    prevID: null,
                    nextID: null
                }

                if ( !this.dataParsed[_j].view ){
                    if (typeof _lastVisibleIdx != 'undefined') {
                        this.dataParsed[_j].prevID = _lastVisibleIdx;
                        this.dataParsed[_lastVisibleIdx].nextID = _j;
                    }
                    _lastVisibleIdx = _j;
                }

                _xTime = 'x' + Math.floor( this.dataParsed[_j].time / 86400 );

                if ( typeof this._oDates[ _xTime ] == 'undefined' )
                    this._oDates[ _xTime ] = [];

                this._oDates[_xTime].push ( _j );

                if (this.dataRandomKeys != null)
                    this.dataRandomKeys.push ( _j );

                _j++;
            }

            if (this.dataRandomKeys == null)
                this.dataRandomKeys = val['randomOrder'];
            else
                this.dataRandomKeys.shuffle();
        }

        if (this._hasJQuery && this._popupFooter)
            this._popupFooterData = $(this._popupFooter).contents();

        return true;
    }

    picturesArchive.prototype = {
        loadSelector : function() {
            var iTime, oTime, sContent, oOption;

            this.firstDate = jsUrlHash.get('AL');
            
            if ( typeof this._oDates[ 'x'+ this.firstDate ] == 'undefined' ) {
                this.firstDate = false;
            }

            for( var sKey in this._oDates ){
                iTime = parseInt( sKey.substring( 1 ) );
                if (!this.firstDate)
                    this.firstDate = iTime;
                oTime = new Date();
                oTime.setTime( iTime * 86400000 );
                sDate = formatDate( oTime, this._archDateFormat );
                sCount = ' (' + this._oDates[ sKey ].length + ')';

                if (typeof this._archiveSelect != "undefined" && this._archiveSelect != null){

                    // DropDown append
                    oOption = document.createElement('option');
                    oOption.appendChild( document.createTextNode( sDate + sCount ) );
                    oOption.value = iTime;

                    if ( 'function' == typeof this._archiveSelect.add )
                        this._archiveSelect.add( oOption, null );
                    else
                        this._archiveSelect.appendChild( oOption );
                        this._archiveSelect.picturesArchive = this;
                        this._archiveSelect.onchange = function (){
                        this.picturesArchive.showArchive(this.value);
                    }
                }

                // dataList append
                if (typeof this._archiveList != "undefined" && this._archiveList != null){
                    oSP = document.createElement('SPAN');
                    oSP.appendChild ( document.createTextNode ( sCount ) );
                    oDD = document.createElement('li');
                    oDD.picturesArchive = this;
                    oDD.appendChild( new this.getListLink( sDate, iTime, this ) );
                    oDD.appendChild( oSP );
                    this._archiveList.appendChild( oDD );
                }
            }
        },

        markSelectorOld : function( val ){
            for ( var i = 0; i < this._archiveSelect.options.length; i++ ){
                var item = this._archiveSelect.options[ i ];

                if ( item.value == val ){
                    this._archiveSelect.selectedIndex = i;
                    break;
                }
            }
        },

        markSelector : function( val ){
            var selID, options = this._archiveSelect.options;
            var optionsLen = options.length;
            if ( typeof val == 'undefined')
                val = this._curArchDate;
            else
                this._curArchDate = val;

            for (var i = 0; i < optionsLen; i++){
                var item = this._archiveSelect.options[i];

                if (item.value == val){
                    this._archiveSelect.selectedIndex = i;
                    var selID = i;
                    break;
                }
            }

            // Previous/next navigation
            if (!this._archiveNext || !this._archivePrev) return true;
            var next = this._archiveNext.getElementsByTagName('a');
            var prev = this._archivePrev.getElementsByTagName('a');

            if (selID<optionsLen-1 && optionsLen>0) {
                next[0].picturesArchive = this;
                next[0].rel= options[selID+1].value;
                next[0].onclick = function(){
                    this.picturesArchive.showArchive(next[0].rel);
                    return false
                };
                next[0].removeAttribute('style');
                next[0].parentNode.removeAttribute('style');
                next[0].style.display='block';
            } else {
                next[0].style.display='none';
                next[0].parentNode.style.background='none';
            }

            next[0].parentNode.getAttribute('style');

            if (selID>0) {
                prev[0].picturesArchive = this;
                prev[0].rel= options[selID-1].value;
                prev[0].onclick = function(){
                    this.picturesArchive.showArchive(prev[0].rel);
                    return false
                };
                prev[0].removeAttribute('style');
                prev[0].parentNode.removeAttribute('style');
                prev[0].style.display='block';
            } else {
                prev[0].style.display='none';
                prev[0].parentNode.style.background='none';
            }
            prev[0].parentNode.getAttribute('style');
        },

        // returns object
        getListLink : function(sData, stamp, picturesArchive){
            var that = this;

            this.date = stamp;
            this.picturesArchive = picturesArchive;

            var a = document.createElement('A');

            a.appendChild( document.createTextNode( sDate ) );
            a.id = 'AL_'+stamp;
            a.href = jsUrlHash.set( 'AL', stamp, true );

            a.onclick = function(){
                that.picturesArchive.showArchive( that.date );
                if ( 'object' == typeof this._contentPage && this._contentPage != null &&
                     'number' == typeof this._contentPage.scrollTop )
                    this._contentPage.scrollTop = 0;
                this.blur();
                return false;
            }

            return a;
        },

        frameResetButtons : function () {
            $('#galleryFooter #prevBtn').css({visibility: 'hidden'});
            $('#galleryFooter #nextBtn').css({visibility: 'hidden'});
            $('#galleryFooter #zoomBtn').css({visibility: 'hidden'});
            $('#galleryFooter #chatBtn').css({visibility: 'hidden'});
            $('#galleryFooter #detachBtn').css({visibility: 'hidden'});
        },

        loadBigPic : function (picIdx ) { //click on pic archive
            var that = this;

            if (that.isDetachedParent && that.detachedWindow) {
                that.detachedWindow.focus();
                return that.detachedWindow.archive.displayPhoto(picIdx);
            }

            // reset title
            $('#galleryHeader').hide().empty();

            // reset initial size
            $('#galleryBody .photo').empty().width( that._popupDefWidth ).height( that._popupDefHeight );

            that.easyBox = $.easyBox({
                    target  : that._popupTarget,
                    type    : 'inline',
                    onShow  : that.frameResetButtons
                });

            this.displayPhoto( picIdx );
            return false;
        },

        close: function () {
            if (this.easyBox)
                this.easyBox.close();
        },

        _saveSettings : function () {
           interfaceCookieSet('photoarch', this._cookie);
        },

        getClientSize: function () {
            return clientSize = {
                width   : document.documentElement.clientWidth || document.body.clientWidth,
                height  : document.documentElement.clientHeight || document.body.clientHeight
            }
        },

        displayPhoto : function (picIdx) {
            var oPhoto;
            var prevID, nextID;
            var that = this, zoomFactor = 1;
            if (typeof(picIdx) == 'undefined' && this.currentPhotoIdx != null) {
                picIdx = this.currentPhotoIdx;
            }
            this.currentPhotoIdx = picIdx;
            oPhoto = this.dataParsed[picIdx];

            if (!oPhoto) return false;

            that.frameResetButtons();

            if (that.zoomSD && !oPhoto.HDWidth)
                zoomFactor = that.zoomSDFactor;

            $('#galleryBody .photo')
                .css({opacity: 0.4})

            var tmpImg = new Image();
                    
            tmpImg.onload = function() {
                that._curPicSize = {
                    width: tmpImg.width * zoomFactor,
                    height: tmpImg.height * zoomFactor
                };
                
                if (typeof that._onPicResize == 'function') {
                    that._onPicResize(that._curPicSize.width,
                                      that._curPicSize.height);
                }

                $('#galleryBody .photo').width( that._curPicSize.width + 5 ).height( that._curPicSize.height + 5 );
                $('#galleryBody').width( that._curPicSize.width + 5 ).height( that._curPicSize.height + 5 );

                $('<img>')
                    .attr({
                            src     : tmpImg.src,
                            width   : that._curPicSize.width,
                            height  : that._curPicSize.height,
                            alt     : ''
                        })
                    .appendTo( $('#galleryBody .photo').empty())
                    .unbind('click')
                    .bind('click', function (e) {
                          that.easyBox.close();
                    });

                that._picTitle = new Date();
                that._picTitle.setTime( oPhoto.time * 1000);

                that._galleryTitle = formatDate( that._picTitle, that._popupArchDateFormat );
                that._picTitle = formatDate( that._picTitle, that._popupPicDateFormat );

                that.displayEasyBox();

                $('#galleryFooter #detachBtn').
                    css({visibility: 'visible'})
                    .unbind('click')
                    .bind('click', function (e) {
                        if (that.isDetachedChild) {
                            closeWindow();
                        } else {
                            that.isDetachedParent = !that.isDetachedParent;
                            if (that.isDetachedParent){
                                that.detachedWindow = popupWin('detachedPic', '/showpic.html', null, 320, 240, 0, 0, false, false, false, true);
                                if (that.detachedWindow) {
                                    if (that.detachedWindow.finishedLoading) {
                                        that.zoomSD = that.detachedWindow.archive.zoomSD;
                                        that.detachedWindow.archive.isDetachedChild = false;
                                        that.detachedWindow.archive.easyBox.close();
                                        that.detachedWindow.finishedLoading();
                                    }
                                    that.detachedWindow.focus();
                                } else {
                                    that.isDetachedParent = false;
                                    that.detachedWindow = undefined;
                                }
                            } else if (that.detachedWindow) {
                                that.detachedWindow.close();
                                that.detachedWindow = undefined;
                            }
                        }
                        return false;
                    });

                if (!that.isChathostOnline) {
                    $('#galleryFooter #chatBtn')
                        .css({visibility: 'visible', opacity: 0.4})
                        .unbind('click')
                        .bind('click', function (e) {
                                alert(translate(491));
                                return false;
                              });
                } else {
                    $('#galleryFooter #chatBtn')
                        .css({visibility: 'visible', opacity: 1})
                        .unbind('click')
                        .bind('click', function (e) {
                            if (that.isDetachedChild && window.parentWin && !window.parentWin.closed){
                                window.parentWin.redirect(undefined, '/accessvid.html?ci=' + that.chathostID + 
                                            (that.chathostNick ? '&cn=' + that.chathostNick : '') +
                                            (that.chathostCategoryID ? '&cti=' + that.chathostCategoryID : ''));
                                window.parentWin.focus();
                            } else {
                                redirect(undefined, '/accessvid.html?ci=' + that.chathostID + 
                                                (that.chathostNick ? '&cn=' + that.chathostNick : '') +
                                                (that.chathostCategoryID ? '&cti=' + that.chathostCategoryID : ''));
                            }
                            return false;
                        });
                }

                if (oPhoto.HDWidth) {
                    $('#galleryFooter #zoomBtn')
                        .css({visibility: 'visible', opacity: 0.4})
                        .unbind('click')
                        .bind('click', function (e) {
                                alert(translate(490));
                                return false;
                              });
                } else {
                    $('#galleryFooter #zoomBtn')
                        .css({visibility: 'visible', opacity: 1})
                        .unbind('click')
                        .bind('click', function (e) {
                                  that.zoomSD = !that.zoomSD;
                                  that._cookie['zoomSD'] = that.zoomSD;
                                  that._saveSettings();

                                  e.preventDefault();
                                  that.displayPhoto(oPhoto.idx);
                                  return false;
                              });
                }

                if (typeof(oPhoto.prevID) != 'undefined' &&
                    oPhoto.prevID != null) {
                    $('#galleryFooter #prevBtn')
                        .unbind('click')
                        .bind('click', function (e) {
                            e.preventDefault();
                            that.displayPhoto(oPhoto.prevID);
                            return false;
                        });
                    $('#galleryFooter #prevBtn').css({visibility: 'visible'});
                } else {
                    $('#galleryFooter #prevBtn')
                        .css({visibility: 'hidden'})
                        .unbind('click');
                }

                if (oPhoto.nextID) {
                    $('#galleryFooter #nextBtn')
                        .unbind('click')
                        .bind('click', function (e) {
                            e.preventDefault();
                            that.displayPhoto(oPhoto.nextID);
                            return false;
                        });
                    $('#galleryFooter #nextBtn').css({visibility: 'visible'});
                } else {
                    $('#galleryFooter #nextBtn')
                        .css({visibility: 'hidden'})
                        .unbind('click.gallery');
                }

                $('#galleryBody .photo')
                    .css({opacity: 1})

                if (typeof that._onPicDisplay == 'function') {
                    that._onPicDisplay();
                }

                tmpImg.onload = {};
                delete tmpImg;
            };
            
            tmpImg.src = (oPhoto.HDWidth ? that.pathPrefixHD : that.pathPrefixBig) + oPhoto.path;
        },

        displayEasyBox : function() {
            var that = this;
            that.easyBox = $.easyBox({
                    target  : that._popupTarget,
                    type    : 'inline',
                    title   : '<div>' +
                              '<span class="sname">Archive: </span>' + that._galleryTitle + '<br />' +
                              '<span class="sname">Time: </span>' + that._picTitle +
                              '</div>', 
                    onClose : function () {
                        if (that.isDetachedChild) {
                            closeWindow(false);
                        }
                    },
                    onOpen  : function () {
                        that._popupFooterData && this.setFooter( that._popupFooterData );
                    },
                    opacity : (that.isDetachedChild ? 1 : 0.4)
                });

            if (this.isDetachedChild)
                $('[rel="easyBoxClose"]').css({ visibility:'hidden' });

        },

        resizeEasyBox : function() {
            if (this.easyBox)
                this.easyBox.redraw();
        },

        // returns object
        getPhotoCell : function(picArc, bAuthorized, oPhoto, sLocation ){
            var that = this;

            var li  = document.createElement('LI');
            var a   = document.createElement('A');
            var img = document.createElement('IMG');
            var span= document.createElement('SPAN');

            var liPath  = bAuthorized ? picArc.pathPrefixNormal : picArc.pathPrefixOverlay;
            var isHDPhoto = ( oPhoto.HDWidth );

            li.style.backgroundImage = 'url(' + liPath + oPhoto.path + ')';

            var time = new Date();
            time.setTime( oPhoto.time * 1000);
            span.innerHTML = formatDate( time, picArc._picDateFormat );
            
            img.src = bAuthorized ? picArc._imgSpacer : picArc._imgOverlay;
            img.id = oPhoto.id;
            img.height = 120;
            img.width = 160;
            img.alt = '';
            img.picTitle = span.innerHTML;
            img._picEnlargeFunc = picArc._picEnlargeFunc;
            img.picPath = oPhoto.path;
            
            a.href = sLocation;

            a.onmouseout = function() {
                return function(){
                    window.status = '';
                    return true;
                }
            }();
            
            if ( !bAuthorized ) {
                a.onmouseover = function() {
                    return function(){
                        window.status = translate(234);
                        return true;
                    }
                }();
            } else {
                a.onmouseover = function() {
                    return function(){
                        window.status = translate(234);
                        return true;
                    }
                }();
                
                a.onclick = function( oImg ) {
                    return function(){
                        if (typeof oImg._picEnlargeFunc != 'undefined' && oImg._picEnlargeFunc){
                            oImg._picEnlargeFunc(oPhoto);
                        } else if (picArc.iconHDSrc ) {
                            picArc.loadBigPic(oPhoto.idx);
                        } else {
                            var width = (typeof popupWidth == 'undefined' ? 340 : popupWidth);
                            var height = (typeof popupHeight == 'undefined' ? 275 : popupHeight);
                            var r = popupWin ('ArchPhoto', '/showpic.html?PicFilename=' + picArc.pathPrefixBig + oPhoto.path, '',
                                              width, height, (screen.width - 400), 20, false, false, true);
                        }
                        return false;
                    }
                }( img );
            }

            if ( isHDPhoto && picArc.iconHDSrc ) {
                var icon = document.createElement('IMG');
                icon.src = picArc.iconHDSrc; //'/com/img/hdicon.gif';
                icon.width = 21;
                icon.height = 9;
                icon.alt = '';
                icon.title = 'High-definition photo';
                icon.className = 'icon';
                icon.style.position = 'absolute';
                icon.style.top = '3px';
                icon.style.right = '3px';
                icon.style.width = '21px';
                icon.style.height = '9px';
                icon.style.border = '0';
                icon.style.display = 'inline';

                a.appendChild( icon );

                
                icon = null;
            }

            a.appendChild( img );

            li.appendChild( a );
            li.appendChild( span );

            span = img = a = null;
            
            return li;
        },

        showSelection : function (startFrom, countLimit, full, picContent){
            while (this._picContent.hasChildNodes())
                this._picContent.removeChild(this._picContent.lastChild);

            if (full && startFrom && countLimit && this.dataRandomKeys.length - startFrom < countLimit)
                startFrom = 0;

            for (var i = startFrom; i < this.dataRandomKeys.length; i++){
                if (countLimit && i >= countLimit + startFrom)
                    break;

                this.insertPicture(this.dataRandomKeys[i], (typeof picContent != 'undefined' && picContent ? picContent : null));
            }
        },

        insertPicture : function ( picID, archDate ){
            var oPhoto = this.dataParsed[picID];

            if ( this._hasPicAccess || !oPhoto.view ) {
                li = new this.getPhotoCell( this, true, oPhoto, '#' );
            }
            else {
                li = new this.getPhotoCell( this, false, oPhoto, this._logonLink + 
                                            urlencode(window.location.pathname + window.location.search + 
                                                      (archDate ? jsUrlHash.set('AL', archDate, true ) : '')));
            }

            this._picContent.appendChild( li );
        },

        showArchive : function( archDate ){
            if ( 'object' == typeof archDate && archDate == this._archiveSelect && archDate != null )
                archDate = archDate.options[ archDate.selectedIndex ].value;

            var oPhoto, li;

            while ( this._picContent.hasChildNodes() )
                this._picContent.removeChild( this._picContent.lastChild );

            if (this._picContent.parentNode.scrollLeft){
                this._picContent.parentNode.scrollLeft = 0;
                this._picContent.parentNode.scrollTop = 0;
            }

            if (typeof this._archiveSelect != "undefined" && this._archiveSelect != null)
                this.markSelector( archDate );

            this.updateArchiveHistory( archDate );

            for ( var i = 0; i < this._oDates['x' + archDate].length; i++ ) {
                this.insertPicture(this._oDates['x' + archDate][i], archDate);
            }

            if (typeof this._archCurrentDate != 'undefined' &&
                this._archCurrentDate != null){
                oTime = new Date();
                oTime.setTime( archDate * 86400000 );
                sDate = formatDate( oTime, this._archDateFormat );
                while (this._archCurrentDate.hasChildNodes())
                    this._archCurrentDate.removeChild(this._archCurrentDate.lastChild);
                this._archCurrentDate.appendChild(document.createTextNode( sDate ));
            }

            if (this._oneRowOnly){
                this._picContent.style.width =
                    this._picContent.getElementsByTagName('li').length * this._cellWidth + 1 + 'px';
            }
        },

        updateArchiveHistory : function (albumIndex){
            if ( this.chathostID != jsCookie.get( 'chID' ) ) {
                jsCookie.set( 'chID', this.chathostID );
                jsCookie.set( 'chVA', null );
            }

            var aViewedAlbum = jsCookie.get( 'chVA' );

            if ( null == aViewedAlbum ) {
                aViewedAlbum = [];
            } else {
                aViewedAlbum = aViewedAlbum.split(',');

                for ( var i = 0; i < aViewedAlbum.length; i++ ) {
                    document.getElementById( 'AL_' + aViewedAlbum[ i ] ).className = 'visited';
                }
            }

            if ( null != albumIndex && document.getElementById( 'AL_' + albumIndex ) ) {
                jsUrlHash.set( 'AL', albumIndex );

                document.getElementById( 'AL_' + albumIndex ).className = 'selected';

                aViewedAlbum[ aViewedAlbum.length ] = albumIndex;

                jsCookie.set( 'chVA', aViewedAlbum.unique() );
            }
            return false;
        }
    };

