﻿/// <reference name="MicrosoftAjax.js"/>
Type.registerNamespace("AsiaAustraliaTech");

/// <summary>
/// This component is responsible for entire row hover selection when the rows are grouped
///</summary>
AsiaAustraliaTech.GroupRowHover = function() {
    AsiaAustraliaTech.GroupRowHover.initializeBase(this);

    //fields
    this._HoverClass = null;
    this._GroupAttributeName = null;
    this._onMouseOver$delegate = Function.createDelegate(this, this._onMouseOver);
    this._onMouseOut$delegate = Function.createDelegate(this, this._onMouseOut);
}

AsiaAustraliaTech.GroupRowHover.prototype = {

    //properties
    get_HoverClass: function() {
        return this._HoverClass;
    },

    set_HoverClass: function(value) {
        this._HoverClass = value;
    },

    get_GroupAttributeName: function() {
        return this._GroupAttributeName;
    },

    set_GroupAttributeName: function(value) {
        this._GroupAttributeName = value;
    },

    //constructors
    initialize: function() {
        AsiaAustraliaTech.GroupRowHover.callBaseMethod(this, 'initialize');
        $(String.format("tr[{0}]", this.get_GroupAttributeName())).hover(this._onMouseOver$delegate, this._onMouseOut$delegate);
    },

    dispose: function() {
        this._onMouseOver$delegate = null;
        this._onMouseOut$delegate = null;
        $(String.format("tr[{0}]", this.get_GroupAttributeName())).unbind('onmouseover').unbind('onmouseout');
        AsiaAustraliaTech.GroupRowHover.callBaseMethod(this, 'dispose');
    },

    //private methods
    _onMouseOver: function(evt) {
        id = $(evt.currentTarget).attr(this.get_GroupAttributeName());
        $(String.format("tr[{0}={1}]", this.get_GroupAttributeName(), id)).addClass(this.get_HoverClass());
    },

    _onMouseOut: function(evt) {
        id = $(evt.currentTarget).attr(this.get_GroupAttributeName());
        $(String.format("tr[{0}={1}]", this.get_GroupAttributeName(), id)).removeClass(this.get_HoverClass());
    }
}
AsiaAustraliaTech.GroupRowHover.registerClass('AsiaAustraliaTech.GroupRowHover', Sys.Component);

Sys.Application.add_load(function() {
    if (window.$GroupRowHover) {
        window.$GroupRowHover.dispose();
    }
    window.$GroupRowHover = $create(AsiaAustraliaTech.GroupRowHover, { 'HoverClass': 'trHover', 'GroupAttributeName': 'group' });
});

if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
