/*
	Class: 
		
		
	Usage:
		
		
	Parameters:
		
		
	Exemple:
	
	About:
		Profil.js v.1.0 for mootools v1.1 05 / 2007
		
		by Floor SA (http://www.floor.ch) MIT-style license
		
		last modified by Denis Schneiter 
*/
var Reasons = new Class({
	options : {
		'img_class' : 'img_reasons',
		'path_img' : '/data/content/'
	},
	
    /*
	Constructor: initialize
		Constructor
	
		-
	*/
	initialize : function(options) {
		this.setOptions(options)
		this._initReasons();
	},
	/*
	Function: _
		Internal method
		
		Parameters:
			
	*/
	_initReasons : function() {
		
		this.div_reasons = $('reasons');
			
		$ES('.' + this.options.img_class, this.div_reasons).each(function(el){

			el.setStyle('cursor', 'pointer');
			
			var current_reason = el.getProperty('title');
			
			if (!this.default_reason) { this.default_reason = current_reason ; }	
			
			el.getParent().addEvent('click', function(){
				if (this.opened_reason) { this._closeReasons(this.opened_reason, current_reason);  }
			
				if (!this.opened_reason) { this.opened_reason = '1'; }
				
				if (this.opened_reason != '0') {
					this._openReasons(current_reason);
				}

			}.bind(this));	
		}, this);
		
		this._openReasons(this.default_reason);	
				
	},
	/*
	Function: _
		Internal method
		
		Parameters:
			
	*/
	_openReasons : function(idlayer) {
		if (idlayer == this.opened_reason) { return; }
		
		$('layer_'+idlayer).setStyle('visibility','hidden');
		
		$('layer_'+idlayer).setStyle('display','block');
	
		$('imgreasons_'+idlayer).setProperty('src',  this.options.path_img + 'image_s/' + idlayer + '.png');
		var heightdiv=100 + $('layer_'+idlayer).clientHeight;
		$('reasons').setStyle('height',heightdiv + 'px');
		$('layer_'+idlayer).setStyle('visibility','visible');
		
		this.opened_reason = idlayer;
				
	},
	/*
	Function: _
		Internal method
		
		Parameters:
			
	*/
	_closeReasons : function(idlayer, current_layer) {
		
		if (idlayer == '0') { 
			this.opened_reason = '1';
			return ;
		}
		
		$('layer_'+idlayer).setStyle('display','none');
		$('imgreasons_' + idlayer).setProperty('src', this.options.path_img + 'image/' + idlayer + '.png');
		
		if (idlayer == current_layer) {
			$('reasons').setStyle('height','100px');
			this.opened_reason = '0';
		}
	}
});

Reasons.implement(new Options, new Events);

// Initialize classes
window.addEvent('domready', function() {
	if ($('reasons')) new Reasons();
});