

var dhtml_objects = new Array()

function cross_test() {
    create_object_array()
    //alert(document.getElementById("layer2").offsetWidth)
    //alert(document.layers.layer2.document.height)
    //alert(dhtml_objects["layer2"].visibility)
}

function create_object_array() {

    // All the <div> tags are stored in this array
    var div_tags = new Array()
    
    // Is the browser W3C DOM compliant?
    if (document.getElementById) {
    
        // If so, use getElementsByTagName() to get the <div> tags
        div_tags = document.getElementsByTagName("div")
        
        // Loop through the <div> tags
        for (var counter = 0; counter < div_tags.length; counter++) {
        
            // Store the current <div> object
            current_div = div_tags[counter]
            
            // Store how the browser accesses styles
            object_css = current_div.style
            
            // Store some properties
            object_id = current_div.id
            object_left = parseInt(current_div.style.left)
            object_top = parseInt(current_div.style.top)
            
            // Is the visibility defined?
            if (current_div.style.visibility) {
                object_visibility = current_div.style.visibility
            }
            else {
                object_visibility = "inherit"
            }
            object_units = "px"
            
            // Create a new div_object and store it in dhtml_objects
            dhtml_objects[object_id] = new div_object(current_div,
                                                      object_css, 
                                                      object_id, 
                                                      object_visibility,
                                                      object_units)
        }
    }
    
    // Is the browser DHTML DOM compliant?
    else if (document.all) {
        
        // If so, use document.all to get the <div> tags
        div_tags = document.all.tags("div")
        
        // Loop through the <div> tags
        for (var counter = 0; counter < div_tags.length; counter++) {
        
            // Store the current <div> object
            current_div = div_tags[counter]
            
            // Store how the browser accesses styles
            object_css = current_div.style
            
            // Store some properties
            object_id = current_div.id
            object_left = parseInt(current_div.style.pixelLeft)
            object_top = parseInt(current_div.style.pixelTop)

            // Is the width defined?
            if (current_div.style.width) {
            
                // If so, store the style.width property
                object_width = parseInt(current_div.style.width)
            }
            else {

                // If not, store the offsetWidth property
                object_width = parseInt(current_div.offsetWidth)
            }
            
            // Is the height defined?
            if (current_div.style.height) {
            
                // If so, store the style.height property
                object_height = parseInt(current_div.style.height)
            }
            else {
                
                // If not, store the offsetHeight property
                object_height = parseInt(current_div.offsetHeight)
            }

            // Is the visibility defined?
            if (current_div.style.visibility) {
                object_visibility = current_div.style.visibility
            }
            else {
                object_visibility = "inherit"
            }

            object_units = "px"
            
            // Create a new div_object and store it in dhtml_objects
            dhtml_objects[object_id] = new div_object(current_div,
                                                      object_css, 
                                                      object_id, 
                                                      object_left, 
                                                      object_top, 
                                                      object_width,
                                                      object_height,
                                                      object_visibility,
                                                      object_units)
        }
    }
    
    // Is the browser LDOM compliant?
    else if (document.layers) {
    
        // If so, use document.layers to get the <div> tags
        div_tags = document.layers
        
        // Loop through the <div> tags
        for (var counter = 0; counter < div_tags.length; counter++) {
            
            // Store the current <div> object
            current_div = div_tags[counter]
            
            // Store how the browser accesses styles
            object_css = current_div
            
            // Store some properties
            object_id = current_div.id
            object_visibility = current_div.visibility
            object_units = ""
            
            // Create a new div_object and store it in dhtml_objects
            dhtml_objects[object_id] = new div_object(current_div,
                                                      object_css, 
                                                      object_id, 
                                                      object_visibility,
                                                      object_units)
        }
    }
}

function div_object (obj, css, id, visibility, units) {
    this.obj = obj
    this.css = css
    this.id = id
    this.left = get_left
    this.right = get_right
    this.top = get_top
    this.bottom = get_bottom
    this.width = get_width
    this.height = get_height
    this.visibility = visibility
    this.units = units
    this.set_visibility = set_visibility
    this.move_to = move_to
    this.move_by = move_by
}

function get_left() {
    return parseInt(this.css.left)
}

function get_top() {
    return parseInt(this.css.top)
}

function get_width() {
    
    // Is the a W3C or DHTML DOM browser?
    if (!document.layers) {
        
        // If so, is the width defined?
        if (this.css.width) {
           
            // If so, return the width property
            return parseInt(this.css.width)
        }
        else {
               
            // If not, return the offsetWidth property
           return parseInt(this.obj.offsetWidth)
       }
    }
    else {
    
        // If not, return the document.width property
        return parseInt(this.obj.document.width)
    }
}

function get_height() {
    
    // Is the a W3C or DHTML DOM browser?
    if (!document.layers) {
        
        // If so, is the height defined?
        if (this.css.height) {
           
            // If so, return the height property
            return parseInt(this.css.height)
        }
        else {
               
            // If not, return the offsetHeight property
           return parseInt(this.obj.offsetHeight)
       }
    }
    else {
    
        // If not, return the document.height property
        return parseInt(this.obj.document.height)
    }
}

function get_right() {
    return this.left() + this.width()
}

function get_bottom() {
    return this.top() + this.height()
}

function move_to (new_left, new_top) {
    this.css.left = new_left
    this.css.top = new_top
}

function move_by (delta_left, delta_top) {

    // Add the delta values
    this.css.left = this.left() + parseInt(delta_left)
    this.css.top = this.top() + parseInt(delta_top)
}

function set_visibility (new_visibility) {

    // Is this an LDOM browser?  
    if (document.layers) {
    
        // If so, set the proprietary visibility values
        if (new_visibility == "visible") {
            this.css.visibility = "show"
        }
        else if (new_visibility == "hidden") {
            this.css.visibility = "hide"
        }
        else {
            this.css.visibility = "inherit"
        }
    }
    else {
        
        // Otherwise, just set the visibility
        // to the value of the argument
        this.css.visibility = new_visibility
    }
}
