if (document.getElementById && document.createElement && 
    document.createTextNode && document.getElementsByTagName) {

var picSwap = {

	picSource : document.getElementById('picChange'),
	
	theBody : document.getElementsByTagName('body')[0],
	
 
  timeDelay : 5*1000, // change delay time in seconds
	
	pix : ['images/image1.jpg', 'images/image2.jpg', 'images/image3.jpg', 'images/image4.jpg', 'images/image5.jpg', 'images/image6.jpg'],


	howMany : null ,
	
	PicCurrentNum : 0,
	


  init : function() {
  
    // configure event listening
    this.util.configEvents();
		
		this.howMany = picSwap.pix.length;
		
    // assign listeners to the onload
    this.util.addEvent(window, 'load', this.preloader, true);
		

  },
	
	preloader : function()  {

    imageObj = new Image();
    // start preloading     
		for(var i=0; i<picSwap.howMany; i++) {          
		  imageObj.src= picSwap.pix[i];     
		}
		
		 picSwap.startPix();
	}, 
	
	startPix : function()  {
	  setInterval("picSwap.slideshow()", picSwap.timeDelay);
	},
	
  slideshow : function() {
    picSwap.PicCurrentNum++;
    if (picSwap.PicCurrentNum == picSwap.howMany) {
    picSwap.PicCurrentNum = 0;
    }
    picSwap.picSource.src = picSwap.pix[picSwap.PicCurrentNum];
		picSwap.labelSource.firstChild.nodeValue=picSwap.labels[picSwap.PicCurrentNum]
  },

  util : {

    configEvents : function() {
      if (document.addEventListener) {
        this.addEvent = function(el, type, func, capture) { el.addEventListener(type, func, capture); };
        this.stopBubble = function(evt) { evt.stopPropagation(); };
        this.stopDefault = function(evt) { evt.preventDefault(); };
        this.findTarget = function(evt, targetNode, container) {
         var currentNode = evt.target;
         while (currentNode && currentNode !== container) {
          if (currentNode.nodeName.toLowerCase() === targetNode) { return currentNode; break; }
          else { currentNode = currentNode.parentNode; }
         };
         return false;
        };
      }
      else if (document.attachEvent) {
       this.addEvent = function(el, type, func) { el["e" + type + func] = func; el[type + func] = function() { el["e" + type + func] (window.event); }; el.attachEvent("on" + type, el[type + func]); };
       this.stopBubble = function(evt) { evt.cancelBubble = true; };
       this.stopDefault = function(evt) { evt.returnValue = false; };
       this.findTarget = function(evt, targetNode, container) { var currentNode = evt.srcElement; 
        while (currentNode && currentNode !== container) {
         if (currentNode.nodeName.toLowerCase() === targetNode) { return currentNode; break; }
         else { currentNode = currentNode.parentNode; }
        };
        return false;
       };
      }
    }
  }
};

picSwap.init();

}
