
function Rotation (id) {

    this._id = id;

    this._element = document.getElementById(id);

    this._list = [];
    for (el in this._element.childNodes) {
        if (this._element.childNodes[el].tagName == 'A') {
            this._list.push(this._element.childNodes[el]);
        }
    }

    this._image = [];

    this._time = 7000;

    this._index = 0;

    this._len = this._list.length;

    this._intervalID = null;

    this.ie = (navigator.appName == 'Microsoft Internet Explorer');

    this.getTime = function() {
        return this._time;
    }

    this.next = function() {
        if (this._len > 1) {
            var objOld = this._getElemCurr();
            this._indexInc();
            var objNew = this._getElemCurr();
            this._view(objNew);
            this._hidde(objOld);
        }
    }

    this.clickNext = function() {
        if (this._len > 1) {
            if (this._intervalID != null) {
                clearInterval(this._intervalID);
            }
            this.next();
        }
    }

    this._view = function(elem) {
       // if (typeof elem != 'string' && elem.tagName == 'A') {
            elem.style.display = 'block';
            elem.style.zIndex = 3;
      //  }
    }

    this._hidde = function(elem) {
       // if (typeof elem != 'string' && elem.tagName == 'A') {
            elem.style.zIndex = 4;
            if (this.ie) {
                rotationHidden(elem, 100, true);
            }
            else {
                rotationHidden(elem, 1, false);
            }
      //  }
    }

    this._indexInc = function() {
        this._index++;
        if (this._index  >= this._len) {
            this._index = 0;
        }
    }

    this._indexReset = function() {
        this._index = this.ie ? 1 : 0;
    }

    this._getElemCurr = function() {
        return this.elemChildren(this._index);
    }

    this.elemChildren = function(index) {
        return (typeof index == 'undefined')
             ? this._list
             : this._list[index];
    }

    this.init = function() {
        this._len = this.elemChildren().length;

        var fE = this.elemChildren(0);
        //if (fE.tagName == 'A') {
            fE.style.display = 'block';
            fE.style.zIndex = 4;
        //}
        var e = undefined;
        for(var i = 1; i < this._len; i++) {
            e = this.elemChildren(i);
        //    if (e.tagName == 'A') {
                e.style.display = 'none';
                e.style.zIndex = 3;
        //    }
        }
        if (this._len > 1) {
            this._intervalID = rotationLoop(this, this._time);
        }
    }
    this.init();
}

function rotationHidden(elem, opacity, ie) {
    if (ie) {
        if (opacity - 1 <= 0) {
            elem.style.display = 'none';
            elem.style.filter="alpha(opacity='100')";
            elem.style.zIndex = 3;
        }
        else {
            setTimeout(function() {
                opacity = opacity - 5;
                elem.style.filter="alpha(opacity='" + opacity + "')";
                rotationHidden(elem, opacity, true);
            }, 40);
        }
    }
    else {
        if (opacity <= 0) {
            elem.style.display = 'none';
            elem.style.opacity = 1;
        }
        else {
            setTimeout(function() {
                opacity = opacity - (1 / 100);
                elem.style.opacity = opacity;
                rotationHidden(elem, opacity, false);
            }, 5);
        }
    }
}

function rotationLoop(objRotation) {
        return setInterval(function() {objRotation.next()}, objRotation.getTime());
}

