var ARIAdvancedList = new Class({
	options: {
		selectId: null,
		hiddenId: null,
		splitter: ';'
	},
	
	initialize: function(options) {
		this.setOptions(options);
		
		var self = this;
		$(this.options.selectId).addEvent('change', function(event) {
			var ctrl = event.target,
				values = [];			

			$(ctrl).getElements('option').each(function(opt) {
				if (opt.selected)
					values.push(opt.value);
					
				$(self.options.hiddenId).value = values.join(self.options.splitter);
			});
		});

		if (typeof(jQuery) != 'undefined' && typeof(jQuery.fn.chosen) != 'undefined')
			jQuery('#' + this.options.selectId).chosen().change(function(e, data) {
				var hidEl = $(self.options.hiddenId),
					values = [];
				if (hidEl.value)
					values = hidEl.value.split(self.options.splitter);
	
				if (typeof(data.selected) != 'undefined') {
					values.push(data.selected);
				} else if (typeof(data.deselected) != 'undefined') {
					var idx = values.indexOf(data.deselected);
					if (idx > -1) {
						delete values[idx];
						values = values.clean();
					}
				};
	
				hidEl.value = values.join(self.options.splitter);
			});
	}
});
ARIAdvancedList.implement(new Options);