//
// Global imageSwapper management -- BIS (Bugimus Image Swapper)
//

bugBase.prototype.attachBIS = function() {
	this.BISnum = 0
	this.BISobj = new Array()
}
window.bugimus.attachBIS()

//
// Local imageSwapper functionality
//
function imageSwapper( rate ) {
//	this.browser = new sniffer()
	this.objname = "window.bugimus.BISobj[" + window.bugimus.BISnum + "]"
	window.bugimus.BISobj[window.bugimus.BISnum++] = this
	this.rate = rate
	this.imageindex = -1
	this.numimages = 0
	this.goingup = false
	this.stopall = false
	this.timer = null
	this.img = new Array()
}

imageSwapper.prototype.fall = function( placement, delay ) {
	for( k=1; k<this.numimages; k++, delay++ ) {
		this.timer=setTimeout( this.objname+".showimage('"+placement+"','"+k+"')", delay*this.rate );
		this.imageindex=k;
	}
	return delay;
}

imageSwapper.prototype.rise = function( placement, delay ) {
	for( k=this.numimages-2; k>=0; k--, delay++ ) {
		this.timer=setTimeout( this.objname+".showimage('"+placement+"','"+k+"')", delay*this.rate );
		this.imageindex=k;
	}
	return delay;
}

imageSwapper.prototype.showimage = function( placement, imagenum ) {
	if( imagenum<this.numimages ) document.getElementById(placement).src=this.img[imagenum].src;
	this.imageindex=imagenum;
}

imageSwapper.prototype.loadimage = function( source ) {
	this.img[this.numimages] = new Image()
	this.img[this.numimages].src = source
	this.numimages++
}

imageSwapper.prototype.incimage = function() {
	if( this.imageindex >= this.numimages-1 ) this.imageindex=0;
	else this.imageindex++;
}

imageSwapper.prototype.decimage = function() {
	if( this.imageindex <= 0 ) this.imageindex=this.numimages-1;
	else this.imageindex--;
}

imageSwapper.prototype.stop = function() {
	this.stopall=true
}

imageSwapper.prototype.loop = function( placement, direction ) {
	if( direction=="UP" ) this.decimage(); else this.incimage();
	this.showimage( placement, this.imageindex );
	if( !this.stopall ) this.timer=setTimeout( this.objname+".loop('"+placement+"','"+direction+"')", this.rate );
	else this.stopall=false;
}

imageSwapper.prototype.bounce = function( placement ) {

//alert('hello')

	if( this.goingup && this.imageindex >= this.numimages-1 ) this.goingup=false;
	else if( !this.goingup && this.imageindex <= 0 ) this.goingup=true;
	if( this.goingup ) this.incimage(); else this.decimage();
	this.showimage( placement, this.imageindex );
	if( !this.stopall ) this.timer=setTimeout( this.objname+".bounce('"+placement+"')", this.rate );
	else this.stopall=false;
}

