$(document).ready(function(){
	
	var thumb;
	var large;
	var URL;
	var SRC;
	var ALT;
	var add;
	var allImg = $("#Visual .Small li").length-1;
	var now = 0;
	var target = "#Visual .Small li:eq(" + now + ")";
	
	$("#Visual .Small li").hover(
		function (){
			clearInterval(slideshow);
			now = $("#Visual .Small li").index(this);
			target = "#Visual .Small li:eq(" + now + ")";
			slide();
		},
		function (){
			slideshow = setInterval(function(){ slide(); },5000);
		}
	);
	
	var start = $("#Visual .Small .active").size();
	
	if (start) {
		now = start-1;
		target = "#Visual .Small li:eq(" + now + ")";
		slideshow = setInterval("slide(now)",5000);
	} else {
		slide();
		slideshow = setInterval(function(){ slide(); },5000);
	}
	
	
	function slide( now ) {
		var ac = $(target).attr("class");
		
		if ( ac != "active" ) {
			$("#Visual .Large").stop();
			
			$("#Visual .Small li").removeClass("active").fadeTo(0,0.7);
			$(target).addClass("active").fadeTo(0,1);
			
			change( now );
		}
	}
	
	
	function change( i ) {
		$("#Visual .Large").fadeTo(300,0,function(){
			$(this).remove();
			
			URL = $("a", target).attr("href");
			SRC = $("img", target).attr("src").replace('.gif', '_l.gif').replace('.jpg', '_l.jpg').replace('.png', '_l.png');
			ALT = $("img", target).attr("alt");
			add = '<p class="Large" style="display:none;"><a href="' + URL + '"><img src="'+ SRC +'" width="658" height="322" alt="' + ALT +'" /></a></p>';
			
			$("#Visual").prepend(add);
			$("#Visual .Large").fadeTo(500,1);
			
			now++;
			if ( now > allImg ) {
				now = 0;
			}
			target = "#Visual .Small li:eq(" + now + ")";
		});
	}


});

