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

var actionHandler_photoGallery = {
	isSetup: false,
	photoTotal: 5,
	activePhotoId: 1,
	nextPhotoId: -1,
	setup: function (){
		actionHandler_supportBlocks.total = 0;
	},
	getPhotoElement: function ( id ){
		return this.getElement( "galleryPhotoItem_" + id );
	},
	getThumbElement: function ( id ){
		return this.getElement( "galleryThumbItem_" + id );
	},
	getElement: function ( id ){
		return document.getElementById( id );
	},
	next: function (){
		this.nextPhotoId = this.activePhotoId + 1;
		if( this.nextPhotoId > this.photoTotal )
			this.nextPhotoId = 1;
		this.update();
	},
	prev: function (){
		this.nextPhotoId = this.activePhotoId - 1;
		if( this.nextPhotoId < 1 )
			this.nextPhotoId = this.photoTotal;
		this.update();
	},
	goto: function ( id ){
		this.nextPhotoId = id;
		this.update();
	},
	update: function (){
		if( !this.isSetup )
			this.setup();
		if( this.nextPhotoId != this.activePhotoId ){
			
			//reset all other photos
			this.applyReset();
			
			//get the active photo div
			var activePhotoDiv = this.getPhotoElement( this.activePhotoId );
			
			//disable the active photo
			//activePhotoDiv.style.display = "none";
			//disable the active thumbnail
			this.getThumbElement( this.activePhotoId ).className = "";
			
			//use support block active block to fade
			actionHandler_supportBlocks.activeBlockDiv_out = activePhotoDiv;
			actionHandler_supportBlocks.fadeOut();
			
			
			//get the next photo div
			var nextPhotoDiv = this.getPhotoElement( this.nextPhotoId );
			//enable the next photo
			nextPhotoDiv.style.display = "block";
			//enable the next thumbnail
			this.getThumbElement( this.nextPhotoId ).className = "active";
			
			//set the next photo alpha
			global.setAlpha( nextPhotoDiv, 0 );
			//use support block active block to fade
			actionHandler_supportBlocks.activeBlockDiv_in = nextPhotoDiv;
			actionHandler_supportBlocks.fadeIn();
			
			//update the active photo id
			this.activePhotoId = this.nextPhotoId;
			//update the status message
			this.setStatus();
		}
	},
	setStatus: function (){
		global.setDivContent(
			"gallery_statusDisplay",
			"Viewing Screenshot <strong>" + this.activePhotoId + "</strong> of <strong>" + this.photoTotal + "</strong>"
		);	
	},
	applyReset: function (){
		for( var i = 1; i <= this.photoTotal; i++ ){
			if( i != this.nextPhotoId && i != this.activePhotoId ){
				var divToReset = this.getPhotoElement( i );
				divToReset.style.display = "none";
				global.setAlpha( divToReset, 0 );
			}
		}
	}
}






