﻿
function $(id) { return "string" == typeof id ? document.getElementById(id) : id }
function getCls(obj, tn) {
    var a = new Array();
    var cn = obj.childNodes;
    for (var i = 0; i < cn.length; i++) 
    {
        var c = cn[i]; if (!!c.tagName && c.tagName.toLowerCase() == tn) { a.push(c) } 
    }
    return a};
    var getInfo = function(o) 
    {
    var to = new Object(); to.left = to.right = to.top = to.bottom = 0;
    var twidth = o.offsetWidth; var theight = o.offsetHeight;
    while (o != document.body) 
    {
        try { to.left += o.offsetLeft; to.top += o.offsetTop; o = o.offsetParent }
        catch (e) { break } }
    to.right = to.left + twidth; to.bottom = to.top + theight; return to};
    var CancelBubble = function(e) 
    {
        e = e ? e : window.event;
        if (!!(window.attachEvent && !window.opera)) { e.cancelBubble = true }
        else { e.stopPropagation() } return e
    };
    var CancelSelect = function(e) 
    {
        if (!!(window.attachEvent && !window.opera)) 
    {
        document.onselectstart = function(event) 
        {
        var e = event; e = e ? e : window.event; e.returnValue = false
    }
}
else 
{ document.body.style.MozUserSelect = "none" } };
var UnCancelSelect = function() 
{
    if (!!(window.attachEvent && !window.opera)) 
{
    document.onselectstart = new Function()
}
else { document.body.style.MozUserSelect = "text" } };

//CMHotPic
function CM() {
    var main;
    var moveObjs;
    var menu;
    var lis = new Array();
    var id = 0;
    var moveId = 0;
    var mouseId;
    var timeStart, timeMove;
    var nowMove = false;
    var mOver = false;
    var menuOver = function() {
        if (!!timeStart) clearTimeout(timeStart);
        mouseId = parseInt(this.getAttribute("num"));
        mOver = true; if (!nowMove) { moveId = mouseId; mouseId = -1; move() }
    };
    var menuOut = function() { mOver = false; startMove() };
    var startMove = function() {
        var time = parseInt(moveObjs[id].getAttribute("stopTime"));
        if (time < 3 || isNaN(time)) time = 4; timeStart = setTimeout(move, time * 1000)
    };
    var move = function() 
    {
        nowMove = true;
        if (!mOver) {
            if (id == moveObjs.length - 1) moveId = 0;
            else moveId = id + 1
        }
        moveObjs[id].style.zIndex = 1;
        moveObjs[moveId].style.zIndex = 2;
        moveObjs[moveId].style.left = "258px";
        timeMove = setTimeout(changeLeft, 20);
        lis[id].className = "";
        lis[moveId].className = "on"
    };
    var changeLeft = function() {
        var l = parseInt(moveObjs[moveId].style.left);
        var num = l - l * 0.2; num = num < 1 ? 0 : num; moveObjs[moveId].style.left = num + "px";
        if (num == 0) {
            clearInterval(timeMove); moveObjs[id].style.left = "258px";
            id = moveId; nowMove = false; if (!mOver) { startMove() }
            else { if (mouseId > -1) { moveId = mouseId; mouseId = -1; move() } } 
        }
        else { timeMove = setTimeout(changeLeft, 20) } 
    };
    var init = function() 
    {
        var obj = $("CMHotPic");
        var cn = getCls(obj, "div"); if (cn.length != 2)
            return; 
            main = cn[0];
            menu = cn[1]; 
            moveObjs = getCls(main, "div");
        var uls = menu.getElementsByTagName("ul");
        var ul; 
        if (uls.length > 0) ul = uls[0];
        else return;
        for (var i = 0; i < moveObjs.length; i++) 
        {
            var li = document.createElement("li");
            if (i != 0) { moveObjs[i].style.left = "258px" }
            else 
            {
                moveObjs[i].style.left = "0px";
                li.className = "on"
            } 
            moveObjs[i].style.top = "0px";
            moveObjs[i].style.position = "absolute";
            li.innerHTML = i + 1; li.setAttribute("num", i);
            li.onmouseover = menuOver;
            li.onmouseout = menuOut;
            ul.appendChild(li);
            lis.push(li)
        } startMove()
    };
    init()
}