rotatingImages = new imageRotator(imgArray);
window.onload = function(){window.onload;if(document.getElementById('rotateImg1'))rotatingImages.start();}

function imageRotator(imgArray){
	this.delay = 1000;
	this.setDelay = 6000;
	this.imageArray = imgArray;
	this.rotateNext = function(){
		//set up timer to call function again
		pointer = this;
		this.nextDelay = (this.nextRotatingImg == 2) ? this.setDelay : this.delay;
		this.timer = setTimeout(function(){pointer.rotateNext()}, this.nextDelay);
		
		this.imgObj[this.nextRotatingImg].src = this.imageArray[this.imgIndex];
		
		this.nextRotatingImg++;
		if(this.nextRotatingImg == this.imgObj.length) this.nextRotatingImg = 0;
		
		this.imgIndex++;
		if(this.imgIndex == this.imageArray.length) this.imgIndex = 0;
		

	}
	this.start = function(){
		this.imgObj = [
			document.getElementById('rotateImg1'), 
			document.getElementById('rotateImg2'), 
			document.getElementById('rotateImg3')
		];
		this.nextRotatingImg = 0;
		this.imgIndex = 0;
		
		pointer = this;
		this.timer = setTimeout(function(){pointer.rotateNext()}, this.setDelay);
		
	}
}

//Get the image link from within its (parent) container.
function getImage(parent) {
  var el = parent.firstChild;
  
  while (el) {  // walk through till as long as there's an element
    if (el.nodeName.toUpperCase() == "IMG") { // found an image
      // flickr uses "_s" suffix for small, and "_m" for big images respectively
      return el.src.replace(/_s\.jpg$/, "_m.jpg");
    }
    el = el.nextSibling;
  }
  
  return "";
}
