// JavaScript Document

$(function() {
	var time = 1000;	//切り替えのタイミング
	var speed = 500;	//スライドスピード
	var slideUl = $('#slide > ul');
	var slideList = $('li', slideUl);
	
	//ulの高さ分を上にずらす
	//slideUl.css('margin-top', '-'+slideUl.height()+'px');
	slideUl.css('margin-top', '-'+slideUl.attr('offsetHeight')+'px');
	//リストのmargin
	var mBottom = parseInt(slideList.css('margin-bottom'));
	var count = slideList.length-1;
	var timer = setInterval(loop, time);
	
	//ループ処理
	function loop() {
		//最後のリストまで繰り返す
		if(0 <= count) {
			slideUl.animate({
				marginTop :  parseInt(slideUl.css('margin-top'))+slideList.eq(count).attr('offsetHeight')+mBottom+'px'
			},speed);
		} else {
			//最後まできたらループ終了
			clearInterval(timer);	
		}
		count--;
	}
	//マウスオーバーでストップ
	
	slideUl.hover(
			function(){
				if(0 <= count) clearInterval(timer);
			},
			function () {
				if(0 <= count) timer = setInterval(loop, time);
			}
	);
	
});
