var statemyslider1 = true;
var statemyslider2 = true;
var timecount = 0;
var timerstate = true;


function IhcSlideGallery( array )
{
	this.conf = array;
	var count = 0;
	while( count < 20 )
	{
		var el = document.getElementById('ihcslide'+count);
		if( el != null ){
			this.elements[count] = 'ihcslide'+count;
		}else{	
			break;
		}
		count++;
	}
	timer();
}
IhcSlideGallery.prototype.stateAkt = true; 
IhcSlideGallery.prototype.stateNext = true; 
IhcSlideGallery.prototype.elements = new Array();
IhcSlideGallery.prototype.conf = new Array();
IhcSlideGallery.prototype.aktElIndex = 0;



function timer()
{
if( timerstate )
{
	if( timecount < 7 )
	{
		zeitgeber = setTimeout("timer()", 1000);
		timecount++;
	}
	else
	{
		timerstate = false;
		slider.slide('next');
	}
}
}


IhcSlideGallery.prototype.slide = function( direction )
{
	if( statemyslider1  == true && statemyslider2  == true )
	{	
		statemyslider1  = false;
		statemyslider2  = false;
		
		
		var nextElIndex = 1;
		if( direction == 'next' ){
			nextElIndex = this.getNextIndex();
		}else if( direction == 'prev' ){
			nextElIndex = this.getPrevIndex();
		}
		
		var NextEl = this.elements[nextElIndex];
		var AktEl = this.elements[this.aktElIndex];
		
		if( this.conf['effect'] == 'fade' )
			this.effectFade( NextEl, AktEl );
		else if( this.conf['effect'] == 'slide' )
		{
			if(direction == 'next')
				this.effectSlideNext( NextEl, AktEl );
			else
				this.effectSlidePrev( NextEl, AktEl );
		}
		
		timecount = 0;
		if( !timerstate )
		{
			timerstate = true;
			timer();
		}
		this.aktElIndex = nextElIndex;
	}
}

IhcSlideGallery.prototype.getNextIndex = function()
{
	if(this.elements.length-1 > this.aktElIndex ){
		return parseInt(this.aktElIndex, 10 )+1;
	}else{
		return 0;
	}
}

IhcSlideGallery.prototype.getPrevIndex = function()
{
	if( this.aktElIndex > 0 ){
		return parseInt(this.aktElIndex, 10 )-1;
	}else{
		return this.elements.length-1;
	}
}

IhcSlideGallery.prototype.effectFade = function( NextEl, AktEl )
{ 
	var outEffect = new Fx.Morph(AktEl, {duration: this.conf['duration'], transition: this.conf['transition'], onComplete: setMyState1});
	outEffect.start({
		'opacity': [1,0]
	});	
	
	var inEffect = new Fx.Morph(NextEl, {duration: this.conf['duration'], transition: this.conf['transition'], onComplete: setMyState2});
	inEffect.start({
		'opacity': [0,1]
	});	

}

IhcSlideGallery.prototype.effectSlideNext = function( NextEl, AktEl )
{ 
	var outEffect = new Fx.Morph(AktEl, {duration: this.conf['duration'], transition: this.conf['transition'], onComplete: setMyState1});
	outEffect.set({
		'opacity': 1
	});
	outEffect.start({
		'left': [0,-this.conf['width']]
	});	

	var inEffect = new Fx.Morph(NextEl, {duration: this.conf['duration'], transition: this.conf['transition'], onComplete: setMyState2});
	inEffect.set({
		'opacity': 1
	});
	inEffect.start({
		'left': [this.conf['width'],0]
	});	
}

IhcSlideGallery.prototype.effectSlidePrev = function( NextEl, AktEl )
{ 
	var outEffect = new Fx.Morph(AktEl, {duration: this.conf['duration'], transition: this.conf['transition'], onComplete: setMyState1});
	outEffect.set({
		'opacity': 1
	});
	outEffect.start({
		'left': [0,this.conf['width']]
	});	

	var inEffect = new Fx.Morph(NextEl, {duration: this.conf['duration'], transition: this.conf['transition'], onComplete: setMyState2});
	inEffect.set({
		'opacity': 1
	});
	inEffect.start({
		'left': [-this.conf['width'],0]
	});	
}

function setMyState2()
{
	statemyslider2 = true;
}
function setMyState1()
{
	statemyslider1 = true;
}


