var _ahead = { slide_width: 400, sticks: [], slide: function(i_obj, i_dir) { var l_stick, l_left, l_pos, l_speed; switch(i_dir) { case 1: case 2: if (i_obj.width() > _ahead.slide_width) { l_speed = (i_dir == 1) ? "normal" : 50; i_obj.animate({"left": "+=" + _ahead.slide_width + "px", "background-color":"#FF0000"}, l_speed, function(){ if (i_obj.position().left >= 0) { var l_newLeft = 2 * _ahead.slide_width - i_obj.width(); i_obj.css('left', l_newLeft + 'px'); } }); } break; case -1: case -2: if (i_obj.width() > _ahead.slide_width) { l_speed = (i_dir == -1) ? "normal" : 50; i_obj.animate({"left": "-=" + _ahead.slide_width + "px", "background-color":"#FF0000"}, l_speed, function(){ var l_left; // l_left = l_obj.css('left'); // l_left = l_left.replace(/[^0-9\-]/g, ''); // l_left = parseFloat(l_left); l_left = i_obj.position().left; if (l_left <= _ahead.slide_width - i_obj.width()) { var l_newLeft = - _ahead.slide_width; i_obj.css('left', l_newLeft + 'px'); } }); } break; } }, incSlide: 0, slideAll: function(){ _ahead.incSlide = (_ahead.incSlide + 1) % _ahead.sticks.length; _ahead.slide(_ahead.sticks[_ahead.incSlide], -1); }, init: function() { // if (!$.browser.msie || $.browser.version.substr(0,1)=="8") // { $('.stick').each(function(){ if ($(this).width() > _ahead.slide_width) { //$(this).css('left', '-' + _ahead.slide_width + 'px'); _ahead.sticks.push($(this)); } }); if (_ahead.sticks.length > 0) { setInterval(_ahead.slideAll,3000); } // } // else { // $('.stick').each(function(){ // $(this).css('left', '0px'); // }); // } } }; _ahead.init();