$(function() {
	var $list, size, id, showOne, $displayImg ;
	
	$displayImg = $('#display-images img.first').addClass('grey');
	
	$list = $('.display-content .list');
	size  = $list.size();
		
	if (size > 0 && !$.browser.msie) {	
		id = $list.attr('id');
		
		showOne = function($link) {
			var $next = $link.next();
			if ($next.size() > 0) {
				$link.animate({opacity:0.3},100, 'linear', function(){ showOne($next); });
				$link.animate({opacity:1},300, 'linear');
			} else {
				$link.animate({opacity:1},400, 'linear');
			}
			
			$link.not('a.current').hover( function() {
				$(this).animate({backgroundPosition:"(10px 5px)"}, 400, 'easeOutQuad');
			}, function() {
				$(this).animate({backgroundPosition:"(2px 5px)"}, 400, 'easeOutQuad');
			});
		};
		
		var lastPage = $.cookie('currentPage');
		if (lastPage != id) 
			$('a',$list).css('opacity',0);
		
		$.cookie('currentPage', id, { path: '/', expires: 1 });
		
		showOne($('a:first',$list));
	}
	
	
	$displayImg.clone()
		.appendTo('#display-images')
		.addClass('over')
		.css({opacity:1})
		.animate({opacity:1},1000)
		.animate({opacity:0},4000,'easeInOutQuad', function() { $(this).remove(); });
	$displayImg
		.removeClass('grey')
		.appendTo('#display-images');
	
	
	if ( $('#display-images img').size() > 2) {
		
		rotator = new geckRotator();
		rotator.interval = 12000; 
		rotator.animation = function () {
			var $imgLast, $imgFirst;
			
			$imgLast = $('#display-images img:last');
			$imgLast.clone()
				.appendTo('#display-images')
				.addClass('over grey clone1')
				.css({opacity:0})
				.animate({opacity:1},3000,'easeInOutQuad', function() {
					
					$imgFirst = $('#display-images img:first')
						.css({opacity:1})
						.removeClass('another');
					$imgFirst.clone()
						.prependTo('#display-images')
						.addClass('over2 grey clone2')
						.css({opacity:0})
						.animate({opacity:1},2000,'linear', function() {
							$imgLast.css({opacity:0});
							$('#display-images .clone1').remove();
						})
						.animate({opacity:0},3000,'easeInOutQuad', function() { 
							$('#display-images .clone2').remove(); 
							$imgFirst.appendTo('#display-images');
						});
				});
		};
		rotator.start();
	}
});



