    function picturesArchive ( val ){
        this.chathostID         = val['chathostID'];
        this.logonLink          = val['logonLink'];
        this.picPrefix          = val['pathPrefNormal'];
        this.picPrefixOverlay   = val['pathPrefOverlay'];
        this.picPrefixBig       = val['pathPrefBig'];
        this.hasPicAccess       = val['hasPicAccess'];
        this.oneRowOnly         = val['oneRowOnly'];
        this.photoCellUseDiv    = val['photoCellUseDiv'];
        this.picEnlargeFunc     = val['picEnlargeFunc'];
        this.picContent         = document.getElementById(val['contentID']);
        this.archiveSelect      = document.getElementById(val['archiveSelectID']);
        this.archiveList        = document.getElementById(val['archiveListID']);
        this.contentPage        = document.getElementById(val['contentPageID']);
        this.archCurrentDate    = document.getElementById(val['archCurrentDateID']);
        this.archivePrev        = document.getElementById(val['archivePrevID']);
        this.archiveNext        = document.getElementById(val['archiveNextID']);
        this.imgSpacer          = typeof val['imgSpacer'] == 'undefined' ? '/com/img/spacer.gif' : val['imgSpacer'];
        this.imgOverlay         = typeof val['imgOverlay'] == 'undefined' ? '/com/img/overlay.gif' : val['imgOverlay'];
        this.picDateFormat      = typeof val['picDateFormat'] == 'undefined' ? 'E d NNN yyyy HH:mm' : val['picDateFormat'];
        this.archDateFormat     = typeof val['archdateFormat'] == 'undefined' ? 'dd NNN yyyy' : val['archDateFormat'];
        this.origData           = val['data'];
        this.oDates              = {};
        this.dataRandomKeys     = typeof val['randomOrder'] != 'undefined' && val['randomOrder'] != null ? null : [];
        this.cellWidth          = val['cellWidth'] || 126;
        
        var _aField, _xTime, _oPhoto, i;

        for ( var i = 0; i < this.origData.length; i++ ){
            if ( this.origData[i] == '' ) continue;

            _xTime = 'x' + Math.floor( this.origData[i][1] / 86400 );

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

            this.oDates[_xTime].push ( i );

            if (this.dataRandomKeys != null)
                this.dataRandomKeys.push ( i );
        }
        if (this.dataRandomKeys == null)
            this.dataRandomKeys = val['randomOrder'];
        else
            this.dataRandomKeys.shuffle();
        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 );
            }
        }
    }

    picturesArchive.prototype.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;
            }
        }
    }
    picturesArchive.prototype.markSelector = function( val ){
        var selID, options = this.archiveSelect.options;
        var optionsLen = options.length;

        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';
        }
        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';
        }
    }


    // returns object
    picturesArchive.prototype.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;
    }

    // returns object
    picturesArchive.prototype.getPhotoCell = function(picArc, bAuthorized, oPhoto, sLocation ){
        var that = this;
        
        var isHDPhoto = ( oPhoto.hdIdx != null && Gallery );

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

        this.bigPic = bAuthorized ? picArc.picPrefixBig + oPhoto.path : null;
        var liPath  = bAuthorized ? picArc.picPrefix : picArc.picPrefixOverlay;

        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.picPath = oPhoto.path;
        img.picIdx = oPhoto.idx;
        
        if ( !isHDPhoto ) {
            img.picEnlargeFunc = picArc.picEnlargeFunc;
        }
        else {
            img.picEnlargeFunc = function( chathostID, picIdx ) {
                return function(){
                    Gallery.show( chathostID, picIdx );
                }
            }( picArc.chathostID, oPhoto.hdIdx );
        }

        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();
                    } else {
                        var width = (typeof popupWidth == 'undefined' ? 340 : popupWidth);
                        var height = (typeof popupHeight == 'undefined' ? 275 : popupHeight);
                        var r = popupWin ('ArchPhoto', '/showpic.html?PicFilename=' + that.bigPic, '',
                                          width, height, (screen.width - 400), 20, false, false, true);
                    }
                    return false;
                }
            }( img );
        }

        if ( isHDPhoto ) {
            var icon = document.createElement('IMG');
            icon.src = '/img/hdicon.gif';
            icon.width = 21;
            icon.height = 9;
            icon.alt = '';
            icon.title = 'High-definition photo';
            icon.className = 'icon';

            a.appendChild( icon );
            
            icon = null;
        }

        a.appendChild( img );

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

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

    picturesArchive.prototype.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));
        }
    }

    picturesArchive.prototype.insertPicture = function ( picID, archDate ){
        var oPhoto = this.origData[picID];
        oPhoto = {
            idx: picID,
            id: oPhoto[0],
            time: oPhoto[1],
            view: oPhoto[2],
            path: oPhoto[3],
            hdIdx: oPhoto[6]
        }

        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 ) : '')));
        }

//        if (picContent)
//            picContent.appendChild( li );
//        else
        this.picContent.appendChild( li );
    }

    picturesArchive.prototype.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';
        }
    }

    picturesArchive.prototype.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;
    }


