﻿/// <reference name="MicrosoftAjax.js"/>

Type.registerNamespace("hiscall");

hiscall.TreeMenu_Control = function(element) {
    hiscall.TreeMenu_Control.initializeBase(this, [element]);
    
    var _dropMenu;
    var _openImage;
    var _closeImage;
    var _openFolder;
}

hiscall.TreeMenu_Control.prototype = {
    get_dropMenu: function()
    {
        return _dropMenu;
    },
    set_dropMenu: function(value)
    {
        this._dropMenu = value;
    },
    get_openImage: function()
    {
        return this._openImage;
    },
    set_openImage: function(value)
    {
        this._openImage = value;
    },
    get_closeImage: function()
    {
        return this._closeImage;
    },
    set_closeImage: function(value)
    {
        this._closeImage = value;   
    },
    get_openFolder: function()
    {
        return this._openFolder;
    },
    set_openFolder: function(value)
    {
        this._openFolder = value;
    },

    initialize: function() {
        hiscall.TreeMenu_Control.callBaseMethod(this, 'initialize');
        
        this.get_element().src = this._openImage;
        
        var onClickHandler = Function.createDelegate(this, this.onClick);
        
        $addHandler(this.get_element(), "click", onClickHandler);
        
        this._leaveOpen();
    },
    dispose: function() {        
        
        $clearHandlers(this.get_element());
        
        hiscall.TreeMenu_Control.callBaseMethod(this, 'dispose');
    },
    
    onClick: function()
    {
        this._clickToggle();
    },
    
    _clickToggle: function()
    {
        var dropMenu = this._dropMenu;
        
        if ((dropMenu.style.display == "" && dropMenu.style.visibility == "") || 
            (dropMenu.style.display == "none" && dropMenu.style.visibility == "hidden"))
        {
            dropMenu.style.display = "block";
            dropMenu.style.visibility = "visible";
            this.get_element().src = this._closeImage;
        }
        else
        {
            dropMenu.style.display = "none";
            dropMenu.style.visibility = "hidden";
            this.get_element().src = this._openImage;
        }
    },
    
    _leaveOpen: function()
    {       
        var regEx = new RegExp("_.*_", "i");
        var loc = location.pathname;
        
        var results = loc.match(regEx);
        
        if (results == "_" + this._openFolder + "_")
        {
            var dropMenu = this._dropMenu;
            
            dropMenu.style.display = "block";
            dropMenu.style.visibility = "visible";
            this.get_element().src = this._closeImage;
        }
        
        //alert(results);
    }
}
hiscall.TreeMenu_Control.registerClass('hiscall.TreeMenu_Control', Sys.UI.Control);

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
