var settings = {
    timeout: 5000
};

function max(array) {
    var max = 0;
    for (var i = 0, j = array.length; i < j; i++) {
        if (array[i] > max) {
            max = array[i];
        }
    }
    return max;
}

//$(document).ready(function()
$(window).load(function ()
	       {
		   $("div.slide").each(function()
				       {
					   var children = $(this).children();
					   var count = children.length;
					   if ($(this).parent().attr("class") != "block block-images")
					   {
					       var heights = new Array();
					       for (var k = 0; k < count; k++)
					       {
						   heights.push($(children[k]).height());
						   if (k > 0)
						   {
						       $(children[k]).hide();
						   }
					       }
					       var a = $(this).parent().attr("class");
					       $(this).height(max(heights) + 15);
					   }
					   else
					   {
					       $(this).height(220);
					   }
					   var i = 0;
					   var showcycle = function(i)
					   {
					       var current = i % count;
					       var next = (i + 1) % count;
					       $(children[current]).fadeOut(1000, function()
									    {
										$(children[next]).fadeIn(1000);
									    });
					       i++;
					       if (i > count - 1) { i = 0; }
					       setTimeout(function() {showcycle(i);},settings.timeout);
					   };
					   if (count > 1)
					   {
					       setTimeout(function()
							  {
							      showcycle(i);
							  }, settings.timeout);
					   }
				       });
	       });

