﻿// JScript File


function focus(id){
	if(id == 0){ 
		return; 
	} else {
		document.getElementById(id).focus();
	}
	return;
}

//expand menu item and collapse all others
function expandMenu(id){
	var el = document.getElementById("div_"+id);
	var el_class = document.getElementsByClassName(el.className);
	
	if(el.style.display == "none"){
		for(var i=0; i<el_class.length; i++){
			if(el_class[i] == el){
				toggleDisplay(el,true);
			} else {
				toggleDisplay(el_class[i],false);
			}
		}
	}
}

//displays and hides "element" depending on "bool" value of true or false
function toggleDisplay(element, bool){
	if(bool){
		element.style.display = "";
	} else {
		element.style.display = "none";
	}
}

function slideEffect(id){
    var obj = document.getElementById(id);
    if(obj) {
        if(obj.style.display == "none")
        {
            for(var d = 0; d < obj.parentNode.parentNode.parentNode.getElementsByTagName('div').length; d++)
            {
                if(obj.parentNode.parentNode.parentNode.getElementsByTagName('div')[d].style.display == "")
                {
                    Effect.toggle(obj.parentNode.parentNode.parentNode.getElementsByTagName('div')[d].id, 'slide');
                }
            }
            Effect.toggle(id, 'slide');
        }
    }
}

function $bk() {
    this.getMenuVars();
    this.initMenu(this.submenucollection, this.linkmenucollection, false);
    this.initMenu(this.submenucollection, this.linkmenucollection, true);
    this.normalizeTable();
}

$bk.prototype.normalizeTable = function() {
    if(this.obj('content').getElementsByTagName('div')[0]) {
        if(this.obj('content').getElementsByTagName('div')[0].offsetHeight < 300) {
            this.obj('content').getElementsByTagName('div')[0].style.height = '300px'; 
        }
    }
    if(this.obj('bg_boardlist')) {
        var links = this.obj('bg_boardlist').getElementsByTagName('a');
        for(var a = 0; a < links.length;a++) {
            if(links[a].innerHTML.length == 0) {
                links[a].innerHTML = '* no name provided';
            }
        }
    }
}

$bk.prototype.submenucollection = new Array();
$bk.prototype.linkmenucollection = new Array();

$bk.prototype.obj = function(obj) {
    var type = typeof(obj);
    switch (type) {
        case "object":
            return obj;
            break;
        case "string":
            return document.getElementById(obj);
            break;
    }
}

$bk.prototype.getMenuVars = function() {
    var divSubLinks = this.obj('divSubLinks');
    var divSubLinksCollection = divSubLinks.getElementsByTagName('div');
    for(var i = 0; i < divSubLinksCollection.length; i++) {
        this.submenucollection.push(divSubLinksCollection[i].id)
    }
    var divMainLinks = this.obj('divMainLinks');
    var divMainLinksCollection = divMainLinks.getElementsByTagName('a');
    for(var i = 0; i < divMainLinksCollection.length; i++) {
        this.linkmenucollection.push(divMainLinksCollection[i].id)
    }
}

$bk.prototype.isMSIE = function() {
    if(document.all) {
        return true;
    }
    else {
        return false;
    }
}

$bk.prototype.currentMenu = function(link, links) {
    this.initMenu(this.submenucollection, this.linkmenucollection);
    link.onmouseover = function() {
        return false;
    }
}

$bk.prototype.pageCollection = function() {
    var pages = new Array();
    pages.push('bg_register-0');
    pages.push('bg_join-0');
    pages.push('bg_location-0');
    pages.push('bg_weare-0');
    pages.push('bg_faq-0');
    pages.push('bg_links-0');
    pages.push('bg_history-0');
    pages.push('bg_wordofgod-1');
    pages.push('bg_board-1');
    pages.push('bg_bibletext-1');
    pages.push('bg_gospel-1');
    pages.push('bg_bibleinfo-1');
    pages.push('bg_life-2');
    pages.push('bg_schedule-2');
    pages.push('bg_news-2');
    pages.push('bg_currentgroup-2');
    pages.push('bg_boardlist-2');
    pages.push('bg_rosary-3');
    pages.push('bg_stations-3');
    pages.push('bg_roster-3');
    pages.push('bg_servants-4');
    pages.push('bg_accountinfo');
    pages.push('bg_enote');
    pages.push('bg_help');
    pages.push('bg_message');
    return pages;
}

$bk.prototype.initMenu = function(menu, links, instance) {
    if(!instance) {
        if(menu.length > 0 && links.length > 0) {
            for(var i = 0; i < links.length; i++) {
                this.obj(links[i]).setAttribute('name', 'link_' + i)
                this.obj(links[i]).onmouseover = function() {
                   var index = this.name.split('link_')[1];
                   $bk.currentMenu(this, links);
                   for(var m = 0; m < menu.length; m++) {
                        $bk.obj(menu[m]).style.display = 'none';
                   }
                   Effect.Appear($bk.obj(menu[index]));
                }
            }
        }
    }
    else {
        for(var p = 0; p < this.pageCollection().length; p++) {
            if(this.obj(this.pageCollection()[p].split('-')[0]) && this.pageCollection()[p].split('-')[1]) {
                this.currentMenu(this.obj(links[this.pageCollection()[p].split('-')[1]]), links);
                for(var m = 0; m < menu.length; m++) {
                    this.obj(menu[m]).style.display = 'none';
                }
                Effect.Appear(this.obj(menu[this.pageCollection()[p].split('-')[1]]));
            }
        }
    }
}

window.onload = function() {
    $bk = new $bk();
}
