(function() {
	var interval = 7000;
	
	$(document).ready(function() {
		
		$('.slider').each(function() {
			var s = $(this);
			
			/*s.get(0).onmousewheel = function(e) {
				if (!e || !e.wheelDelta) return;
				e.preventDefault();
				anim(e.wheelDelta > 0 ? 1 : -1);
			};*/

			var pos = 0;
		
			var sl = $('<div></div>');
			sl.css({position:'absolute', left:pad});
			var scr = s.find('.screen');
			scr.css({'float':'left'});
			var pMax = scr.length - 1;
			sl.append(scr);
			s.append(sl);
			s.append(s.find('.controls'));
			
			var pad = parseInt(s.find('.screen').css('margin-right'));
			
			s.width(s.find('.screen').width());
			s.height(s.find('.screen').height());
			s.css({position:'relative', overflow:'hidden',padding:pad});
			
			var w = s.width() + pad;
			sl.width((pMax+1) * w);
			s.find('.left').click(function(){anim(-1);});
			s.find('.right').click(function(){anim(1);});
			
			function anim(k)
			{
				pos += k;
				if (pos > pMax) pos = 0;
				if (pos < 0) pos = pMax;
				sl.clearQueue();
				sl.animate({left: pad -pos * w}, 500);
				clearTimeout(tid);
				tid = setTimeout(auto, interval * (.5+Math.random()));
			}
			
			var tid = setTimeout(auto, interval * (.5+Math.random()));
			
			function auto() 
			{
				anim(1);
			}
		});
	});
	
})();

