/** menuswap.js
 * --------------------------------------------------
 *  说明：
 *      移动交换式菜单处理，需配合样式定义使用。
 *
 *  构造参数：
 *      @beg: 首先显示的菜单项 ID
 *      @currName: 当前项的样式 class 名
 *      @linkName: 其它项的样式 class 名
 *      @firstName: 首项的样式 class 名
 *      @_curr: 当前显示项
 *      @_first: 首项元素
 *
 *  @Tubz. 2009.3.23.
 * --------------------------------------------------
 */

function MenuSwap(currName, linkName, firstName)
{
    this._currName = currName;
    this._linkName = linkName;
    this._firstName = firstName;
    this._curr = null;
    this._first = null;
}

MenuSwap.prototype.show = function(node)
{
    if (!this._curr) this._curr = node;
    // 覆盖首项样式
    this._first.className = this._linkName;
    this._curr.className = this._linkName;
    node.className = this._currName;

    this._curr = node;
}

MenuSwap.prototype.reset = function(node)
{
    node.className = this._linkName;
    // 恢复首项样式
    this._first.className = this._firstName;

    this._curr = node;
}

MenuSwap.prototype.first = function(id)
{
    var e = document.getElementById(id);
    // 设置首项
    e.className = this._firstName;
    this._first = e;
}


/**
 * 标签切换类
 * 同时在容器区插入相应内容。
 *
 * @param currName 当前项的样式 class 名
 * @param linkName 其它项的样式 class 名
 * @param boxID 内容显示区 ID
 */
function TabSwap(currName, linkName, boxID)
{
    this._currName = currName;
    this._linkName = linkName;
    this._curr = null;
    this._box = document.getElementById(boxID);
}

/**
 * @param node 当前 Tab 元素
 * @param id 当前需要显示的内容的容器 ID
 */
TabSwap.prototype.show = function(node, id)
{
    if (!this._curr) this._curr = node;

    this._curr.className = this._linkName;
    node.className = this._currName;
    this._curr = node;

    this._box.innerHTML = document.getElementById(id).innerHTML;
}

TabSwap.prototype.first = function(nodeid, bid)
{
    var e = document.getElementById(nodeid);
    this.show(e, bid);
}
