
// depends on common.js: QQ
if (typeof QQ === "undefined") {
    var QQ = {};
}
QQ.Element = function() {

    return {
        // returns element, id might be element itself or id of the element
        getObject: function(id){
            if (obj(id) != null) 
                return obj(id);
            else 
                return id;
        },
        // toggle an element
        toggle: function(elementID, on){
            var id;
            if (obj(elementID) != null) {
                id = obj(elementID);
            }
            else {
                id = elementID;
            }
            if (on == "true" || on == 1) {
                try {
                    id.style.display = "block";
                } 
                catch (e) {
                    alert(e);
                }
            }
            else 
                if (on == "false" || on == 0) {
                    try {
                        id.style.display = "none";
                    } 
                    catch (e) {
                        alert(e);
                    }
                }
                else {
                    if (id.style.display == "display") {
                        id.style.display = "none";
                    }
                    else 
                        if (id.style.display == "none") {
                            id.style.display = "display";
                        }
                }
        },
        // returns the element that triggered the event
        getEventObject: function(evt){
            if (evt.srcElement !== undefined) 
                return event.srcElement; // for IE7
            return evt.target; // for other browsers
        },
        getSize: function(id){
            var object = this.getObject(id);
            
            var Size = {};
            Size.width = object.scrollWidth;
            Size.height = object.scrollHeight;
            
            return Size;
        },
        getWidth: function(id){
            return this.getSize(id).width;
        },
        getHeight: function(id){
            return this.getSize(id).height;
        },
        getPosition: function(id){
            var object = this.getObject(id);
            
            var leftOffset = object.offsetLeft;
            var topOffset = object.offsetTop;
            var parent = object.offsetParent;
            
            while (parent != document.body && parent != null) {
                leftOffset += parent.offsetLeft;
                topOffset += parent.offsetTop;
                parent = parent.offsetParent;
            }
            
            var Position = {};
            Position.x = leftOffset;
            Position.y = topOffset;
            
            return Position;
        },
        getX: function(id){
            return this.getPosition(id).x;
        },
        getY: function(id){
            return this.getPosition(id).y;
        }
    };
}();
