var opacityType = '';
var cachedimages = new Array();

function animation(id,div,steps,speed) {
	this.imagesrc = new Array();
	this.imageframes = new Array();
	this.currentimage = 0;
	this.opacity = 100;
	this.id = id;
	this.div = div;
	this.steps = steps;
	this.speed = speed;
	}

function setupAnimation(dummyImage) {
 d = document.getElementById(dummyImage);
	if (typeof d.style.opacity != 'undefined') {
	 opacityType = 'w3c';
	 }
	else if (typeof d.style.MozOpacity != 'undefined') {
	 opacityType = 'mozilla';	
	 }
	else if (typeof d.styleKHTMLOpacity != 'undefined') {
	 opacityType = 'khtml';
	 }
	else if (typeof d.filters == 'object') {
	 opacityType = 'ie';
	 }
	else {
	 opacityType = 'none';
	 }
 if (opacityType != 'none') {
	 for (m=0; m<images.length; m++) {
   loadCache(images[m]);
			c = images[m];
			document.getElementById(c.div).style.backgroundImage = "url('"+c.imageframes[c.currentimage].src+"')";
 		setInterval('fadeImg('+m+')',c.speed);
			}
		}
	}

function loadCache(w) {
	for (i=0; i< w.imagesrc.length; i++) {
		w.imageframes[i] = new Image;
		w.imageframes[i].src = w.imagesrc[i];
		}
 }

function setOpacity(w,opacity) {
 opacity = (opacity >= 99)?99:opacity;
 switch(opacityType) {
	 case 'w3c':
		 w.style.opacity = opacity/100;
			break;
		case 'mozilla':
		 w.style.MozOpacity = opacity/100;
		 break;
		case 'khtml':
		 w.styleKHTMLOpacity = opacity/100;
		 break;
		case 'ie':
		 w.style.filter = 'alpha(opacity:'+opacity+')';
		 break;
	 }
 }

function fadeImg(i) {
 w = images[parseInt(i)];
 if (w.opacity <= -200) {
		w.opacity = 100;
	 setOpacity(document.getElementById(w.id), w.opacity);
	 document.getElementById(w.id).src = w.imageframes[w.currentimage].src;
	 w.currentimage++;
		if (w.currentimage >= w.imageframes.length) {
		 w.currentimage = 0;
		 }
  document.getElementById(w.div).style.backgroundImage = "url('"+w.imageframes[w.currentimage].src+"')";
  }
 w.opacity -= w.steps;
 setOpacity(document.getElementById(w.id), w.opacity);
 }