
function Collisions()
{
    this.update();
}

Collisions.prototype.update = function()
{
    function getMatches(nodeList)
    {
        var ret = [];
        
        for(i in nodeList) {
            
            if(!nodeList[i])
                continue;
            
            if(nodeList[i].className && nodeList[i].className.indexOf('solid') != -1) {
                
                ret[ret.length] = nodeList[i];
            }
            
            if(nodeList[i].childNodes) {
                
                var matches = getMatches(nodeList[i].childNodes);
                
                for(j in matches)
                    ret[ret.length] = matches[j];
            }
        }
        
        return ret;
    }
    
    this.boxes = getMatches(document.body.childNodes);
}

// Returns an object with these attributes: x, y, w, h
Collisions.prototype.getColBox = function(node)
{
    var ret = {};
    
    ret.x = node.offsetLeft;
    ret.y = node.offsetTop;
    ret.w = node.offsetWidth;
    ret.h = node.offsetHeight;
    
    while(node = node.offsetParent) {
        
        ret.x += node.offsetLeft;
        ret.y += node.offsetTop;
    }
    
    return ret;
}

Collisions.prototype.isSolid = function(x, y, w, h)
{
    for(i in this.boxes) {
        
        var b = this.getColBox(this.boxes[i]);
        
        if(!(x + w < b.x || x > b.x + b.w || y + h < b.y || y > b.y + b.h))
            return true;
    }
}
