﻿
var photos = new Array();
var arrayLength = 0;

function photoArray(items) {
	this.items = items;
	arrayLength = items.length;
	for (p = 0; p < items.length; p++) {
		photos[p] = new makePhotos(items[p][0], items[p][1]).write();
	}
	rotatePhotos();
}

function makePhotos(i, l) {
	var photo = new Image();
	photo.src = i;
	this.img = photo;
	this.link = l;
	this.write = writePhotos;
}

function writePhotos() {
	var str = '';
	str += '<a href="' + this.link + '">';
	str += '<img border="0" src="' + this.img.src + '" /></a>';
	return str;
}

var nIndex = 0;
var timerID = null;

function rotatePhotos() {
	var len = photos.length;
	if (nIndex >= len)
		nIndex = 0;
	document.getElementById('photos').innerHTML = photos[nIndex];
	nIndex++;
	timerID = setTimeout('rotatePhotos()', 6000);
}


function pausePhotos() {
	if (timerID != null) {
		clearTimeout(timerID);
		timerID = null;
	}
}

function playPhotos() {
	if (timerID == null) {
		timerID = setTimeout('rotatePhotos()', 1000);
	}
}
