var __step = 2;
var _slider = '#offer-slide ol';
var _lisSlots = '#offer-slide ol li';
var _velocitySlider = 'slow';
var _posAtual = 1;
var _totSlots = 0;
var _addedLast = false;
var timerRound = {
		delay: 7000,
		timer: {},
		slots: {},
		setToShow : function() {return setTimeout(function(){$('#next').click();}, timerRound.delay); },
		round : function() { clearTimeout(timerRound.timer); timerRound.timer = timerRound.setToShow();},
		start : function() { timerRound.mountSlots(); timerRound.timer = timerRound.setToShow(); },
		init : function() { setTimeout(function() { timerRound.start(); }, 1000); },
		mountSlots : function() { if (_totSlots == 0) { _totSlots = $(_lisSlots).length; } timerRound.slots = new Array(); var count = 0; for (var i = 1; i <= _totSlots; i = i + __step) { timerRound.slots[count++] = i; }}
} 
timerRound.init();

$(function() {
	$('#prev').click(function() { var itens = $(_lisSlots);	if (!hasPrevious(itens)) { if (_totSlots == 0) {_totSlots = itens.length;} var firstFake = null; if (!_addedLast) { for (var i = 0; i < __step; i++) { var item = itens[i]; var clone = item.cloneNode(true); clone.id = 'box' + (itens.length+1); item.parentNode.appendChild(clone); if (!_addedLast) { firstFake = clone; } _addedLast = true; } } else { firstFake = itens[_totSlots]; } _posAtual = _totSlots+1; $(_slider).animate({left: firstFake.offsetLeft*-1}, 0); } showSlider(_posAtual-__step); });
	$('#next').click(function() { var itens = $(_lisSlots); if (!hasNext(itens)) { if (_totSlots == 0) { _totSlots = itens.length; } if (!_addedLast) { for (var i = 0; i < __step; i++) { var item = itens[i]; var clone = item.cloneNode(true); clone.id = 'box' + (itens.length+1); item.parentNode.appendChild(clone); _addedLast = true; }} else { var first = itens[0]; _posAtual = 1; $(_slider).animate({left: first.offsetLeft*-1}, 0); } } showSlider(_posAtual+__step); });
});
function hasPrevious(itens) { if (itens) { return _posAtual - __step > 0; }	return false;}
function hasNext(itens) { if (itens) { return itens.length - __step >= _posAtual; } return false;}
function showSlider(pos) { if (pos) { var slider = $(_slider); var itens = $(_lisSlots); var item = itens[pos-1]; try { slider.animate({left: item.offsetLeft*-1}, _velocitySlider); _posAtual = pos; } catch(err) { alert("error " + pos); } if (_totSlots == 0) _totSlots = itens.length; ativaBullet(_posAtual % _totSlots); timerRound.round(); }} 
function ativaBullet(group) { for (var i = 0; i < timerRound.slots.length; i++) { var bullet = $('#bulletGroup' + timerRound.slots[i]); if (group == timerRound.slots[i]) { bullet.addClass('active'); } else { bullet.removeClass('active'); } }} 
function showGroup(group) { var itens = $(_lisSlots); if (_totSlots == 0) { _totSlots = itens.length; } var pos = parseInt(group); return showSlider(pos); }
