; (function($) { $.fn.extend({ "daliFocus": function(options) { var obj = $(this); var speed = options.speed; var duration = options.duration; var dalitime; var moving = false; var aro = 'next'; var pnum = obj.find('.fpp').length; $('.fsmall em:eq(0)').addClass('on'); MoveFirst(); obj.find('.fsmall em').click(function() { if (!moving && !$(this).hasClass('on')) { var inidx = $(this).index(); aro = inidx > obj.find('.fsmall em.on').index() ? 'next' : 'prev'; MoveGo(inidx); } }) $(document).on('click', '#aroleft', function(){ aro = 'prev'; var idx = $('.fsmall em.on').index(); idx--; idx<0 && (idx=pnum-1); if (!moving) { MoveGo(idx) } }) $(document).on('click', '#aroright', function(){ aro = 'next'; var idx = $('.fsmall em.on').index(); idx++; idx==pnum && (idx=0); if (!moving) { MoveGo(idx) } }) function MoveGo(inidx) { moving = true; if (dalitime) { clearTimeout(dalitime); } var outidx = obj.find('.fsmall em.on').index(); var left = '100'; var moveto = '-=100'; if (aro == 'prev') { left = '-100'; moveto = '+=100'; } obj.find('.fpp').eq(outidx).animate({ left: moveto + '%' }, duration, 'easeInOutExpo'); obj.find('.fcc').eq(outidx).animate({ left: moveto + '%' }, duration, 'easeInOutExpo'); obj.find('.fpp').eq(inidx).css({ 'left': left + '%' }).animate({ left: moveto + '%' }, duration, 'easeInOutExpo', function() { MoveOver(inidx); moving = false; }); obj.find('.fcc').eq(inidx).css({ 'left': left + '%' }).animate({ left: moveto + '%' }, duration, 'easeInOutExpo'); $('.fsmall em').eq(outidx).removeClass("on"); $('.fsmall em').eq(inidx).addClass("on"); } function MoveFirst() { obj.find('.fpp:eq(0),.fcc:eq(0)').css({ 'left': 0 }); MoveOver(0); } function MoveOver(inidx) { aro = 'next'; if (pnum > 1) { inidx++; inidx == pnum && (inidx = 0) dalitime = setTimeout(function() { MoveGo(inidx) }, speed); } } } }); })(jQuery);