/*
Filename: photoswap.js
Desc:    Photo swapping script to change out images in psuedo random order.
Author:   Relevant Arts Enterprise, Inc. <http://www.relevantarts.com/>
          John A. Lock <jlock@relevantarts.com>
Created:  2006-Aug-23
Modified: 
*/

var BoxPos = 0;
var BoxOrder = new Array(2,1,3);
var Delay = 1500;
var MaxPhotos = 3;

var Box1Link = new Array();
Box1Link[1] = "http://www.riverwoodproperties.com/dvillepromen.html";
Box1Link[2] = "http://www.riverwoodproperties.com/ptreecitypro.html";
Box1Link[3] = "http://www.riverwoodproperties.com/windwardprom.html";

var Box2Link = new Array();
Box2Link[1] = "http://www.riverwoodproperties.com/springsprome.html";
Box2Link[2] = "http://www.riverwoodproperties.com/poncedeleonc.html";
Box2Link[3] = "http://www.riverwoodproperties.com/hickoryflat.html";

var Box3Link = new Array();
Box3Link[1] = "http://www.riverwoodproperties.com/springslandi.html";
Box3Link[2] = "http://www.riverwoodproperties.com/easternshore.html";
Box3Link[3] = "http://www.riverwoodproperties.com/cummingfesti.html";

// Initialize the img counters for each box
var Box1Img = 0;
var Box2Img = 0;
var Box3Img = 0;

// Change Box 1's photo
function Box1Chg() {
	Box1Img++;
	if (Box1Img > MaxPhotos) {
		Box1Img = 1;
	}
	document["photo1"].src = "img/photos/featured/box1/photo" + Box1Img + ".jpg";
	ReplaceLink('link1', Box1Link[Box1Img]);
	NextBox = CalcNext();
	setTimeout("Box" + NextBox + "Chg()", Delay);
}

// Change Box 2's photo
function Box2Chg() {
	Box2Img++;
	if (Box2Img > MaxPhotos) {
		Box2Img = 1;
	}
	document["photo2"].src = "img/photos/featured/box2/photo" + Box2Img + ".jpg";
	ReplaceLink('link2', Box2Link[Box2Img]);
	NextBox = CalcNext();
	setTimeout("Box" + NextBox + "Chg()", Delay);
}

// Change Box 3's photo
function Box3Chg() {
	Box3Img++;
	if (Box3Img > MaxPhotos) {
		Box3Img = 1;
	}
	document["photo3"].src = "img/photos/featured/box3/photo" + Box3Img + ".jpg";
	ReplaceLink('link3', Box3Link[Box3Img]);
	NextBox = CalcNext();
	setTimeout("Box" + NextBox + "Chg()", Delay);
}

// Calculate the next box to be changed
function CalcNext() {
	BoxPos++;
	if (BoxPos > (BoxOrder.length - 1)) {
		BoxPos = 0;
	}
	return(BoxOrder[BoxPos]);
}

function ReplaceLink(LinkName, NewURL) {
  for (LinkID in document.links) {
    if (document.links[LinkID].name == LinkName) {
      document.links[LinkID].href = NewURL;
    }
  }
}

// Start the swap on a random box
function StartSwap(BoxPos) {
	StartBox = BoxOrder[BoxPos];	
	eval("Box" + StartBox + "Chg()");
}

