var promos;
var kids;

function play(action, speed, frames){
 	for (i=0;i<=frames;i++)
 		{
			time=setTimeout(action,speed*i);
 		}
	clearTimeout(time);
}
	

function rollingLogos(id, divname, frequency){

	this.div = document.getElementById(divname);
	
	this.logos = new Array();
	
	// a really hacky bit of code that allows setTimeout to reference this
	// object.
	
	this.obj = id + "Object"
	eval(this.obj + "=this");
	
	this.current = 0;
	this.currentOpacity = 10;
	this.factor = -1;
	this.canFade = true;
	
	this.switchToImage = function(index){
		this.canFade = false;
		this.current=index;
		this.currentOpacity = 10;
		this.factor=1;
		this.div.className='on';
		this.showImage(this.current);
		
	}
	
	this.reset = function(){
		this.canFade = true;
	}
	
	this.nextImage = function(){
		this.current++;
		if(this.current >= this.logos.length) this.current = 0;
		this.showImage(this.current);
	}
	
	this.showImage = function(index){
		for(i=0; i < this.logos.length; i++){
			if(i==index){
				this.logos[i].className="visible";
			}else{
				this.logos[i].className="invisible";
			}
		}
	
	}
	
	this.fade = function(factor){
		if((factor < 0 && this.currentOpacity > 0)||(factor > 0 && this.currentOpacity <10)) this.currentOpacity+=factor;
		if(this.currentOpacity>=10){
			this.div.className = "on";
		}else{
			this.div.className = "vis" + this.currentOpacity;
		}
	}
	
	
	this.fadeToNextImage = function(){
	if(!this.canFade) return;
		if(this.factor < 0){
			if(this.currentOpacity == 0){
				this.factor = 1;
				this.nextImage();
				return;
			}
		}else{
			if(this.currentOpacity >= 10){
			 	return;
			 }
		}
		this.fade(this.factor);
	}
	
	this.changeImage = function(){
		this.factor = -1;
		play(this.obj + '.fadeToNextImage()',40,22);
		setTimeout(this.obj + '.changeImage()',frequency);
	}
	
	divs = this.div.getElementsByTagName('div');
	for(i =0; i < divs.length; i++){
		this.logos[i] = divs.item(i);
	}
	setTimeout(this.obj+'.changeImage()',frequency);
	
}
