﻿/// <reference name="MicrosoftAjax.js"/>

Type.registerNamespace("Ovation.Site.icjr.js");

Ovation.Site.icjr.js.collapseExpandBehavior = function(element) {
    Ovation.Site.icjr.js.collapseExpandBehavior.initializeBase(this, [element]);

    this._titleElement = null;
    this._itemsElement = null;
    this._elementStatus = "closed";
}

Ovation.Site.icjr.js.collapseExpandBehavior.prototype = {
    initialize: function() {
        Ovation.Site.icjr.js.collapseExpandBehavior.callBaseMethod(this, 'initialize');

        $addHandlers(this._titleElement,
            {
                click: this._titleClick
            }, this);

        // Add custom initialization here
    },

    dispose: function() {
        $clearHandlers(this._titleElement);

        //Add custom dispose actions here
        Ovation.Site.icjr.js.collapseExpandBehavior.callBaseMethod(this, 'dispose');
    },

    _titleClick: function(e) {
        this._toggleDiv();

        if (this._elementStatus == "closed") {
            this._elementStatus = "opened";
        }
        else {
            this._elementStatus = "closed";
        }
    },

    _toggleDiv: function() {
        if (this._elementStatus == "closed") {
            this._open();
        }
        else {
            this._close();
        }
    },

    // Close Div
    _close: function() {
        this._itemsElement.style.visibility = "hidden";
        this._itemsElement.style.display = "none";

        this._titleElement.className = "title closed";
    },

    // Open Div
    _open: function() {
        this._itemsElement.style.visibility = "visible";
        this._itemsElement.style.display = "block";

        this._titleElement.className = "title opened";
    }
}

Ovation.Site.icjr.js.collapseExpandBehavior.registerClass('Ovation.Site.icjr.js.collapseExpandBehavior', Sys.UI.Behavior);

Ovation.Site.icjr.js.collapseExpandBehavior.createProperty("titleElement");
Ovation.Site.icjr.js.collapseExpandBehavior.createProperty("itemsElement");

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

