﻿Type.registerNamespace('Framework.Controls');

Framework.Controls.CheckBoxCssExtender = function(element) {
    Framework.Controls.CheckBoxCssExtender.initializeBase(this, [element]);
    this.el = element;
    this._CheckedCssClass;
    this._CssClass;
    this._div;
    this._clickHandler = Function.createDelegate(this, this._click);
    this._changeHandler = Function.createDelegate(this, this._toggle);
}
Framework.Controls.CheckBoxCssExtender.prototype = {
    get_CssClass: function() {
        return this._CssClass;
    },
    set_CssClass: function(value) {
        this._CssClass = value;
    },
    get_CheckedCssClass: function() {
        return this._CheckedCssClass;
    },
    set_CheckedCssClass: function(value) {
        this._CheckedCssClass = value;
    },

    initialize: function() {
        Framework.Controls.CheckBoxCssExtender.callBaseMethod(this, 'initialize');
        this._createCss();
    },
    dispose: function() {
        Framework.Controls.CheckBoxCssExtender.callBaseMethod(this, 'dispose');

        // remove event handlers
        $removeHandler(this.el, "change", this._changeHandler);
        $removeHandler(this.el, "click", this._clickHandler);
    },

    _createCss: function() {
        // Create div overlay
        this._div = document.createElement("div");
        this.el.parentNode.insertBefore(this._div, this.el)

        //this.el.style.display = "none";
        this._div.style.position = "relative";
        this._div.style.cursor = "pointer";
        this._div.appendChild(this.el);
        this.el.style.position = "absolute";
        this.el.style.cursor = "pointer";
        $(this.el).fadeTo(0, 0);

        // Set initial css classes
        if (!this._CheckedCssClass) this._CheckedCssClass = this._CssClass + "chk";
        if (this.el.checked) this._div.className = this._CheckedCssClass;
        else this._div.className = this._CssClass;

        // Add event handlers
        $addHandler(this.el, "change", this._changeHandler);
        $addHandler(this.el, "click", this._clickHandler);
    },
    _toggle: function(e) {
        if (this.el.checked) {
            this._div.className = this._CheckedCssClass;
        } else {
            this._div.className = this._CssClass;
        }
    },
    _click: function(e) {
        this.el.blur();
    }/*,
    onChange: function(clientFunction) {
        if (clientFunction) clientFunction;
    }*/
}
Framework.Controls.CheckBoxCssExtender.registerClass('Framework.Controls.CheckBoxCssExtender', AjaxControlToolkit.BehaviorBase);
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();