function IhcFadeGallery( galleryelement )
{      
	this.galleryEl = galleryelement.getElements('img:not([class*=spacer-gif])');
	var lastIndex = this.galleryEl.indexOf(this.galleryEl.getLast());
	if( !(lastIndex > 0) ){
		return;
	}
	this.galleryEl.setStyles({
		'position':'absolute',
		'top':0,
		'left':0,
		'opacity':0
	});
	galleryelement.setStyle('visibility','visible');

	
	this.anzEl = parseInt(this.galleryEl.indexOf( this.galleryEl.getLast() ))+1;

	this.fade(0);
	this.autofade();
}

IhcFadeGallery.prototype.galleryEl = null;  
IhcFadeGallery.prototype.aktElIndex = 0;
IhcFadeGallery.prototype.anzEl = 0;
IhcFadeGallery.prototype.timer = 0;

IhcFadeGallery.prototype.getNext = function()
{
	if(this.anzEl-1 > this.aktElIndex ){
		return parseInt(this.aktElIndex, 10 )+1;
	}else{
		return 0;
	}
}

IhcFadeGallery.prototype.getPrev = function()
{
	if( this.aktElIndex > 0 ){
		return parseInt(this.aktElIndex, 10 )-1;
	}else{
		return this.anzEl-1;
	}
}

IhcFadeGallery.prototype.autofade = function()
{
	var myObject = this;
	if( this.timer <= 6000 ){
		this.timer = this.timer + 100;
	}else{
		this.fade(this.getNext());
	}
	setTimeout(function(){myObject.autofade();},100);
}

IhcFadeGallery.prototype.fade = function( index )
{
	this.timer = 0;
	if( index >= 0 ){
		this.galleryEl[this.aktElIndex].set('tween', {duration: 1500});
		this.galleryEl[this.aktElIndex].tween('opacity',0);
	}
	this.galleryEl[index].set('tween', {duration: 1500});
	this.galleryEl[index].tween('opacity',1);
	this.aktElIndex = index;
}

