

var GStreetMapCaption = function (args){
    if (args){
        this.hlPointsManager = args.hlPointsManager ? args.hlPointsManager : null;
        this.containerId = args.containerId ? args.containerId : null;
    }else{
        this.hlPointsManager = null;
        this.containerId = null;
    }

}

GStreetMapCaption.prototype = {
    setHLPointsManager : function (hlPointsManager){
        this.hlPointsManager = hlPointsManager;
    },
    updateChildsCategories : function (check){
        //Se busca el li padre del check
        var node = $(check).up("li");
        if (node){
            $(node).select("ul li .txt .input-hlpoint-category").each(function (item){
                item.checked = this.checked;
                $(item).fire("my:change");
            }.bind(check));
        }
    },
    updateHLPointsViewState : function (event) {
        var check = event.element();
        var categoryId = check.value;
        var visible = check.checked;
        if (this.hlPointsManager){
            this.hlPointsManager.iterateHLPoints(function (hlPoint){
                //Se cambia la visiblidad de los markers de la categoria actual
                if (hlPoint.categoryId==this.category){
                    if (this.stateView) { hlPoint.show()}
                    else {hlPoint.hide()}
                }
                //Se cambia los checks de categorias hijas
            }.bind({thiz: this, category: categoryId, stateView: visible}));
        }
        this.updateChildsCategories(check);
    },
    registerHLPointsCategoriesInputs : function () {
        if (this.containerId){
            $$('#'+this.containerId+' .input-hlpoint-category').each(function (item){
                $(item).observe('click',this.updateHLPointsViewState.bind(this));
                $(item).observe('my:change',this.updateHLPointsViewState.bind(this));
            }.bind(this));
        }
    }
}

