﻿//Global Variables
var choirFolder = "choir";

//Debug function - comment out the document.write line to remove
function debug(thisMessage) {
    document.write("<p class=debug>Debug message: " + thisMessage + "</p>");
}

function extractPageName(hrefString) {
    var arr = hrefString.split('/');
    return (arr.length < 2) ? hrefString : arr[arr.length - 2].toLowerCase() + arr[arr.length - 1].toLowerCase();
}

function setActiveMenu(arr, crtPage) {
    for (var i = 0; i < arr.length; i++) {
        if (extractPageName(arr[i].href) == crtPage) {
            if (arr[i].parentNode.tagName != "DIV") {
                arr[i].className = "current";
                arr[i].parentNode.className = "current";
            }
        } 
        else {
            if ( ( extractPageName(arr[i].href) == choirFolder+"index.htm") && (crtPage == choirFolder) ) {
               if (arr[i].parentNode.tagName != "DIV") {
                   arr[i].className = "current";
                   arr[i].parentNode.className = "current";
               }
            }
        }
    }
}

function setPage() {
    //Read fontSize from Cookie
    thisSize = parseInt(getCookie("fontSize"));
	if ( (thisSize != null) && (isNaN(thisSize) != true) ) {
        thisObject = document.getElementById("content");
		thisObject.style.fontSize = thisSize + "pt";
    } 
    hrefString = document.location.href ? document.location.href : document.location;
    if (document.getElementById("leftnav") != null)
        setActiveMenu(document.getElementById("leftnav").getElementsByTagName("a"), extractPageName(hrefString));
}

//Text Resizing Functions
function textUp(sizeChange) {
    var oldSize = 0;
    var newSize = 0;
    thisObject = document.getElementById("content");
    if (thisObject.style.fontSize == "") {
        oldSize = 10;
        newSize = oldSize + sizeChange;
    }
    else {
        oldSize = parseInt(thisObject.style.fontSize);
        newSize = oldSize + sizeChange;
    }
    if (newSize < 6) newSize = 6;
    if (sizeChange == 0) newSize = 10;
    setCookie("fontSize", newSize, 7);
    thisObject.style.fontSize = newSize + "pt";
}
//Cookie Functions
function setCookie(c_name, value, expiredays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name + "=" + escape(value) +
((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
}
function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}
function setSubMenu(thisMenu){
	if (thisMenu==""){
		thisMenu="home";
	}
	thisObject = document.getElementById("nav_"+thisMenu);
	thisObject.style.display='';
}

function setCurrentTopNav() {
	var currentURL = window.location;
	var currentFolder = currentURL.pathname.split("/");
	var currentTopNav=currentFolder[1];
	var stringTopNav = "mainworshipmusicsermonslearnvisitshoppeoplelinks";
	if (currentTopNav.length == 0 || currentTopNav.indexOf(".") >=0 || currentTopNav == "events") {
		currentTopNav="main";
	}
	if (currentTopNav == "choir") {
		currentTopNav="music";
	}
	if (stringTopNav.indexOf(currentTopNav) >= 0) {
		thisObject = document.getElementById("topnav_"+currentTopNav);
		thisObject.className="topnavCurrent";
	}
	var doSetCurrentLeftNav = setCurrentLeftNav();
}

function setCurrentLeftNav(){
    var nav = document.getElementById("leftnav");
    var a = nav.getElementsByTagName("A");
    for(var i=0;i<a.length;i++) if(a[i].href == window.location.href.split("#")[0]) a[i].className="current";
}
