﻿var TabMenu = new Object();
TabMenu = {
    isAutomatic: false,
    $: function(v)
    {
        return document.getElementById(v)
    }, getEles: function(id, ele)
    {
        return this.$(id).getElementsByTagName(ele);
    },
    sideTab:
   {
       heads: 'tabTit', heads_ele: 'span', bodys: 'tabBody', bodys_ele: 'ol'
   },
    headsClassName:
   {
       active: 'select', normal: ''
   },
    bodysClassName:
   {
       active: 'block', normal: 'none'
   },
    TabChang: function()
    {
        var eles = this.getEles(this.sideTab.heads, this.sideTab.heads_ele);
        var body = this.getEles(this.sideTab.bodys, this.sideTab.bodys_ele);
        for (var i = 0; i < eles.length; i++)
        {
            (function()
            {
                var p = i;
                eles[p].onmouseover = function()
                {
                    TabMenu._TabChang(p, body, eles);
                }
            }
         )();
        }
    },
    _TabChang: function(n, body, obj)
    {
        for (var i = 0; i < body.length; i++)
        {
            if (i == n)
            {
                body[n].className = this.bodysClassName.active;
                obj[n].className = this.headsClassName.active;
            }
            else
            {
                body[i].className = this.bodysClassName.normal;
                obj[i].className = this.headsClassName.normal;
            }
        }
    }
}
/*
-------------------------
tag切换
-------------------------
*/
function tagMenu(menuId, contentId, isAutomatic)
{
    var menu = document.getElementById(menuId);
    var content = document.getElementById(contentId);
    var time = 2000;
    var Interval = null;
    var n = 0;


    var list = menu.firstChild.cells;
    var contentList = content.childNodes;

    if (list.length > 0 && contentList.length == list.length)
    {
        list[0].className = "active";
        contentList[0].className = "active";
        for (var i = 0; i < list.length; i++)
        {
            list[i].onmouseover = function()
            {
                setTagMenu(this, list, contentList);
                if (isAutomatic)
                {
                    window.clearInterval(Interval);
                }
            }

            if (isAutomatic)
            {
                list[i].onmouseout = function()
                {
                    Interval = window.setInterval(automatic, time);
                }
                contentList[i].onmouseout = function()
                {
                    Interval = window.setInterval(automatic, time);
                }
                contentList[i].onmouseover = function()
                {
                    window.clearInterval(Interval);
                }
            }
            list[i].setAttribute("id", i);
            contentList[i].setAttribute("id", i);

        }
    }

    function setTagMenu(othis, list, contentList)
    {
        for (var i = 0; i < list.length; i++)
        {
            if (list[i].id == othis.id)
            {
                list[i].className = "active";
            }
            else
            {
                list[i].className = "normal";
            }
        }

        for (var j = 0; j < contentList.length; j++)
        {
            if (contentList[j].id == othis.id)
            {
                contentList[j].className = "active";
            }
            else
            {
                contentList[j].className = "normal";
            }
        }
    }

    if (isAutomatic && list.length > 0 && contentList.length == list.length)
    {
        Interval = window.setInterval(automatic, time);
    }

    function automatic()
    {
        setActive(n);
        n++;
        if (n > (list.length - 1))
        {
            n = 0;
        }
    }
    function setActive(Id)
    {
        for (var i = 0; i < list.length; i++)
        {
            if (Id == i)
            {
                list[i].className = "active";
                contentList[i].className = "active";
            }
            else
            {
                list[i].className = "normal";
                contentList[i].className = "normal";
            }
        }
    }
}
/*
-------------------------
设置列表选择
-------------------------
*/
function setListItemSelect(myDataList)
{
    if (myDataList != null)
    {
        var list = myDataList.cells;

        for (var i = 0; i < list.length; i++)
        {
            list[i].setAttribute("id", i);
            list[i].onclick = function()
            {
                setBg(this);
            }
        }
    }

    function setBg(oThis)
    {
        for (var i = 0; i < list.length; i++)
        {
            if (list[i].getAttribute("id") == oThis.id)
            {
                list[i].className = "active";
            }
            else
            {
                list[i].className = "normal";
            }
        }
    }
}
