﻿jQuery.fn.randomContent = function(settings) {
    return this.each(function() {
        var _variable = settings.variable;
        var _width = 0;
        var _lis = [];
        _lis.push(0);
        var ul = jQuery(this);
        ul.index_li = 0;
        var _width_max = 0;
        var _cursor = 0;
        ul.find('li.rc').each(function(i) {
            var me = jQuery(this);
            var _width_me = me.width();
            if (_width_me > _width_max) _width_max = _width_me;
            _cursor++;
            _width = _width + me.width();
            _lis.push(_width);
        });
        ul.find('li.rc').css('width', _width_max + 'px');
        jQuery('div.div-rc_'+_variable).css('width', _width_max + 'px');
        ul._lis = _lis;
        ul.css('width', _width_max * _cursor + 'px');
        //var _current = false;
        var _current = 0;
        var _helper = {
            _index0: [],
            _index1: [],
            getNext: function() {
                var _ret = false;
                if (_isRandom) _ret = _helper._getRandom();
                else _ret = _helper._getOrdered();
                return _ret;
            },
            _getRandom: function() {
                if (_helper._index1.length == 0) {
                    for (var i = 0; i < ul._lis.length; i++) {
                        _helper._index1.push(ul._lis[i]);
                    }
                    _helper._index0 = [];
                }
                var _max = _helper._index1.length - 2;
                var _random = Math.round(_max * Math.random());
                _helper._index0.push(_helper._index1[_random]);
                var _ret = _helper._index1[_random];
                _helper._index1.splice(_random, 1);
                return _random;
            }
        };
        _current = _helper._getRandom();
        ul.css('left', -_current * _width_max + 'px');
    });
};