/**
* 選單收合
* @author JASON WANG, LANECHANG HONG
* @class 
*/
var MenuList = {

    _mm: null,

    _sm: null,

    currUnit: null,

    smNum: 0,

    isclick: false,

    box_title_in: function(_element) {
        _element.getElementsByTagName('div')[0].className = 'box_title_over';
        _element.getElementsByTagName('div')[0].getElementsByTagName('div')[0].className = 'box_title_txt_over';
    },

    box_title_out: function(_element) {
        if (_element.parentNode.id != this.currUnit) {
            _element.getElementsByTagName('div')[0].className = 'box_title';
            _element.getElementsByTagName('div')[0].getElementsByTagName('div')[0].className = '';
        }
    },

    docGetElementsByClassName: function(_className) {
        var _resultArr = new Array();
        var _allArr = document.getElementsByTagName('*');

        try {
            for (var i = 0; i < _allArr.length; i++) {
                if (_allArr[i].className == _className) {
                    _resultArr[_resultArr.length] = _allArr[i];
                }
            }
            return _resultArr;
        }
        catch (e) {
            return null;
        }
        finally {
            _resultArr = null;
            _allArr = null;
            delete _resultArr;
            delete _allArr;
        }
    },

    click2focus: function(_element, _evt) {
        _element.focus();
        (_evt.type == 'click') ? this.isclick = true : this.isclick = false;
    },

    box_toggle_expand: function(_element) {
        var _elmt = _element;
        var i = 1;
        var collection = document.getElementsByTagName('div');
        var tmpId = '';
        try {
            if (_element.href.indexOf('#') == -1 && this.isclick == true) {
                document.location = _element.href;
                throw new Error();
            }

            this.isclick = false;
            this.currUnit = _elmt.parentNode.id;
            if (_elmt.parentNode.className == 'box') {

                for (i = 1; i <= collection.length; i++) {
                    if (collection[i - 1].id.substring(0, 4) == 'box_' || collection[i - 1].id.substring(0, 3) != 'box') continue;
                    tmpId = collection[i - 1].id.replace('box', '');
                    if (collection[i - 1].id == this.currUnit) {
                        collection[i - 1].className = 'box_expand';
                        collection[i - 1].getElementsByTagName('div')[0].className = 'box_title_over';
                        collection[i - 1].getElementsByTagName('div')[0].getElementsByTagName('div')[0].className = 'box_title_txt_over';

                        if (document.getElementById('box_content' + tmpId) != null) document.getElementById('box_content' + tmpId).style.display = 'block';

                    }
                    else {
                        collection[i - 1].className = 'box';
                        collection[i - 1].getElementsByTagName('div')[0].className = 'box_title';
                        collection[i - 1].getElementsByTagName('div')[0].getElementsByTagName('div')[0].className = '';
                        if (document.getElementById('box_content' + tmpId) != null) document.getElementById('box_content' + tmpId).style.display = 'none';
                    }
                    tmpId = null;
                }
            }
            else {
                _elmt.parentNode.className = 'box';

                if (document.getElementById('box_content' + _elmt.parentNode.id.substr(_elmt.parentNode.id.length - 1, 1)) != null)
                    document.getElementById('box_content' + _elmt.parentNode.id.substr(_elmt.parentNode.id.length - 1, 1)).style.display = 'none';
            }
        }
        catch (e) {
            return;
        }
        finally {
            _elmt = null;
            i = null;
            collection = null;
            tmpId = null;
            delete collection;
            delete tmpId;
            delete i;
            delete _elmt;
        }
    },

    getParam: function(_paramStr) {
        var v = {
            _href: document.location.href,
            _qStr: null,
            _obj: null,
            _valueParamArr: null,
            i: 0
        }

        try {
            v._qStr = v._href.split('?')[1];
            if (v._qStr == null) throw new Error();
            v._obj = new Object();
            v._valueParamArr = v._qStr.split('&');
            for (v.i = 0; v.i < v._valueParamArr.length; v.i++) {
                v._obj[v._valueParamArr[v.i].split('=')[0]] = v._valueParamArr[v.i].split('=')[1];
            }

            if (v._obj[_paramStr] == null || v._obj[_paramStr] == undefined) throw new Error();
            return v._obj[_paramStr];
        }
        catch (e) {
            return ''
        }
        finally {
            v = null;
            delete v;
        }
    },

    highlightCurrUnit: function() {
        this.smNum = this.docGetElementsByClassName('box').length;
        this._mm = this.getParam('mm');
        this._sm = this.getParam('sm');

        try {
            if (this._mm != '') {
                this.currUnit = 'box' + this._mm;
                document.getElementById(this.currUnit).className = 'box_expand';
                if (document.getElementById('box_content' + this._mm) != null) document.getElementById('box_content' + this._mm).style.display = 'block';
                document.getElementById(this.currUnit).getElementsByTagName('div')[0].className = 'box_title_over';
                document.getElementById(this.currUnit).getElementsByTagName('div')[0].getElementsByTagName('div')[0].className = 'box_title_txt_over';

                if (this._sm != '') {
                    document.getElementById(this.currUnit).getElementsByTagName('a')[this._sm].style.color = '#ffffff';
                    document.getElementById(this.currUnit).getElementsByTagName('a')[this._sm].style.backgroundColor = '#34a7b7';
                }
            }
        }
        catch (e) {
            return;
        }
    },

    init: function() {
        var collection = document.getElementsByTagName('div');
        var i = 1;
        if (collection.length == 0) return;
        for (i = 1; i <= collection.length; i++) {
            if (collection[i - 1].id.indexOf('box_content') != -1) {
                collection[i - 1].style.display = 'none';
            }
        }
    }
};


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

