
/*******************************************/
/* Copyright Netalfa Kft. - www.netalfa.hu */
/*******************************************/

var nawaElements = Array();

function nawaGetElement (id)
{
    return document.getElementById(id);
}


function nawaElementCreate (e)
{
    if (e == null)
        return null;
    var id = null;
    if (typeof(e) == "string")
    {
        id = e;
        e = document.getElementById(id);
    }
    if (e == null)
        return null;    
    var ne = new NAWAElement();
    ne.element = e;
    ne.id = e.id;
    if (ne.id != null)
        nawaElements[id] = ne;
    return ne;
}

function nawaElement (id)
{
    if (id == null)
        return null;
    var e = nawaElements[id];    
    if (e == null)
    {
        e = nawaElementCreate(id);
        if (e != null)
            nawaElements[id] = e;
    }
    return e;
}

function NAWAElement ()
{
    this.id = null;
    this.element = null;

    this.shower = null;
    this.scroller = null;
    this.mover = null;

    this.getElement = getElement;
    function getElement ()
    {
        if (this.element == null)
            this.element = nawaGetElement(this.id);
        return this.element;
    }

    function init ()
    {
    }

    this.getParent = getParent;
    function getParent ()
    {
        var parent = this.element.parentNode;
        if (parent == null)
            return null;
        var ne = new NAWAElement();
        ne.id = parent.id;
        ne.element = parent;
        return ne;
    }

    this.getWidth = getWidth;
    function getWidth ()
    {
        return this.getElement().offsetWidth;
    }
    
    this.getHeight = getHeight;
    function getHeight ()
    {
        return this.getElement().offsetHeight;
    }

    this.getTop = getTop;
    function getTop ()
    {
        return this.getElement().offsetTop;
    }

    this.getLeft = getLeft;
    function getLeft ()
    {
        return this.getElement().offsetLeft;
    }

    this.setPosition = setPosition;
    function setPosition (top, left)
    {
        this.setTop(top);   
        this.setLeft(left);
    }

    this.setTop = setTop;
    function setTop (top)
    {
        this.getElement().style.top = top;
    }

    this.setTopOffset = setTopOffset;
    function setTopOffset (offset)
    {
        this.setTop(this.getTop() + offset);
    }

    this.setLeft = setLeft;
    function setLeft (left)
    {
        this.getElement().style.left = left;
    }

    this.setLeftOffset = setLeftOffset;
    function setLeftOffset (offset)
    {
        this.setLeft(this.getLeft() + offset);
    }

    this.setRight = setRight;
    function setRight (right)
    {
        this.setLeft(right - this.getWidth());
    }

    this.setBottom = setBottom;
    function setBottom (bottom)
    {
        this.setTop(bottom - this.getHeight());
    }

    this.setFromRight = setFromRight;
    function setFromRight (right)
    {
        this.setLeft(nawaGetAreaWidth() - this.getWidth() - right);
    }

    this.setFromBottom = setFromBottom;
    function setFromBottom (bottom)
    {
        this.setTop(nawaGetAreaHeight() - this.getHeight() - bottom);
    }


    this.setClip = setClip;
    function setClip (clip)
    {
        if (clip == null)
        {
            if (nawaBrowser.isGecko())
                this.getElement().style.clip = null;
            else
                this.getElement().style.clip = "rect(0px," + this.getWidth() + " px," + this.getHeight() + "px,0px)";
        }
        else
        {
            this.getElement().style.clip = clip;
        }
    }

    this.setClipRect = setClipRect;
    function setClipRect (top, right, bottom, left)
    {
        this.getElement().style.clip = "rect(" + top + "px," + right + "px," + bottom + "px," + left + "px)";
    }

    this.isInArea = isInArea;
    function isInArea ()
    {
        var top = this.getTop();
        var left = this.getLeft();
        if ((top > nawaGetAreaHeight()) || (left > nawaGetAreaWidth()) || (left + this.getWidth() < 0) || (top + this.getHeight() < 0))
            return false;
        return true;
    }

    this.show = show;
    function show ()
    {
        this.getElement().style.visibility = "visible";
    }

    this.hide = hide;
    function hide ()
    {
        this.getElement().style.visibility = "hidden";
    }

    this.hideOut = hideOut;
    function hideOut ()
    {
        this.hide();
        /* We move the element to the left to remove the scrollbars in
         * the case the move have grown the area.
         * This case even if the window is resized, the scrollbars won't
         * be shown because of the hidden element.
         */
        this.setPosition(0, (-1 * this.getWidth()));
    }



    this.setPositionCenter = setPositionCenter;
    function setPositionCenter ()
    {
        this.setTop((nawaGetAreaHeight() - this.getHeight()) / 2);
        this.setLeft((nawaGetAreaWidth() - this.getWidth()) / 2);
    }

    this.setPositionHCenter = setPositionHCenter;
    function setPositionHCenter ()
    {
        this.setLeft((nawaGetAreaWidth() - this.getWidth()) / 2);
    }

    this.setPositionVCenter = setPositionVCenter;
    function setPositionVCenter ()
    {
        this.setTop((nawaGetAreaHeight() - this.getHeight()) / 2);
    }


}


