﻿
function setup_marquee() {
   if (!document.getElementById("marqueecontainer"))
      return; 
   pic = document.getElementById("marqueecontainer").getElementsByTagName("img");
   marquee_height = document.getElementById("marqueecontainer").style.height;
   speed = 7; //Lower the number to increase the speed
   pix_count = pic.length
   mode = 0;
   spacer = 2; //Add space between images
   myLeft = new Array(pix_count)
   totalWidth = 0;
   
   for (ii=0;ii<pix_count;ii++){ 
      myLeft[ii] = totalWidth
      totalWidth = totalWidth + spacer + pic[ii].width;   
      if (pic[ii].height > marquee_height) {
         marquee_height = pic[ii].height
      }
   }
   myPause = setInterval("startScrolling()",speed)
   document.getElementById("marqueecontainer").style.height = marquee_height + "px";
}

function startScrolling(){
      window.clearInterval(myPause)
      myInterval = setInterval("autoScroll()",speed)	
}	
	
function autoScroll(){
   for (ii=0;ii<pix_count;ii++){
      myLeft[ii] = myLeft[ii] - 1
		
      if (myLeft[ii] == -(spacer + pic[ii].width)){ 
         hhh = 0 //Reset the total pixel length of each of the images.
         for (nnn=0;nnn<pix_count;nnn++){
            if (nnn!=ii){
               hhh = hhh + spacer + pic[nnn].width
            }			
         }
         myLeft[ii] =  hhh
      }
      pic[ii].style.left = myLeft[ii] + "px";
   }
   mode = 1
}

function stop(){
	if (mode == 1){
		window.clearInterval(myInterval)
	}
	if (mode == 0){
		window.clearInterval(myPause)
	}	
}

function go(){
	if (mode == 1){
		myInterval = setInterval("autoScroll()",speed)
	}
	if (mode == 0){
		myPause = setInterval("startScrolling()",speed)
	}	
}

if (window.addEventListener) 
	window.addEventListener("load", setup_marquee, false);
else if (window.attachEvent)
	window.attachEvent("onload", setup_marquee);