(function($) {

var quotations = $("#quotations");
var currentQuote = quotations.find(".currentquote");
var currentQuoteIndex = 0;

//create images from the UL list

quotations.find("ul a").each(function() {
	
	var link = $(this);
	
	$("<img />").attr({
		src : link.attr("href"),
		alt : link.html()
	}).hide().appendTo(currentQuote);
});

//put all images in one node set and hide the list

var quotes = currentQuote.find("img");
quotations.find("ul").hide();

//save a reference to the first image

var activeQuote = quotes.eq(currentQuoteIndex);

//show the next or previous image

function showQuote(newIndex) {
	currentQuoteIndex = newIndex >= quotes.length ? 0 : newIndex;
	currentQuoteIndex = currentQuoteIndex < 0 ? quotes.length - 1 : currentQuoteIndex;
	
	activeQuote.fadeOut(2000);
	activeQuote = quotes.eq(currentQuoteIndex).fadeIn(4000);
}

//start timer to cycle images

var interval = setInterval(function() {
	showQuote(currentQuoteIndex + 1);
}, 8000);


})(jQuery);




