$(document).ready(function() {
$("#img .desc").animate({ opacity: 0, marginBottom: -80 }, 1 );
$("#img .desc").delay(800).animate({ opacity: 0.80, marginBottom: "0" }, 2000 );
$("#img ul li:first").addClass('first');
$("#img ul li:last").addClass('last');
var pause = false;
var clickNext = function(){
	if(!pause) {
		var $next_li = $("#img ul li.active").next("li");
		if($("#img ul li.active").hasClass("last")){
			$("#img ul li").removeClass('active');
			$("#img ul li.first").addClass("active");
			var rfoAlt = $("#img ul .active").find('a').attr("title");
			var rfoRel = $("#img ul .active").find('a').attr("rel");
			var rfoLink = $("#img ul .active").find('a').attr("href");
			var rfoDesc = $("#img ul .active").find('a').html();
			$("#rfoAnim").stop(true, true).fadeIn(function() {
				$("#rfoAnim").css("z-index", "3");
				$("#rfoUrl").attr({href: rfoLink, title: rfoAlt});			
				$("#rfoMain").attr({src: rfoRel, alt: rfoAlt});	
				$("#img .desc").stop(true, true).animate({ opacity: 0, marginBottom: "-80px" }, 1000 ,
				function() {
					$("#img .desc").html(rfoDesc).delay(800).animate({opacity: 0.80, marginBottom: "0"}, 1500);
				});
			});
			$("#rfoAnim").stop(true, true).fadeOut(500, function(){
				$("#rfoAnim").attr({src: rfoRel, alt: rfoAlt}).css("z-index", "1");
			});
			return false;
		} else {
			$("#img ul li").removeClass('active');
			$next_li.addClass("active");
			var rfoAlt = $("#img ul .active").find('a').attr("title");
			var rfoRel = $("#img ul .active").find('a').attr("rel");
			var rfoLink = $("#img ul .active").find('a').attr("href");
			var rfoDesc = $("#img ul .active").find('a').html();
			$("#rfoAnim").stop(true, true).fadeIn(function() {
				$("#rfoAnim").css("z-index", "3");
				$("#rfoUrl").attr({href: rfoLink, title: rfoAlt});			
				$("#rfoMain").attr({src: rfoRel, alt: rfoAlt});	
				$("#img .desc").stop(true, true).animate({ opacity: 0, marginBottom: "-80px" }, 1000 ,
				function() {
					$("#img .desc").html(rfoDesc).delay(800).animate({opacity: 0.80, marginBottom: "0"}, 1500);
				});
			});
			$("#rfoAnim").stop(true, true).fadeOut(500, function(){
				$("#rfoAnim").attr({src: rfoRel, alt: rfoAlt}).css("z-index", "1");
			});
			return false;
		}
	}
};
setInterval(clickNext, 6000);

$("#img ul li").hover(function(){
	if ($(this).is(".active")) {
		return false;
	}
	else {
		pause = true;
		$("#img ul li").removeClass('active');
		$(this).addClass('active');
		var rfoAlt = $("#img ul .active").find('a').attr("title");
		var rfoRel = $("#img ul .active").find('a').attr("rel");
		var rfoLink = $("#img ul .active").find('a').attr("href");
		var rfoDesc = $("#img ul .active").find('a').html();
		$("#rfoAnim").stop(true, true).fadeIn(function() {
			$("#rfoAnim").css("z-index", "3");
			$("#rfoUrl").attr({href: rfoLink, title: rfoAlt});			
			$("#rfoMain").attr({src: rfoRel, alt: rfoAlt});
				$("#img .desc").stop(true, true).animate({ opacity: 0, marginBottom: "-80px" }, 1000 ,
				function() {
					$("#img .desc").html(rfoDesc).delay(800).animate({opacity: 0.80, marginBottom: "0"}, 1500);
				});
		});
		$("#rfoAnim").stop(true, true).fadeOut(500, function(){
			$("#rfoAnim").attr({src: rfoRel, alt: rfoAlt}).css("z-index", "1");
		});
	}
}, 
	function() {
		pause = false;
	}
);

});
