$(document).ready(function() {

	$("img#advstpic_0").show();
	var roll;
	function start(){
		
	roll = setInterval(function(){
			
			var rollobj=$(".advstpic");
			var rolltotal=parseInt(rollobj.size())-1;
			var nextId,nowId;
			$("img.advstpic").each(function(){
				
				if(this.style.display=='block' || this.style.display=='inline'){
					nowId=parseInt(this.id.substr(9));
					if(nowId>=rolltotal){
						nextId=0;
					}else{
						nextId=nowId+1;
					}
				}
			});
			$("img#advstpic_"+nextId).fadeIn('slow').show('slow');
			$("img#advstpic_"+nowId).fadeOut('slow').hide();
	},5000)};
	start();
	$("img.spic").mouseover(function(){
				id = this.id.substr(5);
				clearInterval(roll);
				$("img.advstpic").each(function(){
					$("#"+this.id).fadeOut('slow').hide();
				});
				$("#advstpic_"+id).fadeIn('slow').show('slow');
				
	});
			$("img.spic").mouseout(function(){
				roll = setInterval(function(){
			
			var rollobj=$(".advstpic");
			var rolltotal=parseInt(rollobj.size())-1;
			var nextId,nowId;
			$("img.advstpic").each(function(){
				
				if(this.style.display=='block' || this.style.display=='inline'){
					nowId=parseInt(this.id.substr(9));
					if(nowId>=rolltotal){
						nextId=0;
					}else{
						nextId=nowId+1;
					}
				}
			});
			$("img#advstpic_"+nextId).fadeIn('slow').show('slow');
			$("img#advstpic_"+nowId).fadeOut('slow').hide();
			},5000);
			});
});

