var WidgetControleur_calendrier = new Class({
	Implements: [Options],
	
	options: {
		racine:'./'
    },
    initialize: function( widget , options ){

		this.widget = widget;
		this.appliquer(options);


		widget.addEvent('resize',this.redimensionner.bind(this));
	
	},
	
	init:function(){

		this.conteneur.set('html','');
		var taille = this.conteneur.getComputedSize();

		this.calendrier = new Calendrier( this.conteneur ,{
			grille:{colonne:1,ligne:1},
			mois:{largeur:taille.width-12,hauteur:taille.height-51},
			navigation:{disposition:false},
			curseur:{jour:'normal'},
			survol_element:false,
			onSelectEvenement:function( agenda , evenement ){
			
				if (evenement.lien_externe) {
					window.open(evenement.lien);	
				} else {
					document.location.href = evenement.lien;
				}

			}.bind(this),
			onBeforeChangeDate:function(debut, fin, _this){

				this.calendrier = _this;
				var div = new Element('div');

				new Request.JSON({
					url:this.racine + 'index.php?controller=calendrier&action=widget_evenement&debut=' + debut.format('%Y%m%d') + '&fin=' + fin.format('%Y%m%d'),
					data: {v465987123_10: true},
					async:false,
					update:div,
					onSuccess:function(agendas){
						this.calendrier.options.agendas = [];
						if (agendas) {
							$each(agendas, function(agenda){
								if (this.options[agenda.code]) {
									this.calendrier.options.agendas.push(agenda);
								}
							},this);
						}
					}.bind(this)
				}).send();

			}.bind(this)
		});

	},
	
	appliquer:function( options ){
		
		this.setOptions(options);
		
		this.conteneur = this.widget.affichage.contenu;
		this.racine = this.conteneur.getElement('input[name=racine]').get('value');
		
		this.init();
	},
	
	redimensionner:function(){

		this.init();
		
	}
	
});



 

