﻿Type.registerNamespace('dotMailer.SignupForm.Constructor');

dotMailer.SignupForm.Constructor = Class.create({
    initialize: function(FormPanelID, LinkID, LinkImageOpen, LinkImageClose) {
        this.FormPanel = $(FormPanelID);
        this.getFormElements();
        this.Link = $(LinkID);
        var images = this.Link.getElementsByTagName('img');
        if (images.length > 0) {
            this.LinkImage = $(images[0]);
        }

        this.LinkImageOpened = LinkImageOpen;
        this.LinkImageClosed = LinkImageClose;
        this.Link.observe('click', this.ToggleForm.bindAsEventListener(this));

        if (arguments.length > 4) {
            for (var i = 4; i < arguments.length; i++) {
                $(arguments[i]).observe('click', this.ToggleForm.bindAsEventListener(this));
            }
        }
    },
    getFormElements: function() {
        this.FormElements = new Array();
        var e = this.FormPanel.childNodes;
        for (var i = 0; i < e.length; i++) {
            this.FormElements.push(e[i]);
        }
    },
    ToggleForm: function(event) {
        event.stop(event);

        if (this.LinkImage.readAttribute('src') == this.LinkImageClosed) {
            this.LinkImage.setAttribute('src', this.LinkImageOpened);
            this.FormPanel.style.display = 'block';
        } else {
            this.LinkImage.setAttribute('src', this.LinkImageClosed);
            this.FormPanel.style.display = 'none';
        }

    }
})

