﻿ImagesLentManager = function() {
    this._cklist = $.cookie("PL_ILN");
    if (!this._cklist || this._cklist == '') { this._cklist = 'people'; }
    this._backLformat = '';
    this._fowardLformat = '';
    this._lents = new Array();
};
ImagesLentManager.prototype = {
    init: function(fowordL, backL) {
        try { this.try_init(fowordL, backL); } catch (e) { alert(e); }
    },
    try_init: function(fowordL, backL) {
        this._backLformat = backL;
        this._fowardLformat = fowordL;
        var _this = this;
        $.each($('.tab-list'), function(i, v) {
            var obj = $(this).attr('obj');
            if (!obj || obj == '') return;
            $(this).attr('obji', i);
            var l = new ImagesLent(_this._fowardLformat.replace('.filter', obj), _this._backLformat.replace('.filter', obj));
            _this._lents.push(l);
            $(v).click(function() {
                var li = $(this).attr('obji');
                for (var lj in _this._lents) {
                    if (li == lj) {
                        if (!_this._lents[lj].get_closed()) break;
                        _this._lents[lj].enable(this);
                    } else {
                        _this._lents[lj].disable();
                    }
                }
            });
            if (obj.indexOf(_this._cklist) == 0) { l.enable(v); }
        });
    }
};

ImagesLent = function(fowordL, backL) {
    this._el = null;
    this._foword = fowordL;
    this._back = backL;
    this._closed = true;
    this._v = null;
    this._top_array = null;
    this._down_array = null;
};

ImagesLent.prototype = {
    get_closed: function() { return this._closed; },
    init: function() {
        if (this._el == null) {
            this._el = $('#imgs-lent');
        }
    },

    insert: function() {
        this._insert_schema();
        if (this._down_array == null) {
            $.post(this._foword, function(data) {
                if (!data) return;

            });
        }
    },
    _insert_schema: function() {
        var cover = document.createElement('div');
        var top = document.createElement('div');
        var content = document.createElement('div');
        var down = document.createElement('div');
        cover.appendChild(top);
        cover.appendChild(content);
        cover.appendChild(down);
        var _this = this;
        //        $(top).attr('class','top off').click(function() {

        //        });
        $(top).attr('class', 'top off');
        $(down).attr('class', 'down off');
        $(content).addClass('items');

        $(this._el).html(cover);


    },

    enable: function(v) {
        this.init();
        this._closed = false;
        this._v = v;
        $(v).addClass('on');
        $(v).find('.tab-info').css({ "width": "300px" });
        this.insert();
    },
    disable: function() {
        this._closed = true;
        if (this._v == null) return;
        $(this._v).find('.tab-info').css({ "width": "auto" });
        $(this._v).removeClass('on');
    }
};


CountArray = function(total, array) {
    if (array) this._array = array; else this._array = new Array();
    if (total) this._total = total; else this._total = -1;
    this._pos = 0;
};
CountArray.prototype = {
    get_array: function() { return this._array; },
    get_item: function(i) { return this.get_array()[i]; },
    get_total: function() { return this._total; },
    get_pos: function() { return this._pos; },
    set_pos: function(pos) { this._pos = pos; }
};