$(function() {
	
	if (jQuery.fn.supersleight) $('#content, #navPrimary').supersleight();
	
	var newgen = $('#newgen');
	if (newgen.length) {
		var pos = 0;
		var timer;
		var points = $('#newgen-points');
	
		function slideToNext(timed) {
			if (timed) {
				timer = setTimeout(function(){
					pos == 3 ? pos = 0 : pos++;
					points.animate({
						marginLeft: '-' + (pos * 288) + 'px'
					}, 300);
					slideToNext(true);
				}, 8000);
			} else {
				pos == 3 ? pos = 0 : pos++;
				points.animate({
					marginLeft: '-' + (pos * 288) + 'px'
				}, 500);
			}
		}
	
		newgen.attr('title','Click to scroll through slides manually').click(function(event){
			if (!$(event.target).is('img')) {
				newgen.removeAttr('title').css('cursor','move');
				clearTimeout(timer);
				slideToNext(false);
			}
		});

		slideToNext(true);
	}
	
});
