FotoPlayer = Ext.extend(Object, {
    
    thumbOpacity: 0.6,
    thumbPadding: 5,
    index: 0,
    containerX: 500,
    fotoEl: null,
    animate: false,
    scrollSpeed: 0,
    btnOpacity: 0,
    
    init: function(bilderwechsel) {
		
        this.fotos = Ext.select('.galerie .galerie-picture a');
		
		if (this.fotos.getCount() > 0) {
			
			this.showFoto();
	
			this.zurueckBtn = Ext.select('.galerie .zurueck');
			this.vorBtn = Ext.select('.galerie .vor');
			
			this.zurueckBtn.on('click', this.onZurueckBtnClick, this);
			this.vorBtn.on('click', this.onVorBtnClick, this);
			this.fotos.on('click', this.onFotosClick, this);
			
			if (bilderwechsel) {
				this.interval = setInterval(this.nextFoto.createDelegate(this), 5000);
			}
		}
    },
	onZurueckBtnClick: function() {
		clearInterval(this.interval);
		this.prevFoto();
	},
	onVorBtnClick: function() {
		clearInterval(this.interval);
		this.nextFoto();
	},
	onFotosClick: function() {
		clearInterval(this.interval);
	},
	prevFoto: function() {
		this.index--;
		if (this.index < 0)
			this.index = this.fotos.getCount() - 1;
			
		this.showFoto();		
	},
	nextFoto: function() {
		this.index++;
		if (this.index >= this.fotos.getCount())
			this.index = 0;
			
		this.showFoto();
	},
	showFoto: function() {
		this.fotos.addClass('hidden');
		this.fotos.item(this.index).removeClass('hidden');
	}
})

Ext.onReady(function(){
    var player = new FotoPlayer();
    player.init(this.bilderwechsel);
}, this)
