function Profile(src, href, preload)
{
	var img = null;

	if (preload)
	{
		img = document.createElement("img");
		img.setAttribute("src", src);
	}

	this.src = src;
	this.href = href;
}

function ProfileViewer()
{
	var me = this;
	var rotator = new Rotator();

	this.profiles = rotator.items;
	this.image = null;
	this.link = null;
	this.play = null;
	this.pause = null;
	this.buttons = [];
	this.interval = 1000;

	this.buttons.add = function(image)
	{
		var idx = this.length;

		this[idx] = image;
		image.onclick = function()
		{
			if (!(idx < me.profiles.length))
				return (false);
			if (-1 < rotator.selectedIndex)
				before();
			if (!rotator.move(idx))
				return (false);
			update();
			return (false);
		}
	}

	this.init = function()
	{
		rotator.interval = this.interval;

		rotator.onbeforechange = before;
		rotator.onchange = update;

		this.play.onclick = function()
		{
			if (-1 < rotator.selectedIndex)
				before();
			play();
			return false;
		}

		this.pause.onclick = function()
		{
			rotator.stop();
			me.play.src = toggle(me.play.src, false);
			me.pause.src = toggle(me.pause.src, true);
			return false;
		}

		play();
	}

	function toggle(value, parity)
	{
		value = value.replace(/_on(\.\w+)$/, "$1");
		return (parity ? value.replace(/^(.*)(\.\w+)$/, "$1_on$2") : value);
	}

	function before()
	{
		if (me.buttons[rotator.selectedIndex])
			me.buttons[rotator.selectedIndex].src = toggle(me.buttons[rotator.selectedIndex].src, false);
	}

	function play()
	{
		rotator.interval = me.interval;
		if (!rotator.start())
			return (false);
		me.pause.src = toggle(me.pause.src, false);
		me.play.src = toggle(me.play.src, true);
		update();
		return (true);
	}

	function update()
	{
		if (me.buttons[rotator.selectedIndex])
			me.buttons[rotator.selectedIndex].src = toggle(me.buttons[rotator.selectedIndex].src, true);
		me.image.src = rotator.selectedItem.src;
		me.link.href = rotator.selectedItem.href;
		
		if(!me.link.href.match('friendsofquinn.com'))
			me.link.target = '_blank';
		else
			me.link.target = '_self';
	}
}



