(function ($) {
	
	var SS = {
		flag: false,
		now: 0,
		
		init: function () {
			this.leng = $('#thumbnails ul li').size();
			$('#thumbnails, #thumbnails ul').width(this.leng * 67 + 7);
			
			$('#picture li').eq(0).fadeIn(1250, function () {
				$('#thumbnails').fadeIn(750, function () {
					SS.thumbSetting();
					SS.rotation();
					SS.flag = true;
				});
			}).addClass('c');
		},
		
		thumbSetting: function () {
			$('#thumbnails li').each(function (n) {
				$(this).animate({
					opacity : 1,
					left : n * 60 + (n + 1) * 7 + 'px'
				},500, 'swing', function () {
					$(this).find('a').css('position', 'relative');
					$(this).find('a img').css('position', 'absolute');
					$('<span />').css('position', 'absolute').appendTo($(this).find('a')).fadeIn('100');
				});
				if (n == 0) $(this).addClass('c');
				
				$(this).find('a').click(function () {
					if (!SS.flag || $(this).parent().hasClass('c')) return false;
					SS.flag = false;
					SS.pictChange(n);
					SS.thumbChange(n);
					return false;
				});
			});
		},
		
		thumbChange: function (n) {
			$('#arrow').animate({
				left : 7 + 67 * n + 'px'
			}, 500, 'swing');
			
			$('#thumbnails ul li.c a span').fadeOut(250, function () {
				$(this).parent().parent().removeClass('c');
				$(this).fadeIn(250);
			});
			
			$('#thumbnails ul li').eq(n).find('span').fadeOut(250, function () {
				$(this).parent().parent().addClass('c');
				$(this).fadeIn(250);
			});
		},
		
		pictChange: function (n) {
			clearTimeout(SS.timer);
			$('#picture li.c').fadeOut(500, function () {
				$(this).removeClass('c');
			});
			$('#picture li').eq(n).fadeIn(500, function () {
				$(this).addClass('c');
				SS.now = n;
				SS.flag = true;
				SS.rotation();
			});
		},
		
		rotation: function () {
			var func = function () {
				SS.flag = false;
				var next = ((SS.now + 1) == SS.leng) ? 0 : SS.now + 1;
				SS.pictChange(next);
				SS.thumbChange(next);
			};
			this.timer = setTimeout(func, 5000);
		}
	};
	
	var SSIE6 = {
		flag: false,
		now: 0,
		
		init: function () {
			this.leng = $('#thumbnails ul li').size();
			$('#thumbnails, #thumbnails ul').width(this.leng * 67 + 7);
			
			$('#picture li').eq(0).show().addClass('c');;
			SSIE6.thumbSetting();
			SSIE6.rotation();
			SSIE6.flag = true;
		},
		
		thumbSetting: function () {
			$('#thumbnails li').each(function (n) {
				$(this).css({left : n * 60 + (n + 1) * 7 + 'px'});
				$(this).find('a').css({position : 'relative'});
				$(this).find('a img').css({position : 'absolute'});
				$('<span />').css('position', 'absolute').appendTo($(this).find('a'));
				if (n == 0) $(this).addClass('c');
				
				$(this).find('a').click(function () {
					if (!SSIE6.flag || $(this).parent().hasClass('c')) return false;
					SSIE6.flag = false;
					SSIE6.pictChange(n);
					SSIE6.thumbChange(n);
					return false;
				});
			});
		},
		
		thumbChange: function (n) {
			$('#arrow').css({left : 7 + 67 * n + 'px'});
			$('#thumbnails ul li.c').removeClass('c');
			$('#thumbnails ul li').eq(n).find('span').parent().parent().addClass('c');
		},
		
		pictChange: function (n) {
			clearTimeout(SSIE6.timer);
			$('#picture li.c').hide().removeClass('c');
			$('#picture li').eq(n).show().addClass('c');
			SSIE6.now = n;
			SSIE6.flag = true;
			SSIE6.rotation();
		},
		
		rotation: function () {
			var func = function () {
				SSIE6.flag = false;
				var next = ((SSIE6.now + 1) == SSIE6.leng) ? 0 : SSIE6.now + 1;
				SSIE6.pictChange(next);
				SSIE6.thumbChange(next);
			};
			this.timer = setTimeout(func, 5000);
		}
	};
	
	$(function () {
		if (typeof document.documentElement.style.maxHeight != "undefined") {
			SS.init();
		}
		else {
			SSIE6.init();
		}
	});
	
})(jQuery);
