$idx = 0;
$fadeSpeed = 600;

function swapImages ()
{
	$active = $("div#img img.active");
	$inactive = $("div#img img.inactive");

	if ($idx == $imageList.length-1) {
		$idx = 0;
	} else {
		$idx++;
	}
	$inactive.attr("src", $imageList[$idx]).fadeIn($fadeSpeed);

	$inactive.removeClass("inactive").addClass("active");
	$active.removeClass("active").addClass("inactive").fadeOut($fadeSpeed);
}

$(document).ready(function() {
	$.preLoadImages($imageList);
//	$("div#img").append('<img src="'+$imageList[$idx]+'" width="700" alt="" />');
//	$("div#img img").addClass("active").css("display", "block");
	$('<img src="'+$imageList[$idx]+'" width="700" alt="" />').insertAfter("div#img img").addClass("inactive").css("display", "none");
	setInterval('swapImages()', 7000);
});

// image prelaoder
(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function(images) {
    var args_len = images.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = images[i];
      cache.push(cacheImage);
    }
  };
})(jQuery);
