﻿if (typeof ($CONFIG) == "undefined" || !$CONFIG) {
    $CONFIG = {}
}
var scope = $CONFIG;
scope._ua = navigator.userAgent.toLowerCase();
scope.$IE = /msie/.test(scope._ua);
scope.$OPERA = /opera/.test(scope._ua);
scope.$MOZ = /gecko/.test(scope._ua);
scope.$IE5 = /msie 5 /.test(scope._ua);
scope.$IE55 = /msie 5.5/.test(scope._ua);
scope.$IE6 = /msie 6/.test(scope._ua);
scope.$IE7 = /msie 7/.test(scope._ua);
scope.$SAFARI = /safari/.test(scope._ua);
scope.$winXP = /windows nt 5.1/.test(scope._ua);
scope.$winVista = /windows nt 6.0/.test(scope._ua);
var $IE = scope.$IE,
$MOZ = scope.$MOZ,
$IE6 = scope.$IE6;
var Boot = {};
Boot.addDOMLoadEvent = function (func) {
    if (!window.__load_events) {
        var init = function () {
            if (arguments.callee.done) {
                return
            }
            arguments.callee.done = true;
            if (window.__load_timer) {
                clearInterval(window.__load_timer);
                window.__load_timer = null
            }
            for (var i = 0; i < window.__load_events.length; i++) {
                window.__load_events[i]()
            }
            window.__load_events = null
        };
        if (document.addEventListener) {
            document.addEventListener("DOMContentLoaded", init, false)
        }
        if (/WebKit/i.test(navigator.userAgent)) {
            window.__load_timer = setInterval(function () {
                if (/loaded|complete/.test(document.readyState)) {
                    init()
                }
            },
            10)
        }
        if (window.ActiveXObject) {
            window.__load_timer = setInterval(function () {
                try {
                    document.body.doScroll("left");
                    init()
                } catch (ex) { }
            },
            10)
        }
        window.onload = init;
        window.__load_events = []
    }
    window.__load_events.push(func)
};
Boot.getJsVersion = function () {
    var ver = false;
    if ($CONFIG) {
        ver = $CONFIG.js ? $CONFIG.js : ""
    }
    if (ver) {
        return "?v=" + ver
    } else {
        return ""
    }
};
try {
    Boot.addDOMLoadEvent(main)
} catch (e) { }
if (typeof Dae == "undefined") {
    Dae = {}
}
Dae.pkg = function (ns) {
    if (!ns || !ns.length) {
        return null
    }
    var levels = ns.split(".");
    var nsobj = Dae;
    for (var i = (levels[0] == "Dae") ? 1 : 0; i < levels.length; ++i) {
        nsobj[levels[i]] = nsobj[levels[i]] || {};
        nsobj = nsobj[levels[i]]
    }
    return nsobj
};
function $E(oID) {
    var node = typeof oID == "string" ? document.getElementById(oID) : oID;
    if (node != null) {
        return node
    } else { }
    return null
}
function $C(tagName) {
    return document.createElement(tagName)
}
function $N(name) {
    return document.getElementsByName(name)
}
Dae.pkg("Core");
if (typeof Core == "undefined") {
    Core = Dae.Core
}
Dae.pkg("Core.Array");
Core.Array.each = function (ar, insp) {
    var r = [];
    for (var i = 0; i < ar.length; i++) {
        var x = insp(ar[i], i);
        if (x !== null) {
            r.push(x)
        }
    }
    return r
};

Core.Array.foreach = function (ar, insp) {
    if (ar == null && ar.constructor != Array) {
        return []
    }
    var i = 0,
    len = ar.length,
    r = [];
    while (i < len) {
        var x = insp(ar[i], i);
        if (x !== null) {
            r[r.length] = x
        }
        i++
    }
    return r
};
function Jobs() {
    this._jobTable = []
}
Jobs.prototype = {
    _registedJobTable: {},
    initialize: function () { },
    _registJob: function (jobName, rel) {
        this._registedJobTable[jobName] = rel
    },
    add: function (jobName) {
        this._jobTable.push(jobName)
    },
    start: function () {
        var jobs = this._jobTable;
        var regJobs = this._registedJobTable;
        var i = 0;
        var joblen = this._jobTable.length;
        var getTime = function () {
            return new Date().valueOf()
        };
        var interNum = window.setInterval(function () {
            if (i >= joblen) {
                clearInterval(interNum);
                return
            }
            var jobName = jobs[i];
            var job = regJobs[jobName];
            i++;
            if (typeof job == "undefined") {
                return
            }
            var _try = true;
            var _start = getTime();
            try {
                job.call()
            } catch (e) {
                _try = false
            } finally {
                if (_try) {
                    var _end = getTime();
                }
            }
        },
        10)
    },
    call: function (jobName, args) {
        if (typeof this._registedJobTable[jobName] != "undefined") {
            this._registedJobTable[jobName].apply(this, args)
        } else {
        }
    }
};
$registJob = function (name, rel) {
    Jobs.prototype._registJob(name, rel)
};
$callJob = function (name) {
    var args = [];
    if (arguments.length > 1) {
        Core.Array.foreach(arguments,
        function (v, i) {
            args[i] = v
        });
        args.shift()
    }
    Jobs.prototype.call(name, args)
};
if (typeof App == "undefined") {
    var App = {}
}


Dae.pkg("Core.Events");
Core.Events.addEvent = function (elm, func, evType, useCapture) {
    var _el = $E(elm);
    if (_el == null) {
        //$Debug("addEvent 找不到对象：" + elm);
        return
    }
    if (typeof useCapture == "undefined") {
        useCapture = false
    }
    if (typeof evType == "undefined") {
        evType = "click"
    }
    if (_el.addEventListener) {
        _el.addEventListener(evType, func, useCapture);
        return true
    } else {
        if (_el.attachEvent) {
            var r = _el.attachEvent("on" + evType, func);
            return true
        } else {
            _el["on" + evType] = func
        }
    }
};
Core.Events.removeEvent = function (oElement, fHandler, sName) {
    var _el = $E(oElement);
    if (_el == null) {
        //$Debug("removeEvent 找不到对象：" + oElement);
        return
    }
    if (typeof fHandler != "function") {
        return
    }
    if (typeof sName == "undefined") {
        sName = "click"
    }
    if (_el.addEventListener) {
        _el.removeEventListener(sName, fHandler, false)
    } else {
        if (_el.attachEvent) {
            _el.detachEvent("on" + sName, fHandler)
        }
    }
    fHandler[sName] = null
};
Core.Events.getEvent = function () {
    return window.event
};
Core.Events.stopEvent = function (el) {
    var ev = el ? el : Core.Events.getEvent();
    ev.cancelBubble = true;
    ev.returnValue = false
};
if (!$IE) {
    Core.Events.stopEvent = function (el) {
        var ev = el ? el : Core.Events.getEvent();
        ev.preventDefault();
        ev.stopPropagation()
    }
}
Core.Events.fixEvent = function (e) {
    if (typeof e == "undefined") {
        e = window.event
    }
    if (!e.target) {
        e.target = e.srcElement;
        e.pageX = e.x;
        e.pageY = e.y
    }
    if (typeof e.layerX == "undefined") {
        e.layerX = e.offsetX
    }
    if (typeof e.layerY == "undefined") {
        e.layerY = e.offsetY
    }
    return e
};
Dae.pkg("Core.Dom");
Core.Dom.opacity = function (elm, value) {
    elm = $E(elm);
    elm.style.filter = "alpha(opacity=" + value + ")";
    elm.style.opacity = value / 100
};
Core.Dom.getElementsByClass = function (el, tg, clz) {
    el = el || document;
    var rs = [];
    clz = " " + clz + " ";
    var cldr = el.getElementsByTagName(tg),
    len = cldr.length;
    for (var i = 0; i < len; ++i) {
        var o = cldr[i];
        if (o.nodeType == 1) {
            var ecl = " " + o.className + " ";
            if (ecl.indexOf(clz) != -1) {
                rs[rs.length] = o
            }
        }
    }
    return rs
};
Core.Dom.byClz = Core.Dom.getElementsByClass;

Core.Dom.getStyle = function (el, property) {
    switch (property) {
        case "opacity":
            var val = 100;
            try {
                val = el.filters["DXImageTransform.Microsoft.Alpha"].opacity
            } catch (e) {
                try {
                    val = el.filters("alpha").opacity
                } catch (e) { }
            }
            return val / 100;
        case "float":
            property = "styleFloat";
        default:
            var value = el.currentStyle ? el.currentStyle[property] : null;
            return (el.style[property] || value)
    }
};


App.timer = new 
function () {
    this.list = {};
    this.refNum = 0;
    this.clock = null;
    this.allpause = false;
    this.delay = 25;
    this.add = function (fun) {
        if (typeof fun != "function") {
            throw ("The timer needs add a function as a parameters")
        }
        var key = "" + (new Date()).getTime() + (Math.random()) * Math.pow(10, 17);
        this.list[key] = {
            fun: fun,
            pause: false
        };
        if (this.refNum <= 0) {
            this.start()
        }
        this.refNum++;
        return key
    };
    this.remove = function (key) {
        if (this.list[key]) {
            delete this.list[key];
            this.refNum--
        }
        if (this.refNum <= 0) {
            this.stop()
        }
    };
    this.pause = function (key) {
        if (this.list[key]) {
            this.list[key]["pause"] = true
        }
    };
    this.play = function (key) {
        if (this.list[key]) {
            this.list[key]["pause"] = false
        }
    };
    this.stop = function () {
        clearInterval(this.clock);
        this.clock = null
    };
    this.start = function () {
        var _this = this;
        this.clock = setInterval(function () {
            _this.loop.apply(_this)
        },
        this.delay)
    };
    this.loop = function () {
        for (var k in this.list) {
            if (!this.list[k]["pause"]) {
                this.list[k]["fun"]()
            }
        }
    }
};
App.animation = {
    vibrate: function (d, v, m, k, s, u) {
        var T = 2 * Math.PI * Math.sqrt(m / k);
        var A = v * Math.sqrt(m / k);
        var n = Math.ceil(T * 100 / d);
        var c = 0;
        var orbit = [];
        while (A > s) {
            orbit.push(A * Math.sin((c / n) * 2 * Math.PI));
            c++;
            c = c % n;
            A = A - u
        }
        return orbit
    },
    accelerate: function (d, h, g, v) {
        var orbit = [];
        var l = 0;
        while (true) {
            var v1 = v;
            v = v1 + d * g / 10;
            l = l + d * (v + v1) / 20;
            if (l < h) {
                orbit.push(l)
            } else {
                break
            }
        }
        return orbit
    },
    curtain: function (d, h, p) {
        var orbit = [h];
        var l = h;
        while (l > 1) {
            l = l * p;
            orbit.unshift(l)
        }
        return orbit
    },
    speed: function (d, h, v) {
        var t = Math.ceil(h / v);
        var n = Math.ceil(t * 100 / d);
        var orbit = [];
        for (var i = 0; i < n; i++) {
            orbit.push((i + 1) * h / n)
        }
        return orbit
    },
    circle: function (d, l, v) {
        var t = 2 * Math.PI * l / v;
        var n = Math.ceil(t * 100 / d);
        var orbit = [];
        for (var i = 0; i < n; i++) {
            orbit.push({
                x: l * Math.sin(((i + 1) / n) * 2 * Math.PI),
                y: l * Math.cos(((i + 1) / n) * 2 * Math.PI)
            })
        }
        return orbit
    },
    taccelerate: function (d, h, t) {
        var n = Math.ceil(t * 100 / d);
        var orbit = [];
        for (var i = 0; i < n; i++) {
            orbit.push(Math.pow((i + 1) / n, 2) * h)
        }
        return orbit
    }
};


(function (proxy) {
    proxy.setOpacity = function (element, value) {
        element.style.filter = "alpha(opacity=" + value + ")";
        element.style.opacity = value / 100
    };
    proxy.opacity = function (element, cfg, callback) {
        var _first = cfg.first;
        var _last = cfg.last || 0;
        if (_last == _first) {
            proxy.setOpacity(element, _first);
            if (typeof callback === "function") {
                callback(_first, _last)
            }
            return false
        }
        var _time = Math.floor((cfg.time || 5) * 100 / proxy.timer.delay);
        var _orbit = [];
        for (var i = 0; i < _time; i++) {
            _orbit.push(_first + (_last - _first) * i / _time)
        }
        var _current = 0;
        var _timerhook = proxy.timer.add(function () {
            if (_current >= _orbit.length) {
                proxy.timer.remove(_timerhook);
                proxy.setOpacity(element, _last);
                if (typeof callback === "function") {
                    callback(_first, _last)
                }
                return false
            }
            proxy.setOpacity(element, _orbit[_current]);
            _current++
        })
    }
})(App);


Core.Dom.domInsert = function (pnode, param, pos, callback) {
    pos = /^(afterBegin|afterEnd|beforeBegin|beforeEnd)$/.test(pos) ? pos : "beforeEnd";
    callback = (typeof callback == "function" ? callback : function () { });
    var args = arguments;
    if ($IE) {
        var ctype = "HTML";
        if (typeof param == "object") {
            if (param.nodeType == 1) {
                ctype = "Element"
            } else {
                if (param.nodeType == 3) {
                    ctype = "Text";
                    param = param.data
                } else {
                    ctype = "HTML"
                }
            }
        } (function () {
            try {
                pnode.doScroll("left");
                pnode["insertAdjacent" + ctype](pos, param);
                callback.call(args.caller);
                callback = param = null
            } catch (e) {
                window.setTimeout(arguments.callee, 0)
            }
        })()
    } else {
        if (typeof param == "object" && /^(1|3)$/.test(param.nodeType)) {
            switch (pos) {
                case "afterBegin":
                    pnode.insertBefore(param, pnode.firstChild);
                    break;
                case "afterEnd":
                    if (pnode.parentNode.nodeType == 1) {
                        pnode.parentNode.insertBefore(param, pnode.nextSibling)
                    }
                    break;
                case "beforeBegin":
                    if (pnode.parentNode.nodeType == 1) {
                        pnode.parentNode.insertBefore(param, pnode)
                    }
                    break;
                case "beforeEnd":
                    pnode.appendChild(param);
                    break
            }
        } else {
            var tmp = document.createElement("div");
            tmp.innerHTML = param;
            switch (pos) {
                case "afterBegin":
                    while (tmp.lastChild) {
                        pnode.insertBefore(tmp.lastChild, pnode.firstChild)
                    }
                    break;
                case "afterEnd":
                    if (pnode.parentNode.nodeType == 1) {
                        while (tmp.lastChild) {
                            pnode.parentNode.insertBefore(tmp.lastChild, pnode.nextSibling)
                        }
                    }
                    break;
                case "beforeBegin":
                    if (pnode.parentNode.nodeType == 1) {
                        while (tmp.firstChild) {
                            pnode.parentNode.insertBefore(tmp.firstChild, pnode)
                        }
                    }
                    break;
                case "beforeEnd":
                    while (tmp.firstChild) {
                        pnode.appendChild(tmp.firstChild)
                    }
                    break
            }
            tmp = null
        }
        callback.call(args.caller)
    }
};

(function (proxy) {
    proxy.insmarquee = function (pulley, list, cfg) {
        var that = {
            hooker: null,
            list: list,
            sttimeout: cfg.sttimeout
        };
        var insorbit = [];
        var hooker = null;
        var current = 0;
        var showing = 0;
        var scroll = 0;
        var parent = that.list[0].parentNode;
        var st;
        var ele;
        if (cfg === undefined) {
            cfg = {}
        }
        var speed = cfg.speed || 5;
        var forward = cfg.forward || "left";
        var orbitk = 2;
        var getinsOrbit = function (distance) {
            return proxy.animation.speed(proxy.timer.delay * orbitk, distance, speed)
        };
        var finishOne = function () { };
        var moveOne = function () { };
        var looping = function () { };
        pulley.style.overflow = "hidden";
        var isIns = false;
        if (forward === "up") {
            scroll = pulley.scrollTop;
            insorbit = getinsOrbit(that.list[0].offsetHeight);
            finishOne = function (itemNum) {
                parent.removeChild(that.list[itemNum]);
                parent.appendChild(that.list[itemNum])
            };
            moveOne = function (itemNum) {
                insorbit = getinsOrbit(that.list[itemNum].offsetHeight)
            };
            looping = function (step) {
                pulley.scrollTop = scroll + insorbit[step]
            }
        } else {
            if (forward === "down") {
                scroll = pulley.scrollTop;
                insorbit = getinsOrbit(that.list[that.list.length - 1].offsetHeight);
                finishOne = function (itemNum) {
                    that.pause("opacity");
                    isIns = false;
                    that.list[that.list.length - 1 - itemNum].style.backgroundColor = "#fff";
                    proxy.opacity(that.list[that.list.length - 1 - itemNum], {
                        first: 0,
                        last: 100,
                        time: Math.ceil(that.list[that.list.length - 1 - itemNum].offsetHeight / speed / 4)
                    },
                    function () {
                        clearTimeout(st);
                        st = setTimeout(function () {
                            if (!that.hooker || that.hooker == "parse") {
                                return false
                            }
                            that.restart()
                        },
                        that.sttimeout || 3000)
                    })
                };
                moveOne = function (itemNum) {
                    insorbit = getinsOrbit(that.list[that.list.length - 1 - itemNum].offsetHeight)
                };
                looping = function (step, itemNum) {
                    if (!isIns) {
                        try{
                        parent.removeChild(that.list[that.list.length - 1 - itemNum]);
                        proxy.setOpacity(that.list[that.list.length - 1 - itemNum], "0");
                        that.list[that.list.length - 1 - itemNum].style.height = "0px";
                        that.list[that.list.length - 1 - itemNum].style.overflow = "hidden";
                        Core.Dom.domInsert(parent, that.list[that.list.length - 1 - itemNum], "afterBegin")
                        }catch(ex){that.restart()}
                    }
                    isIns = true;
                    try{
                    that.list[that.list.length - 1 - itemNum].style.height = insorbit[step] + "px";
                    }catch(ex){}
                }
            } else {
                if (forward === "right") { } else {
                    if (forward === "left") {
                        scroll = pulley.scrollLeft;
                        insorbit = getinsOrbit(that.list[0].offsetWidth);
                        finishOne = function (itemNum) {
                            parent.removeChild(that.list[itemNum]);
                            parent.appendChild(that.list[itemNum])
                        };
                        moveOne = function (itemNum) {
                            insorbit = getinsOrbit(that.list[itemNum].offsetWidth - parseInt(Core.Dom.getStyle(that.list[that.list.length - 1], "paddingTop")))
                        };
                        looping = function (step) { }
                    } else {
                        if (forward == "insertDown") {
                            pulley.style.overflow = "visible";
                            ele = that.list.shift();
                            insorbit = getinsOrbit(ele.offsetHeight);
                            finishOne = function (itemNum) {
                                that.pause("opacity");
                                isIns = false;
                                if (ele && ele.style) {
                                    ele.style.height = "auto";
                                    ele.style.backgroundColor = "#fff";
                                    proxy.opacity(ele, {
                                        first: 0,
                                        last: 100,
                                        time: 1
                                    },
                                    function () {
                                        clearTimeout(st);
                                        st = setTimeout(function () {
                                            if (typeof that.afterRoll === "function") {
                                                that.afterRoll()
                                            }
                                            that.rollDone = true;
                                            if (that.list.length == 0 || !that.hooker || that.liveStop == true || that.hooker == "pause") {
                                                return false
                                            }
                                            that.restart();
                                            ele = that.list.shift()
                                        },
                                        that.sttimeout || 2500)
                                    })
                                }
                            };
                            moveOne = function (itemNum) {
                                if (typeof cfg.afterIns === "function") {
                                    cfg.afterIns(ele)
                                }
                            };
                            looping = function (step, itemNum) {
                                if (!isIns) {
                                    if (!ele) {
                                        return false
                                    }
                                    insorbit = getinsOrbit(ele.offsetHeight);
                                    proxy.setOpacity(ele, "0");
                                    ele.style.height = "0px";
                                    ele.style.overflow = "hidden";
                                    Core.Dom.domInsert(pulley, ele, "afterBegin",
                                    function () {
                                        that.rollDone = false
                                    })
                                }
                                isIns = true;
                                ele.style.height = insorbit[step] + "px"
                            }
                        }
                    }
                }
            }
        }
        that.start = function () {
            hooker = proxy.timer.add(function () {
                looping(current, showing);
                current += 1;
                if (current >= insorbit.length) {
                    finishOne(showing);
                    showing += 1;
                    showing %= that.list.length;
                    moveOne(showing);
                    current = 0
                }
            });
            that.hooker = hooker
        };
        that.stop = function () {
            proxy.timer.remove(hooker);
            that.hooker = null
        };
        that.pause = function (str) {
            proxy.timer.pause(hooker);
            that.hooker = str || "parse"
        };
        that.restart = function () {
            proxy.timer.play(hooker);
            that.hooker = hooker
        };
        that.setList = function (arr, act) {
            if (act === "reset" || that.list.length == 0) {
                that.list = [];
                for (var k = 0; k < arr.length; k++) {
                    that.list.push(arr[k])
                }
                clearTimeout(st);
                ele = that.list.shift();
                that.setLivePlay()
            } else {
                that.list = that.list.concat(arr)
            }
        };
        that.getList = function () {
            return that.list
        };
        that.setLiveStop = function (fun) {
            that.liveStop = true;
            if (typeof fun == "function") {
                fun()
            }
        };
        that.getLiveStop = function () {
            return that.liveStop
        };
        that.setLivePlay = function () {
            proxy.timer.play(hooker);
            that.hooker = hooker;
            that.liveStop = false
        };
        return that
    }
})(App);
$registJob("marquee",
function () {
    var marqueeBox = $E("txtBoxCon").parentNode;
    var divs = marqueeBox.getElementsByTagName("div");
    var items = [];
    for (var i = 0,
    len = divs.length; i < len; i += 1) {
        if (divs[i].className === "itemt") {
            items.push(divs[i])
        }
    }
    //App.bindMedia($E("txtBoxCon"));
    var ss = setTimeout(function () {
        var doMarquee = new App.insmarquee(marqueeBox, items, {
            forward: "down",
            speed: 5
        });
        Core.Events.addEvent(marqueeBox,
        function () {
            doMarquee.pause()
        },
        "mouseover");
        Core.Events.addEvent(marqueeBox,
        function () {
            doMarquee.restart()
        },
        "mouseout");
        doMarquee.start();
        clearTimeout(ss)
    },
    500)
});
function main() {
    var jobs = new Jobs();
    jobs.add("marquee");
    jobs.start()
};
