var switchtime = 4000; // Time (in milliseconds) that each image is displayed for
var fadetime = 1000; // Time (in milliseconds) that the fade transition lasts for

var image_count = new Array();
var current_image = new Array();
var old_image = new Array();
var auto_scroll = new Array();

$(document).ready(function(){
	fadeinprogress = false;
	galleryRows = $(".advertgalleryrow").size();
	for (count=0;count<galleryRows;count=count+1)
	{
		auto_scroll[count] = true;
		image_count[count] = $(".advertgalleryrow").eq(count).find("img").hide().size();
		current_image[count] = 0;
		$(".advertgalleryrow").eq(count).find("img").eq(current_image[count]).show();
	}
	
	$("body").everyTime(switchtime,function() {
		for (count=0;count<galleryRows;count=count+1)
		{
			if (auto_scroll[count] == true) {
				old_image[count] = current_image[count];
				current_image[count] ++;
				if (current_image[count] > (image_count[count]-1)) { current_image[count] = 0; }
				
				$(".advertgalleryrow").eq(count).find("img").eq(current_image[count]).fadeIn(fadetime);
				$(".advertgalleryrow").eq(count).find("img").eq(old_image[count]).fadeOut(fadetime);
			}
		}
	});
});
