var ds_Module_Web_Agenda = ds_Base.extend({
	
    options: {},
    mouseX: 0,
    mouseY: 0,
    eventId: 0,
    
    initialize: function(options) {
        this.setOptions(options);
    },

    initEvents: function() {
       var events = $$('ul.activities li a').addEvent('click', this.getEvent.bind(this));
    },

    initSearchForm: function() {
        this.agendaZoekenForm = new ds_Plugin_Form({
            form:$('AgendaSearchForm'),
            onValid: 'redirect',
            scroll: false
        });

        $('keyword').addEvents({
            'blur' : function () {
                if(this.value == ''){
                    this.value = 'Vul een trefwoord in.';
                }
            },
            'focus' : function () {
                if(this.value == 'Vul een trefwoord in.'){
                    this.value = '';
                }
            }
        });
        this.agendaZoekenForm.addButton({icon:'submit', text:'Zoeken', event:this.submitZoekenForm.bind(this)});
    },

    submitZoekenForm: function () {
        if ( $('keyword').getValue() == 'Vul een trefwoord in.') {
            $('keyword').setProperty('value', '');
        }
        $('AgendaSearchForm').submit();
    },

    initAgendaSignUpForm: function () {
        this.agendaSignUpForm = new ds_Plugin_Form({
            form:$('AgendaSignupForm'),
            onValid: 'redirect'
        });
        this.agendaSignUpForm.setWizardFromFieldsets();
    },

    initAgendaSignUpWizard: function (sHref) {
        this.agendaSignUpForm = new ds_Plugin_Form({
            form:$('AgendaSignupForm'),
            onValid: this.redirect.pass([sHref], this)
        });
        $('inschrijvingVerzenden').addEvent('click', this.finishSignup.bind(this));
    },

    initAgendaSignUp: function () {
        $('inschrijven').addEvent('click', this.signUp.bind(this), this);
    },

    signUp: function (e) {
        var evt = new Event(e);
        evt.stop();
        this.signUpDialog = this.getWizard('signup-dialog');

        // Set variable options
        this.signUpDialog.setOptions({
            title: $(evt.target).getProperty('title'),
            width: 400,
            height: 600,
            fnComplete: this.initAgendaSignUpWizard.pass([$(evt.target).getProperty('href')], this)
        });

        // Add wizard buttons
        
        this.signUpDialog.getContent($(evt.target).getProperty('href'));
        this.signUpDialog.wizard.addClass('eventPopup');
        this.signUpDialog.show();
    },
    
    finishSignup: function () {
        this.agendaSignUpForm.processForm();
    }, 

    redirect: function (sHref) {
        var aHref = sHref.split('/');
        document.location.href = '/Web/Cursussen/inschrijving-voltooid/op/' + aHref[7];
    },

    getEvent: function(evt) {
        this.closeTeasers();
        if (this.eventId == 0) {
            var mtEvent = new Event(evt);
            this.eventId = this.numerateString($(mtEvent.target).getProperty('id'));
            var url = '/Web/Agenda/Get-teaser/id/' + this.eventId;
            
            this.eventWizzard = this.getWizard('tip-wizard');

            // Set variable options
            this.eventWizzard.setOptions({
                title: 'Activiteit',
                width: 176,
                height: 'auto'
            });

            this.eventWizzard.getContent(url);
            this.eventWizzard.wizard.addClass('eventPopup');
            this.eventWizzard.show();
        }
    },

    showEvent: function(sResponse) {
        $('event-teaser-'+ this.eventId).setHTML(sResponse);
        $('event-teaser-'+ this.eventId).setStyle('display', 'block');
        $('event-teaser-'+ this.eventId).getElement('a#closeIcon').addEvent('click', this.closeTeasers.bind(this));
    },

    closeTeasers: function() {
       $$('.event-teaser-body').empty();
       $$('.event-teaser-body').setStyle('display', 'none');
       this.eventId = 0;

    }

});

ds_Module_Web_Agenda.implement(new Options);
