window.$ = function(id) { return document.getElementById(id); }

function makeSlideshow(parentId, className, random)
{
	var parentElm = $(parentId);
	var random = window.random = random;
	var images = window.images = Array();
	for (var n = 3; n < arguments.length; n++)
	{
		var newElm = parentElm.appendChild(document.createElement('div'));
		newElm.className = className;
		var newImg = newElm.appendChild(document.createElement('img'));
		newImg.src = arguments[n];
		if (document.all)
		{
			newElm.style.filter = 'alpha(opacity=0);';
		}
		newElm.style.opacity = 0;
		images[images.length] = newElm;
	}
	if (random == true)
	{
		var active = window.active = Math.floor(Math.random()*images.length);
	}
	else
	{
		var active = window.active = 0;
	}
	JSTweener.addTween(images[active].style, {
		time: 1,
		transition: 'easeInSine',
		onUpdate: function()
		{
			if (document.all)
			{
				var opacity = Math.round(this.target.opacity*100);
				images[active].style.filter='alpha(opacity='+opacity+')';
			}
		},
		onComplete: function() { if (images.length > 1) { showNextImage(); } },
		opacity: 1
	});
}
function showNextImage()
{
	var show;
	if (random == true)
	{
		do
		{
			show = Math.floor(Math.random()*images.length);
		}
		while(show == active);
	}
	else
	{
		if (active == images.length-1) show = 0;
		else show = active+1;
	}

	JSTweener.addTween(images[show].style, {
		time: 1,
		transition: 'easeInSine',
		onStart: function ()
		{
			for (var n in images)
			{
				images[n].style.zIndex='1';
			}
			images[show].style.zIndex='3';
			images[active].style.zIndex='2';
		}, 
		onUpdate: function()
		{
			if (document.all)
			{
				var opacity = Math.round(this.target.opacity*100);
				images[active].style.filter='alpha(opacity='+opacity+')';
			}
		},
		onComplete: function()
		{
			for (var n in images)
			{
				if (n != show)
				{
					if (document.all)
					{
						images[n].style.filter 	= 'alpha(opacity=0);';
					}
					images[n].style.opacity	= 0;
				}
			}
			images[show].style.filter = 'alpha(opacity=100);';
			showNextImage();
		},
		delay: 2,
		opacity: 1
	});
	active = show;
}