var npFocusRotation = (function() {
    var _DisplayTime = 4000
    var _intervalId = []
    var _CurrentId
    function _rotate(Id) {
        if (!($("#" + Id + " .dropdownRightContent").is(":visible"))) {
            _stop()
            return
        }
        var cur = $("#" + Id + " .dropdownRightContent .item:visible")
        if (cur.is(":last-child")) {
            cur.fadeOut(500, function() {
                $("#" + Id + " .dropdownRightContent .item:first-child").fadeIn(500, function() {
                    _intervalId.push(setTimeout(function() { npFocusRotation.rotate(Id) }, _DisplayTime))
                })
            })
        }
        else {
            cur.fadeOut(500, function() {
                cur.next().fadeIn(500, function() {
                    _intervalId.push(setTimeout(function() { npFocusRotation.rotate(Id) }, _DisplayTime))
                })
            })
        } 
    }
    function _stop() {
        for (var i = 0; i < _intervalId.length; i++) {
            clearTimeout(_intervalId[i])
            _intervalId.splice(i, 1)
        }
        _CurrentId = null
    }
    return {
        go: function(Id) {
            if (Id != _CurrentId) {
                _stop()
                _CurrentId = Id
                _intervalId.push(setTimeout(function() { npFocusRotation.rotate(Id) }, _DisplayTime))
            }
        },
        rotate: function(Id) {
            _rotate(Id)
        },
        stop: function() {
            _stop()
        } 
    }
})()

