function Slide()
{
	this.image = arguments[0];
	this.title = arguments[1];
	this.byline = arguments[2];
	this.text = arguments[3];
	this.link = arguments[4];

	this.activate = function(what)
	{
		if (this.image && what.image)
			what.image.style.backgroundImage = "url(" + this.image + ")";
		what.title.innerHTML = this.title;
		what.byline.innerHTML = this.byline && this.byline.length ? "by " + this.byline : "";
		what.text.innerHTML = this.text;
		what.link.href = this.link;
	}
}

function SlideShow()
{
	var me = this;
	var rotator = new Rotator();
	var slide = arguments[0];
	var paused = true;

	this.items = rotator.items;
	this.play = null;
	this.buttons = [];
	this.interval = 1000;

	this.items.add = function(value)
	{
		this[this.length] = value;
	}

	this.buttons.add = function(image, idx)
	{
		if (isNaN(idx))
			idx = this.length;
		this[idx] = image;
		image.onclick = function()
		{
			if (!(idx < me.items.length))
				return (false);
			if (idx == rotator.selectedIndex)
				return (false);
			if (-1 < rotator.selectedIndex)
				before();
			pause();
			if (rotator.move(idx))
				update();
			return (false);
		}
	}

	this.start = function()
	{
		rotator.interval = this.interval;
		rotator.onbeforechange = before;
		rotator.onchange = update;
		if (this.play)
		{
			this.play.onclick = function()
			{
				if (!paused)
					pause();
				else
					play();
				return (false);
			}
		}
		rotator.move(0);
		return (play());
	}

	function before()
	{
		if (me.buttons[rotator.selectedIndex])
			me.buttons[rotator.selectedIndex].src = toggle(me.buttons[rotator.selectedIndex].src, false);
	}

	function pause()
	{
		rotator.stop();
		if (me.play)
		{
			me.play.src = toggle(me.play.src, true);
			me.play.alt = "play";
		}
		paused = true;
		return (true);
	}

	function play()
	{
		if (-1 < rotator.selectedIndex)
			before();
		if (!rotator.start())
			return (false);
		me.play.src = toggle(me.play.src, false);
		me.play.alt = "pause";
		paused = false;
		update();
		return (true);
	}

	function toggle(value, parity)
	{
		return (value.replace(/_(on|off)\./, (parity ? "_on." : "_off.")));
	}

	function update()
	{
		rotator.interval = me.interval;
		if (me.buttons[rotator.selectedIndex])
			me.buttons[rotator.selectedIndex].src = toggle(me.buttons[rotator.selectedIndex].src, true);
		rotator.selectedItem.activate(slide);
	}
}