﻿var newsTab = {
    category: null,
    imgOver: [
        ['/images/zhTW/images/ta02ov_37.jpg', '/images/zhTW/images/ta02ov_38.jpg', '/images/zhTW/images/ta02ov_39.jpg', '/images/zhTW/images/ta02ov_40.jpg'],
        ['/images/zhTW/images/ta03ov_37.jpg', '/images/zhTW/images/ta03ov_38.jpg', '/images/zhTW/images/ta03ov_39.jpg', '/images/zhTW/images/ta03ov_40.jpg'],
        ['/images/zhTW/images/ta04ov_37.jpg', '/images/zhTW/images/ta04ov_39.jpg', '/images/zhTW/images/ta04ov_38.jpg', '/images/zhTW/images/ta04ov_40.jpg']
    ],
    img: [
        ['/images/zhTW/images/ta02_37.jpg', '/images/zhTW/images/ta02_38.jpg', '/images/zhTW/images/ta02_39.jpg', '/images/zhTW/images/ta02_40.jpg'],
        ['/images/zhTW/images/ta03_37.jpg', '/images/zhTW/images/ta03_38.jpg', '/images/zhTW/images/ta03_39.jpg', '/images/zhTW/images/ta03_40.jpg'],
        ['/images/zhTW/images/ta04_37.jpg', '/images/zhTW/images/ta04_39.jpg', '/images/zhTW/images/ta04_38.jpg', '/images/zhTW/images/ta04_40.jpg']
    ],

    /**
    * 初始化
    */
    onLoad: function(cgy) {
        var list = null;
        var more = null;
        var tab = null;
        var btn = null;
        var anr = null;
        try {
            if (cgy == undefined || cgy == null) throw new Error();
            //搜尋頁籤
            for (var i = 0; i <= 4; i++) {
                //當頁籤不為總頁籤則關閉隱藏
                if (i != 0) {
                    list = document.getElementById('newsList' + i.toString());
                    if (list != undefined && list != null) {
                        list.style.visibility = 'hidden';
                        list.style.display = 'none';
                    }

                    more = document.getElementById('more' + i.toString());
                    if (more != undefined && more != null) {
                        more.style.visibility = 'hidden';
                        more.style.display = 'none';
                    }
                }

                //更改頁籤超連結屬性
                tab = document.getElementById('newsTab' + i.toString());
                if (tab != undefined && tab != null) {
                    tab.href = 'javascript:newsTab.changeTab(\'newsTab' + i.toString() + '\');';
                }

                //更改按鈕狀態
                btn = document.getElementById('newsBt0');
                if (btn != undefined && btn != null) {
                    this.category = cgy - 1;
                    btn.src = this.imgOver[cgy - 1][0];
                }

                //隱藏瞄點
                anr = document.getElementById('newsAhr' + i.toString());
                if (anr != undefined && anr != null) {
                    anr.style.visibility = 'hidden';
                    anr.style.display = 'none';
                }
            }
        }
        catch (e) {
            return;
        }
        finally {
            list = null;
            tab = null;
            btn = null;
        }
    },

    /**
    * 切換頁籤
    * @param {string} tabID  -頁籤編號
    */
    changeTab: function(tabID) {
        var id = null;
        var el = null;
        var i = null;
        var j = null;
        var elName = ['newsList', 'more', 'newsBt'];
        try {
            if (tabID == undefined || tabID == null || tabID == '') throw new Error();
            id = parseInt(tabID.replace('newsTab', ''));
            if (id == null) throw new Error();

            for (i = 0; i <= 3; i++) {
                if (id == i) {
                    for (j = 0; j <= 2; j++) {
                        el = document.getElementById((elName[j] + i.toString()));
                        if (el != undefined && el != null) {
                            if (j == 2) el.src = this.imgOver[newsTab.category][i];
                            else {
                                el.style.visibility = 'visible';
                                el.style.display = '';
                            }
                        }
                    }
                }
                else {
                    for (j = 0; j <= 2; j++) {
                        el = document.getElementById((elName[j] + i.toString()));
                        if (el != undefined && el != null) {
                            if (j == 2) el.src = this.img[newsTab.category][i];
                            else {
                                el.style.visibility = 'hidden';
                                el.style.display = 'none';
                            }
                        }
                    }
                }
            }
        }
        catch (e) {
            return;
        }
        finally {
            id = null;
            el = null;
            elName = null;
            i = null;
            j = null;
        }
    }
};
