﻿Type.registerNamespace('DDTI.Web.Map.Legend');

DDTI.Web.Map.Legend.DTLayerVisibilityControl = function(element) { 
    DDTI.Web.Map.Legend.DTLayerVisibilityControl.initializeBase(this, [element]);
    this._layerIndex = null;
}

DDTI.Web.Map.Legend.DTLayerVisibilityControl.prototype = {
    initialize : function() {
        DDTI.Web.Map.Legend.DTLayerVisibilityControl.callBaseMethod(this, 'initialize');
        this._onclickHandler = Function.createDelegate(this, this._onClick);
        $addHandlers ( this.get_element(), { 'click' : this._onClick }, this );
    },

    dispose : function() {
        $clearHandlers(this.get_element());
        DDTI.Web.Map.Legend.DTLayerVisibilityControl.callBaseMethod(this, 'dispose');
    },

    _onClick : function(e) {
        var w = DDTI.Web.Map.Viewer.DTViewerComponent.prototype.get_width();
        var h = DDTI.Web.Map.Viewer.DTViewerComponent.prototype.get_height();
        DDTI.Web.Map.Viewer.DTViewerComponent.prototype.set_imageUrl('Default.mapx?Todo=ToggleLayer&Layer=' + this._layerIndex + '&Width=' + w + '&Height=' + h + '&Random=' + Math.floor(Math.random()*1000000));
    },
    
    get_layerIndex : function() {
        return this._layerIndex;
    },
    
    set_layerIndex : function(value) {
        if (this._layerIndex !== value) {
            this._layerIndex = value;
            this.raisePropertyChanged('layerIndex');
        }
    }
}

DDTI.Web.Map.Legend.DTLayerVisibilityControl.registerClass('DDTI.Web.Map.Legend.DTLayerVisibilityControl', Sys.UI.Control);

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();