﻿$(document).ready(function(){
	var images = $(".slideshow img");
	images.parent().addClass("loading");
	images.hide();
	images.imagesLoaded(function() {
		slideShow($(this),5000);
	},true);
});

function slideShow(obj,speed) {
	if (obj.length <= 1) return;
	var array = [];
	var fn = {
		loop: function() {
			fn.blend();
			setTimeout(fn.loop, speed );
		},
		blend: function() {
			var current = obj.filter(".current")
				.fadeOut("slow")
				.removeClass("current");
			current = (current.next().length) ?
			current.next() : obj.first();
			current.fadeIn("slow").addClass("current");
		},
		getLargest: function(array) {
			return Math.max.apply( Math, array );
		}
	}
	obj.hide();
	obj.each(function() {
		array.push($(this).height());
	});
	obj.parent().animate({height:fn.getLargest(array)},"fast");
	obj.parent().removeClass("loading");
	obj.first().fadeIn("slow",function() {
		setTimeout(fn.loop, speed );
	}).addClass("current");
}
