nextImg = 2;
imgLoaded = {};
currentTime = new Date();

function doSlideshow(str_divId, imgCount, imgName)
{
	changeImage(str_divId, nextImg, imgName);	
	nextImg = nextImg == imgCount ? 1 : nextImg+1;
}

function changeImage(str_divId, imgNo, imgName)
{
	var nextName = imgName.replace(/%no%/, imgNo);
	nextName += "?"+currentTime.getTime();
	
	if(imgLoaded[""+imgNo+""] !== true)
	{
		var img = new Image();
		$(img).attr('src', nextName).load(function() {
			addImage(str_divId, nextName)
			imgLoaded[""+imgNo+""] = true;
		});
	}
	else
	{
		addImage(str_divId, nextName)
	}
	
	$("#imgNav a").removeClass("active");
	$("#imgNav a[rel='"+imgNo+"']").addClass("active");
}

function addImage(str_divId, imgName)
{
	$('#'+str_divId).prepend("<div class='slide'><img src='"+imgName+"'></div>");
	$('#'+str_divId+' .slide:last').fadeOut(1000, function() {
		$('#'+str_divId+' .slide').not('#'+str_divId+' .slide:first').remove();
	});
}
