var slider;

function slideSwitch(img, thumb) {
    var $active = $('#img_div img.active');
    $active = $active.length == 0 ? $('#img_div img:last') : $active;
	
	if (img=='' || thumb==''){
		var $next = $active.next().length ? $active.next() : $('#img_div img:first');
		thumb = $next.attr('id');
		thumb=thumb.substr(3,1);
		var imgAlt = $('#li' + thumb).find('img').attr("alt");
		var imgDesc = $('#li' + thumb).find('.block').html();
	}else{
		var $next = $(img);
		var imgAlt = $(thumb).find('img').attr("alt");
		var imgDesc = $(thumb).find('.block').html();
	}
	
	if ('#' + $active.attr('id') != img){
		$("#main_image .desc").show();
		$("#main_image .block").animate({ opacity: 1.0 }, 1 );
		
		var imgDescHeight = $("#main_image").find('.block').height();
		
		$("#main_image .block").animate({ opacity: 0, marginBottom: +imgDescHeight }, 500 , function() {
			$("#main_image .block").html(imgDesc).animate({ opacity: 1.0,	marginBottom: "0" }, 500 );
		});
			
		$active.addClass('last-active');
		$next.css({opacity: 0.0}).addClass('active').animate({opacity: 1.0}, 500, function() {
			$active.removeClass('active last-active');
		});
		
		if (img && thumb){
			clearTimeout(slider);
			setTimeout("", 15000);
			slider = setInterval("slideSwitch('','')", 15000);
		}			
	}
}

$(document).ready(function(){
	clearTimeout(slider);
    slider = setInterval("slideSwitch('', '')", 15000);
});

