(function (jq) { jq.extend({ 'foucs': function (con) { var container = jq('#index_b_hero') , imgs = container.find('li.hero') , leftBtn = container.find('a.next') , rightBtn = container.find('a.prev') , config = { interval: con && con.interval || 8000, animateTime: con && con.animateTime || 700, direction: con && (con.direction === 'right'), _imgLen: imgs.length } , i = 0 , getNextIndex = function (y) { return i + y >= config._imgLen ? i + y - config._imgLen : i + y; } , getPrevIndex = function (y) { return i - y < 0 ? config._imgLen + i - y : i - y; } , silde = function (d) { imgs.eq((d ? getPrevIndex(2) : getNextIndex(2))).css('left', (d ? '-2360px' : '2360px')) imgs.animate({ 'left': (d ? '+' : '-') + '=1180px' }, config.animateTime); i = d ? getPrevIndex(1) : getNextIndex(1); } , s = setInterval(function () { silde(config.direction); }, config.interval); imgs.eq(i).css('left', 0).end().eq(i + 1).css('left', '1180px').end().eq(i - 1).css('left', '-1180px'); container.find('.hero-wrap').add(leftBtn).add(rightBtn).hover(function () { clearInterval(s); }, function () { s = setInterval(function () { silde(config.direction); }, config.interval); }); leftBtn.click(function () { if (jq(':animated').length === 0) { silde(false); } }); rightBtn.click(function () { if (jq(':animated').length === 0) { silde(true); } }); } }); }(jq));