//////////////////////////////////////////////////////////////////////////////
//	jaxelement
//////////////////////////////////////////////////////////////////////////////
Jax.Widgets.Element = function() {

    var m_show = null;

    // Declare class and set instance.
    Jax.oop.declare(Jax.Widgets.Element, Jax.Widgets.Widget);
    this.setInstance();
    
    // Set properties.
    this.element = null;
	
    //////////////////////////////////////////////////////////////////////////
    // Initialize
    //////////////////////////////////////////////////////////////////////////
    this.initialize = function(args) {
        this.name = args[0];
        this.parent = args[1];
        this.element = document.getElementById(this.name);
        m_show = this.getStyle("display");
    }
	
    //////////////////////////////////////////////////////////////////////////
    // hide()
    //////////////////////////////////////////////////////////////////////////
    this.hide = function() {
        this.element.style.display = "none";
    }
	
    //////////////////////////////////////////////////////////////////////////
    // show()
    //////////////////////////////////////////////////////////////////////////
    this.show = function(style) {
        if (style != undefined) {
            m_show = style;
        }
        else if (m_show == null || m_show == "none") {
            m_show = "block";
        }
        
        this.element.style.display = m_show;
    }

    //////////////////////////////////////////////////////////////////////////
    // isVisible()
    //////////////////////////////////////////////////////////////////////////
    this.isVisible = function() {
        return this.getStyle().display !== "none";
    }
    
    //////////////////////////////////////////////////////////////////////////
    //	getParentElement
    //////////////////////////////////////////////////////////////////////////
    this.getParentElement = function() {
        return new Jax.Widgets.Element(this.element.parentNode.id, this.parent);
    }
    
    //////////////////////////////////////////////////////////////////////////
    //	getChildren
    //////////////////////////////////////////////////////////////////////////
    this.getChildren = function() {
        var children = [];
        var childNodes = this.element.childNodes;
        for (var ii = 0; ii < childNodes.length; ++ii) {
            if (childNodes[ii].nodeType == 1) {
                children.push(new Jax.Widgets.Element(childNodes[ii].id, this.parent));
            }
        }
        return children;
    }
    
    //////////////////////////////////////////////////////////////////////////
    //  Style
    //////////////////////////////////////////////////////////////////////////
    this.getStyle = function(property) {
        var style = (window.getComputedStyle)
            ? window.getComputedStyle(this.element, null)
            : (this.element.currentStyle)
                ? this.element.currentStyle
                : this.element.style;

        return (property) ? style[property] : style;
    }

    //////////////////////////////////////////////////////////////////////////
    //	Text : Sets the control focus.
    //////////////////////////////////////////////////////////////////////////
    this.getText = function() {
        return this.element.innerHTML;
    }

    this.setText = function(value) {
        return this.element.innerHTML = value;
    }

    //////////////////////////////////////////////////////////////////////////
    // Initialize instance.
    //////////////////////////////////////////////////////////////////////////
    if (arguments.length) {
        this.initialize(arguments);
    }
};