jQuery(function($) {
	
	var swap = function(replacement) {
		$('.feature:visible').fadeOut(150);
		replacement.fadeIn(200);
		$('#features_loading:visible').fadeOut(200);
	},
	lis = $('#features').find('.nav').find('li'),
	click = function(auto) {
		var $this = $(this);
	
		$this.parent().siblings('.here').removeClass('here').end().addClass('here');
		var client = $this.attr('href').match(/client=([^&]*)$/)[1];
	
		if ($('#'+client).length > 0) {
			swap($('#'+client));
		} else {
			var $img = $('.feature:visible').find('img');
		
			$('#features_loading').css({
				height: $img.height(),
				width: $img.width()
			}).fadeTo(0, 0).show().fadeTo(150, 0.7);
		
			$.ajax({
				url: $this.attr('href'),
				success: function(html) {
					var e = $(html).find('.feature').hide();
					$('#features').append(e);
					if (!auto || interval) swap(e);
				}
			});
		}
	},
	interval = MOB ? null : setInterval(function() {
		var f = lis.filter('.here').next();
		if (!f.length) f = lis.filter(':first');
	
		click.call(f.find('a'), true);
	}, 18000);

	$('<div />').attr('id', 'features_loading').appendTo('#features');
	lis.find('a').click(function() {
		clearInterval(interval); interval = null;
		click.call(this, false);
		return false;
	});
	
});