/**
 * => Mootools 1.2
 * 	=> Core
 * @classDescription
 * Classe permettant d'adapter la taille d'un select sous IE quand le texte est trop long pour s'afficher dans la liste déroulante
 * @author M@nu/Baphira
 */
var SelectSizeAdapter = new Class({
	
	Implements: [Options],
	
	options: {
		width: 300,
		ieonly: true
	},

	initialize: function(select, options){
		this.select = $(select);
		this.setOptions(options);
		
		if(this.options.ieonly && !Browser.Engine.trident) {
			return;
		}
		
		this.widthBefore = this.select.getSize();
		this.posBefore = this.select.getStyle('position');
		
		this.select.addEvent('mousedown', function(e) {
			this.expand();
			new Event(e).stop();
		}.bind(this));
		
		this.select.addEvent('change', function(e) {
			this.shrink();
			new Event(e).stop();
		}.bind(this));
		
		this.select.addEvent('blur', function(e) {
			this.shrink();
			new Event(e).stop();
		}.bind(this));
	},
	
	expand: function() {
		this.select.setStyle('position', 'relative');
		this.select.setStyle('width', this.options.width);
	},
	
	shrink: function() {
		this.select.setStyle('width', this.widthBefore.x + 'px');
		this.select.setStyle('position', this.posBefore);
	}
	
});