/**
*   @file
*   This file requires the following files to be included prior:
*
*   utilities/rbrowserdetector.js
*
*/

if(!gBrowserDetector)
    var gBrowserDetector = new RBrowserDetector();


/**
*
*   Deriving from this class
*   promises that you can insert this class
*   into the DOM.
*
*   @param  type    The type of element we want to create. (e.g. "select")
*   @param  name    The name for the element
*   @param  id      The id for the element
*
*/
function Mixin_DomInsertable(type, name, id)
{
    this.DomNode = document.createElement(type);
    this.DomNode.name = name;
    this.DomNode.id = id;

}


Mixin_DomInsertable.statics = new Object(); // Shared enums and stuff.
Mixin_DomInsertable.statics.INSERTMETHOD_BEFOREASSIBLING = 0; /** Places before, as a sibling.*/
Mixin_DomInsertable.statics.INSERTMETHOD_APPENDASCHILD   = 1; /** Appends to a parent, as a child.) */

/**
*   This function is used internally to allow clients to specify a 'style'
*   and map it to the browser specific style.
*
*   Please look at the switch statement to see the available 'cases'
*   you can use in your code, as it will be the best source of
*   documentation.
*/
Mixin_DomInsertable.statics.GetBrowserStyleName = function(style)
{
    switch(style)
    {
        case "float":
            if(gBrowserDetector.gecko)
            {
                return "cssFloat";
            }

            return "styleFloat";

        // By default, just return the style name.
        default:
            return style;
    }

}


/**
*   This function will stuff a node into the DOM
*
*   @param node         The node you wish to use as a parent or sibling.
*   @param insertMethod How you want the node to be inserted
*                       (see Mixin_DomInsertable.statics.INSERTMETHOD*);
*/
Mixin_DomInsertable.prototype.PlaceInDom = function(node, insertMethod)
{

    switch(insertMethod)
    {
        case Mixin_DomInsertable.statics.INSERTMETHOD_BEFOREASSIBLING:
            node.insertBefore(this.DomNode);
            break;
        case Mixin_DomInsertable.statics.INSERTMETHOD_APPENDASCHILD:
            node.appendChild(this.DomNode);
            break;
    }
}


/**
*   This function will return you an attribute property
*   from within the node.
*/
Mixin_DomInsertable.prototype.GetAttribute  = function(attribute)
{
    return this.GetDomNode().getAttribute(attribute);
}

/**
*   This function will set an attribute property
*   from within the node.
*/
Mixin_DomInsertable.prototype.SetAttribute  = function(attribute, value)
{
    return this.GetDomNode().setAttribute(attribute, value);
}

/**
*   This function will return you a style property
*   from within the node.
*
*   NOTE: Because of browser's having different properties we use
*         the Mixin_DomInsertable.statics.GetBrowserStyleName(...)
*         function to allow simple mappings to different variable
*         names.
*/
Mixin_DomInsertable.prototype.GetStyle  = function(style)
{
    var trueStyleName = Mixin_DomInsertable.statics.GetBrowserStyleName(style);
    return this.GetDomNode().style[trueStyleName];
}

/**
*   This function will set a style property
*   from within the node.
*
*   NOTE: Because of browser's having different properties we use
*         the Mixin_DomInsertable.statics.GetBrowserStyleName(...)
*         function to allow simple mappings to different variable
*         names.
*/
Mixin_DomInsertable.prototype.SetStyle  = function(style, value)
{
    var trueStyleName = Mixin_DomInsertable.statics.GetBrowserStyleName(style);
    return this.GetDomNode().style[trueStyleName] = value;
}



/**
*
*  This function will return you the underlying node.
*
*/
Mixin_DomInsertable.prototype.GetDomNode  = function()
{
    return this.DomNode;
}


/**
*
*  This function will set the DOM node.
*
*/
Mixin_DomInsertable.prototype.SetDomNode  = function(node)
{
    this.DomNode = node;
}


/**
*   This will build you up a string of JS used to get a node.
*
*   (Useful for eval() calls).
*
*/
Mixin_DomInsertable.prototype.GetJSStringToGetNode = function()
{
    return "document.getElementById('" + this.GetDomNode().id + "')";
}

/**
*
*   This will show the instance.
*/
Mixin_DomInsertable.prototype.Show = function()
{

    // Set it as visible.
    this.SetStyle("visibility","");

    // If this was set to disappear, reenable it.
    if(this.GetStyle("display") == "none")
    {
        this.SetStyle("display", "block");
    }
}

/**
*
*   This will hide an instance.
*
*   @param disappear    (Optional) If true, this will make the item take up no space.
*/
Mixin_DomInsertable.prototype.Hide = function(disappear)
{
    this.SetStyle("visibility", "hidden");

    if(disappear)
    {
        this.SetStyle("display", "none");
    }
}
