var epaAcc = new Class ({

	Implements: [Options, Events],

	options: {
		onComplete      : Class.empty,
		fixedHeight     : false,
		slideBg         : false,
		bgHeight        : "",
		imgLoad         : [],
		duration        : 600,
		imgOn           : "_on",
		imgOff          : "_off",
		opacity         : false,
		onClass         : "",
		specClass       : "",
		start           : ''
	},

	initialize: function(container, togg, elem, options) {
		this.setOptions(options);
		this.container  = $(container);
		this.togg       = $$('.' + togg) || [];
		this.elem       = $$('.' + elem) || [];

		if (this.container){

			//slide du fond si true dans options
			if(this.options.slideBg == true){
				this.slidingBg();
			}

			//preload des images
			var preload = new Asset.images(this.options.imgLoad);
			//l'accordéon avec changement d'images
			this.togg.setStyle('cursor', 'pointer');
			var ziAcc   = new Accordion (this.togg, this.elem, {
				duration     : this.options.duration,
				fixedHeight  : this.options.fixedHeight,
				opacity      : this.options.opacity,
				onActive  : function(toggler){
					var imgsrc = toggler.getStyle('background-image').toString();
					var newsrc = imgsrc.replace(this.options.imgOff.toString(), this.options.imgOn.toString());
					toggler.setStyle('background-image', newsrc);
					if (this.options.specClass != "" && toggler.hasClass(this.options.specClass)) toggler.addClass(this.options.onClass);
				}.bind(this),
				onBackground : function(toggler){
					var imgsrc = toggler.getStyle('background-image');
					var newsrc = imgsrc.replace(this.options.imgOn, this.options.imgOff);
					toggler.setStyle('background-image', newsrc);
					if (this.options.specClass != "" && toggler.hasClass(this.options.specClass)) toggler.removeClass(this.options.onClass);
				}.bind(this),
				start: this.options.start
			});
		}
	},

	slidingBg: function(){
		//pour cette burne d'ie...
		this.container.setStyle('background-position', [0, 0]);

		this.bgFx = new Fx.Morph(this.container, { 'duration': this.options.duration })

		this.togg.each(function(el, i){
			el.addEvent('click', function(){
				if (i == 0){
					if (this.container.getStyle('background-position') != [0, 0]) {
						this.bgFx.start({'background-position': '0, 0'});
					}
				}
				else {
					if (this.container.getStyle('background-position') != [0, - this.options.bgHeight]) {
						this.bgFx.start({'background-position': '0, -' + this.options.bgHeight});
					}
				}
			}.bind(this));
		}.bind(this));
	}

});
