if (debug_mode === true) {
}
else {
    var console = function() {};
    console.log = function() {};
}

function browserIsSupported() {
    var check = document.getElementById && document.getElementsByTagName && createXMLHTTPObject();
    if (!check)
        return false;
    else
        return true;
}

function _$(domFunction, arg, base, predicate) {
    var result = null;
    try {
        if (base && base[domFunction]) {
            result = base[domFunction](arg);
        }
        else if (document && document[domFunction]) {
            result = document[domFunction](arg);
        }
    }
    catch (e) {
        console.log('domFunction not available');
    }
    if (typeof predicate == 'function' && result.length > 0) {
        var collect = [];
        for (var i = 0; i < result.length; i++) {
            if (predicate(result[i])) {
                collect.push(result[i]);
            }
        }
        result = collect;
    }
    return result;
}

function $id(id, base) {
    return _$('getElementById', id, base);
}

function $class(className, base) {
    return _$('getElementsByTagName', '*', base, function(el) {return el.className.indexOf(className) != -1});
}

function $tag(tag, base) {
    return _$('getElementsByTagName', tag, base);
}

function addEvent(target, event, handler) {
    if (target.addEventListener) {
        target.addEventListener(event, handler, false);
    }
    else if (target.attachEvent) {
        target.attachEvent('on' + event, handler);
    }
}

function removeEvent(target, event, handler) {
    if (target.removeEventListener) {
        target.removeEventListener(event, handler, false);
    }
    else if (target.detachEvent) {
        target.detachEvent('on' + event, handler);
    }
}

var my = {};

my.dom = {};

my.dom.elSize = function(el) {
    var width = el.offsetWidth || el.style.pixelWidth;
    var height = el.offsetHeight || el.style.pixelHeight;
    return {width: width, height: height};
};

my.dom.bodySize = function() {
    var docElem = document.documentElement;
    var width = (docElem && docElem.scrollWidth) || document.body.scrollWidth;
    var height = (docElem && docElem.scrollHeight) || document.body.scrollHeight;
    return {width: width, height: height};
};

my.dom.bodyScroll = function() {
    var docElem = document.documentElement;
    var x = self.pageXOffset || (docElem && docElem.scrollLeft) || document.body.scrollLeft;
    var y = self.pageYOffset || (docElem && docElem.scrollTop) || document.body.scrollTop;
    return {'x': x, 'y': y};
};

my.dom.winSize = function() {
    var docElem = document.documentElement;
    var width = window.innerWidth || (docElem && docElem.clientWidth) || document.body.clientWidth;
    var height = window.innerHeight || (docElem && docElem.clientHeight) || document.body.clientHeight;
    return {'width': width, 'height': height};
};



my.dom.onReadyDo = (function() {
    
    function onReadyDo(func) {
        addEvent(window, 'load', func);
        return;

        var found = false;

        for (var h in handlers) {
            if (handlers[h] === func) {
                found = true;
                break;
            }
        }

        if (!found) {
            handlers.push(func);
        }
    }
    
    return onReadyDo;

    if (document.addEventListener) {
        document.addEventListener('DOMContentLoaded', callHandlers, false);
    }

    /*@cc_on @*/
    /*@if (@_win32)
    document.write('<script id="__ie_onload" defer src="javascript:void(0)"><\/script>');
    var script = document.getElementById("__ie_onload");
    script.onreadystatechange = function() {
        if (this.readyState == 'complete') {
            callHandlers();
        }
    }
    @end @*/

    var handlers = [];

    function callHandlers() {
        for (var h in handlers) {
            if (typeof handlers[h] == 'function') {
                handlers[h]();
            }
        }
    }
})();
