﻿if (!mk) var mk =
{
    info: {
        ver: [2, 9, 8, 3],
        author: "MKing",
        email: "winnie_mk@126.com"
    }, xhr: {
}, magic: {
}, control: {
}, i: function(cName) {	//import a mk class
    var head = document.getElementsByTagName("head");
    if (head.length < 1) {
        alert("HTML dom has no HEAD element.");
        return;
    }
    var scriptEle = document.createElement("script");
    scriptEle.type = "text/javascript";
    scriptEle.src = "mk_" + cName + ".js";
    scriptEle.charset = "utf-8";
    head[0].appendChild(scriptEle);
}, b: {
    /*@cc_on
    isIE: true,
    @*/
    isFF: navigator.userAgent.search(/firefox/i) > -1 ? true : false,
    isOpera: navigator.userAgent.search(/opera/i) > -1 && !this.isIE ? true : false
}, $: function(obj) {
    return typeof obj == "string" ? document.getElementById(obj) : obj;
}, loop: function(arr, fun) {
    if (!arr.length || typeof fun != "function") return;
    for (var i = 0; i < arr.length; i++)
        if (fun(arr[i]))
        break;
}, getSingleNodeInChildNodes: function(tag, parent, index) {
    var _n = false;
    if (typeof tag != "string") return _n;
    var _parent = parent || document;
    var _index = index || 0;
    tag = tag.toLowerCase();
    var _i = 0;
    this.loop(_parent.childNodes, function(n) {
        if (n.nodeType == 1)
            if (n.nodeName.toLowerCase() == tag) {
            _n = n;
            if (_i++ >= _index)
                return true;
        }
    });
    return _n;
}, getChildNodesOfType: function(typeNum, parent) {
    var _cs = [];
    if (typeof typeNum != "number") return _cs;
    var _parent = parent || document;
    this.loop(_parent.childNodes, function(n) {
        if (n.nodeType == typeNum)
            _cs.push(n);
    });
    return _cs;
}, getSingleNodeByTagName: function(tagName, parent, index) {
    if (typeof tagName != "string") return false;
    var _parent = parent || document;
    var _index = typeof index == "number" || 0;
    return _parent.getElementsByTagName(tagName)[_index];
}, getCurrentHeight: function(obj) {
    var height = false;
    if (!obj) return height;
    if (obj.currentStyle) {
        height = obj.currentStyle.height;
    } else if (document.defaultView.getComputedStyle) {
        height = document.defaultView.getComputedStyle(obj, null).height;
    }
    return parseInt(height);
}, loopParentNode: function(self, parentTagName) {
    var n = false;
    if (!self.parentNode || typeof parentTagName != "string") return n;
    var p = self.parentNode;
    parentTagName = parentTagName.toLowerCase();
    while (!!p) {
        if (p.nodeName.toLowerCase() == parentTagName) {
            n = p;
            break;
        }
        p = p.parentNode;
    }
    return n;
}, getDeepAndPath: function(obj, tag, addChildToParent) {
    var _path = [];
    var _deep = 0;
    var _obj = obj;
    var _addChildToParent = !!addChildToParent;
    if (!_obj.childEles) _obj.childEles = [];
    if (typeof tag == "string") {
        tag = tag.toLowerCase();
        while (_obj.parentNode) {
            _obj = _obj.parentNode;
            if (_obj.nodeName.toLowerCase() == tag) {
                _deep++;
                _path.push(_obj);
                if (_addChildToParent)
                    _obj.childEles.push(obj);
            }
        }
    } else {
        while (_obj.parentNode) {
            _obj = _li.parentNode;
            _deep++;
            _path.push(_obj);
            if (_addChildToParent)
                _obj.childEles.push(obj);
        }
    }
    return { path: _path.reverse(), deep: _deep };
}, dom: {	//get all elements of the page. only when nodeType == 1
    nodes: [],
    classNames: [],
    init: function(n, addChildToParent) {
        var _n = n || document;
        var _atp = !!addChildToParent;
        if (!this.nodes.names) this.nodes.names = [];
        for (var i = 0; i < _n.childNodes.length; i++) {
            var node = _n.childNodes[i];
            if (node.nodeType == 1) {
                this.nodes.push(node);
                var nn = node.nodeName.toLowerCase();
                if (!this.nodes[nn]) {
                    this.nodes[nn] = [];
                    this.nodes.names.push(nn);
                }
                this.nodes[nn].push(node);
                if (node.className) {
                    if (!this.classNames[node.className]) {
                        this.classNames.push(node.className);
                        this.classNames[node.className] = [];
                    }
                    this.classNames[node.className].push(node);
                }
                if (_atp) {
                    if (p = node.parentNode) {
                        if (!p.subNodes) p.subNodes = [];
                        p.subNodes.push(node);
                    }
                }
                this.init(node, _atp);
            }
        }
    }
}, splitStep: function(len, stepCount, minValue, type) {
    var steps = [];
    switch (type) {
        default:
            var step = parseInt(len / stepCount);
            steps.push(minValue);
            for (var i = 0; i <= stepCount; i++) {
                var st = step * i;
                if (st > minValue && st < len) steps.push(st);
            }
            steps.push(len);
            return steps;
    }
}, addEvent: function(obj, eventName, fun, bubble) {
    if (obj.addEventListener) {
        obj.addEventListener(eventName, fun, !!bubble);
    } else if (obj.attachEvent) {
        obj.attachEvent("on" + eventName, fun);
    } else {
        obj["on" + eventName] = fun;
    }
}, removeEvent: function(obj, eventName, fun, bubble) {
    if (obj.removeEventListener) {
        obj.removeEventListener(eventName, fun, !!bubble);
    } else if (obj.detachEvent) {
        obj.detachEvent("on" + eventName, fun);
    } else {
        obj["on" + eventName] = null;
    }
}, getRadioPosition: function(radio, angel, addX, addY) {
    return {
        x: Math.cos(angel) * radio + (typeof addX == "number" ? addX : 0),
        y: Math.sin(angel) * radio + (typeof addY == "number" ? addY : 0)
    }
}
};
