var change_thumbs = newClass({
    
    aImgId   : null, // Array of img id
    nImgId   : null, // Current id
    sBaseTag : null, // Base tag
    curNum   : 0,    // Curren array index
    aImgWr   : null, // Array of img wrappers

    timer    : null, // Timer
    
    init : function(aImgId, nImgId, sBaseTag)
    {
        this.aImgId = aImgId;
        this.nImgId = nImgId;
        this.sBaseTag = sBaseTag;

        this.aImgWr = [];
    },

    onready : function()
    {
        var conf = this.config;
        this.aImgWr.push(this.$(this.sBaseTag + " img[src=" + conf.imagePref + this.nImgId + conf.imageSuf + "]"));

        if (this.aImgWr[0] != null) {
            this.aImgWr[0].getParent().addListener(this, "onmouseover", "startTimer");
            this.aImgWr[0].getParent().addListener(this, "onmouseout", "stopTimer");
        }
    },

    //Prepare array of image wrappers
    makeArrOfWrap : function ()
    {
        var conf, $w, iFirstIndex, oParent, oNotImageChld, i;

        conf = this.config;
        $w = this.$w0;

        //Find where first image id place in aImgId
        for (i = 0; i < this.aImgId.length; i++) {
            if (this.nImgId == this.aImgId[i]) {
                iFirstIndex = i;
                break;
            }
        }

        //
        for (i = iFirstIndex + 1; i < this.aImgId.length; i++) {
            this.aImgWr.push($w.makeElement("img", {src:(conf.imagePref + this.aImgId[i] + conf.imageSuf)}));
        }

        //
        for (i = 0; i < iFirstIndex; i++) {
            this.aImgWr.push($w.makeElement("img", {src:(conf.imagePref + this.aImgId[i] + conf.imageSuf)}));
        }

        //
        oParent       = this.aImgWr[0].getParent();
        oNotImageChld = this.aImgWr[0].getNextSibling(); //

        if( oNotImageChld == null) {
            for (i = 1; i < this.aImgWr.length; i++) {
                this.aImgWr[i].setDisplay("none");
                oParent.elm.appendChild(this.aImgWr[i].elm);
            }
        } else {
            for (i = 1; i < this.aImgWr.length; i++) {
                this.aImgWr[i].setDisplay("none");
                oParent.elm.insertBefore(this.aImgWr[i].elm, oNotImageChld.elm);
            }
        }

    },
    
    startTimer : function()
    {
        if (this.aImgWr.length == 1) {
            this.makeArrOfWrap();
        }
        if (!this.timer) {
            this.timer = this.setInterval(this.config.period, this, 'onTimer');
        }
    },

    stopTimer : function()
    {
        if (this.timer) {
            clearInterval(this.timer);
            this.timer = null;
        }

    },

    onTimer : function()
    {
        this.aImgWr[this.curNum].setDisplay("none");
        this.curNum++;

        if (this.curNum == this.aImgWr.length) {
            this.curNum = 0;
        }

        this.aImgWr[this.curNum].setDisplay("inline");
    },

    config : {
        "imagePref" : "/thumb_",
        "imageSuf"  : ".img",
        "period"    : 1500
    }


})
