/****************************************
|
| Translational Research Centre, CHRI
| Created by: Kevin Biskaborn
| Copyright 2009 ScriptReaction
| http://www.scriptreaction.com
|
****************************************/

var actionHandler_supportBlocks = {
	activeBlockId: 0,
	activeBlockDiv_in: {},
	activeBlockDiv_out: {},
	total: -1,
	delay: 2000, //display time for each item
	speed: 50, //fade step speed
	launch: function (){
		this.setup();
	},
	setup: function (){
		//get the total number of blocks
		this.total = (this.getElement( "supporterBlock_fader" )).getElementsByTagName( "div" ).length;
		//select the starting block
		//this.activeBlockId = Math.floor( Math.random() * this.total ) + 1;
		//start the fading
		this.fadeNext();
	},
	getElement: function ( id ){
		return document.getElementById( id );
	},
	fadeNext: function (){
		//get next block
		this.activeBlockId++;
		if( this.activeBlockId > this.total )
			this.activeBlockId = 1;
			
		//reset timers
		if(typeof(this.timer_in) != "undefined") clearTimeout(this.timer_in);
		if(typeof(this.timer_out) != "undefined") clearTimeout(this.timer_out);
		if(typeof(this.timer) != "undefined") clearTimeout(this.timer);
		
		//get active div
		this.activeBlockDiv = this.getElement( "supportBlockItem_" + this.activeBlockId );
		//update active fade div vars
		this.activeBlockDiv_in = this.activeBlockDiv;
		this.activeBlockDiv_out = this.activeBlockDiv;
		
		//set initial div alpha
		global.setAlpha( this.activeBlockDiv, 0 );
		//activate the div display
		this.activeBlockDiv.style.display = "block";
		
		this.fadeIn();
	},
	fadeIn: function (){
		var dsp = this.activeBlockDiv_in;
		var alpha = Math.round( dsp.style.opacity * 100 );
		if(alpha < 100){
			global.setAlpha( dsp, alpha += 10 );
			this.timer_in = setTimeout("actionHandler_supportBlocks.fadeIn()", this.speed);
		} else {
			global.setAlpha( dsp, 100 );
			if(this.total > 1) //do not fade if only 1 item
				this.timer = setTimeout("actionHandler_supportBlocks.fadeOut()", this.delay);
		}
	},
	fadeOut: function (){
		var dsp = this.activeBlockDiv_out;
		var alpha = Math.round( dsp.style.opacity * 100 );
		if(alpha > 0){
			global.setAlpha( dsp, alpha -= 10 );
			this.timer_out = setTimeout("actionHandler_supportBlocks.fadeOut()", this.speed);
		} else {
			global.setAlpha( dsp, 0 );
			dsp.style.display = "none";
			if(this.total > 1) //do not fade if only 1 item
				this.fadeNext();
		}
	}
}






