$(document).ready(function(){
	if($('.feature').length || $('.slideshow-a').length || $('.slideshow-b').length){
		$('.pager').show();
		$('.pager p a:first').addClass('selected');
		if($('.feature').length){
			var w = $('.feature').width();
		} else if($('.slideshow-a').length){
			var w = $('.slideshow-a').width();
		} else if($('.slideshow-b').length){
			var w = $('.slideshow-b').width();
		}
		var count = $('.images img').size();
		var l = w * count;
		$('.images').css({'width': l});
		rotate = function(){
			var id = $selected.attr('rel') - 1;
			var position = id * w;
			$('.pager p a').removeClass('selected');
			$selected.addClass('selected');
			$('.images').animate({left: -position}, 500);
		};
		play = function(){
			timer = setInterval(function(){
				$selected = $('.pager p a.selected').next();
				if($selected.length === 0){
					$selected = $('.pager p a:first');
				}
				rotate();
			}, 7500);
		};
		play();
		$('.images a').hover(function(){
			clearInterval(timer);
		}, function(){
			play();
		});
		$('.pager p a').click(function(){
			$selected = $(this);
			clearInterval(timer);
			rotate();
			play();
			return false;
		});
	}
});
