﻿Type.registerNamespace("Mcw.Rijksoverheid.GoogleMaps");

Mcw.Rijksoverheid.GoogleMaps.TagGroup = function (element) {
    Mcw.Rijksoverheid.GoogleMaps.TagGroup.initializeBase(this, [element]);

    this._element = element;
    this._node = null;
    this._intID = null;
    this._strName = null;
    this._arrTags = [];
}

Mcw.Rijksoverheid.GoogleMaps.TagGroup.prototype = {
    initialize: function () {
        Mcw.Rijksoverheid.GoogleMaps.TagGroup.callBaseMethod(this, 'initialize');

        // Set properties.
        this._intID = this._node.getAttribute("id");
        this._strName = this._node.getAttribute("name");

        // Set header text.
        $(this._element).find("a").text(this._strName);

        // Get tag nodes.
        var arrTags = this._node.getElementsByTagName("tag");

        // Create collection of Tag instances.
        for (var i = 0; i < arrTags.length; i++)
            Array.add(this._arrTags, $create(Mcw.Rijksoverheid.GoogleMaps.Tag, { Node: arrTags[i], TagGroupID: this._intID }, null, null, this.addAndGetTagElement()));
    },
    dispose: function () {
        Mcw.Rijksoverheid.GoogleMaps.TagGroup.callBaseMethod(this, 'dispose');
    },
    addAndGetTagElement: function () {
        // Create listitem element.
        var elLi = document.createElement("li");

        // Create label element.
        var elLbl = document.createElement("label");

        // Create heckbox.
        var elOption = document.createElement("input");
        $(elOption).attr('type', 'checkbox');

        // Append elements.
        elLi.appendChild(elOption);
        elLi.appendChild(elLbl);
        $(this._element).find("ul").append(elLi);
        
        // Check attribute by default.
        $(elOption).attr('checked', 'checked');

        // Return reference to listitem element.
        return elLi;
    },

    get_Node: function () {
        return this._node;
    },
    set_Node: function (value) {
        this._node = value;
    }
}

Mcw.Rijksoverheid.GoogleMaps.TagGroup.registerClass("Mcw.Rijksoverheid.GoogleMaps.TagGroup", Sys.UI.Control);
