$(document).ready(function() {
	fadeSlide.init();
});

var sliceSlide = {
	init: function() {
		sliceSlide.buildDiv();
	},
	
	buildDiv: function() {
		var tar = $('#showPic');

		//将背景图切分20片，生成备用
		for(var i = 0; i < 20; i++)
		{
			tar.append($('<div class="slicePic" id="slicePic' + i + '">').css({
				'background-position-y': '-' + i * 32 + 'px',
				'top': i * 32 + 'px'
				}).data('index', i));
		}
		sliceSlide.doAnimate(0);
	},
	
	doAnimate: function(index) {
		if(index < 20)
		{
			$('#slicePic' + index).animate({
				'left': '-480px'
				}, 150, function() {
					sliceSlide.doAnimate($(this).data('index') + 1);
			});
		}
		else
			tumbSlide.init();
	}
};

var fadeSlide = {
	init: function() {
		fadeSlide.buildDiv();
	},
	
	buildDiv: function() {
		var pic = $('<div class="slicePic">');
		pic.css('opacity', '0');
		$('#showPic').append(pic);
		pic.animate({'opacity': '1'}, 1500, function() {
			tumbSlide.init();
		});
	}
};

var sliceSlide2 = {
	init: function() {
		sliceSlide2.buildDiv();
	},
	
	buildDiv: function() {
		var tar = $('#showPic');

		//将背景图切分20片，生成备用
		for(var i = 0; i < 320; i++)
		{
			tar.append($('<div class="slicePic" id="slicePic' + i + '">').css({
				//'background-position-y': '-' + i * 2 + 'px',
				//'top': i * 2 + 'px',
				'height': '8px'
				}).data('index', i).attr('style', 'background-position: 0px -' + i * 2 + 'px; top:' + i * 2 + 'px'));
		}
		sliceSlide2.doAnimate(0);
	},
	
	doAnimate: function(index) {
		for(var i = 0; i < 320; i++)
		{
			$('#slicePic' + i).animate({'left': '0px'}, i * 5, function() {
				if($(this).data('index') == 319)
				{
					tumbSlide.init();
				}
			});
		}
	}
};

var tumbSlide = {
	init: function() {
		tumbSlide.doAnimate();
	},
	
	doAnimate: function() {
		for(var  i = 1; i < 8; i++)
		{
			$('.tumb' + i).animate({'top': '0px'}, i * 150, function() {
				if($(this).attr('last') == '1')
					titleSlide.init();
			});
		}
	}
};

var titleSlide = {
	init: function() {
		titleSlide.doAnimate();
	},
	
	doAnimate: function() {
		$('.name').css('opacity', '0');
		$('.title').animate({'left': '0px'}, 'normal', function() {
			$('.title').animate({'left': '-20px'}, 'fast', function() {
				$('.entry').css('left', '550px');
				$('.entry').animate({'left': '617px'}, 'fast', function() {
					$('.entry').mouseover(function() {
						//$('#entryBG').stop().animate({'left': '0px'}, 'fast');
						$('#entryBG').stop().animate({'opacity': '0'}, 'fast');
					}).mouseout(function() {
						//$('#entryBG').stop().animate({'left': '-38px'}, 'fast');
						$('#entryBG').stop().animate({'opacity': '1'}, 'fast');
					}).click(function() {
						window.location.href="index.html";
					});
				});
				$('.name').animate({'opacity': '1'}, 'fast');
				titleSlide.nameBlur();
			});
		});
	},
	
	nameBlur: function() {
		$('.nameBlur').css({'opacity': '0', 'visibility': 'visible'});
		$('.nameBlur').animate({'opacity': '1'}, 2000, function() {
			$('.nameBlur').animate({'opacity': '0'}, 2000, function() {
				titleSlide.nameBlur();
			})
		})
	}
};
