﻿	var csAdRotator = {};

	csAdRotator.imgList = new Array;
	csAdRotator.hdlInterval = -1;
    csAdRotator.Delay = 6000;
    
	csAdRotator.AddImage = function(oName, imgNames) {
		var imgNames = imgNames.split(',');
		var img = document.getElementById(oName);

		if (img) {
			img.images = new Array;
			img.imageIndex = 0;
			
			for (c=0; c < imgNames.length; c++) img.images.push(imgNames[c]);		
			csAdRotator.imgList.push(img);
			
			if (csAdRotator.hdlInterval < 0) csAdRotator.hdlInterval = window.setTimeout(csAdRotator.doRotate,csAdRotator.Delay);
		}
	}

	csAdRotator.doRotate = function() {
		csAdRotator.hdlInterval = window.setTimeout(csAdRotator.doRotate,csAdRotator.Delay);
		
		for	(c=0; c < csAdRotator.imgList.length; c++) {
			var img = csAdRotator.imgList[c];
			var idx = img.imageIndex +1;

			if (idx >= img.images.length) idx=0;

			var newSrc;
			if (img.src.lastIndexOf('/') >= 0)			
 				newSrc = img.src.substring(0,img.src.lastIndexOf('/') +1) + img.images[idx];
 			else
 				newSrc = img.images[idx];
 				
			img.src = newSrc;
			img.imageIndex = idx;								
		}
	}

	
/*
	Usage:

	    csAdRotator.AddImage('impactLeft','impact_left_1.png,impact_left_2.png,impact_left_3.png,impact_left_4.png,impact_left_6.png');
	
*/	
