/*
 * Image preview script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Alen Grakalic (http://cssglobe.com)
 * 
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */
 
var a=0;
var b=1;
var t;

$(document).ready(function(){
	t= setInterval("roll(a,b);", 3000); //时间间隔为3秒
});

function roll (off,on){
	clearInterval(t);
	var $firstNode = $('#motto>div'); //#motto 是DIV的ID,'p'是该区间的段落          
	$firstNode.eq(off).fadeOut('slow',function(){  
		$firstNode.eq(on).fadeIn('slow');
	});

	if(on==($('#motto>div').length-1)){
		a=on; //on 指DIV里最后一个P
		b=0;
	}
	else if(off==($('#motto>div').length-1)){
                //当最后一个准备关闭，a, b 重新赋值
		a=0;   
		b=1;
	}
	else{
		a++;
		b++;
	}
	t = setInterval ("roll(a, b);", 3000);
}

