// JavaScript Document

var Preloader = {
  callbacks: [],
  images: [],
  loadedImages: [],
  imagesLoaded: 0,

  add: function(image){
    if (typeof image == 'string') this.images.push(image);
    if (typeof image == 'array' || typeof image == 'object'){
      for (var i=0; i< image.length; i++){
        this.images.push(image[i]);
      }
    }
  },
  onFinish: function(func){
    if (typeof func == 'function') this.callbacks.push(func);
    if (typeof func == 'array' || typeof func == 'object'){
      for (var i=0; i< func.length; i++){
        this.callbacks.push(func[i]);
      }
    }
  },
  load: function(){
    for(var i=0; i<this.images.length; i++){
      this.loadedImages[i] = new Image();
      this.loadedImages[i].onload = function(){ Preloader.checkFinished.apply(Preloader) }
      this.loadedImages[i].src = this.images[i];
    }
  },
  checkFinished: function(){
    this.imagesLoaded++;
    if (this.imagesLoaded == this.images.length) this.fireFinish();
  },
  fireFinish: function(){
    for (var i=0; i<this.callbacks.length; i++){
      this.callbacks[i]();
    }
    this.images = [];
    this.loadedImages = [];
    this.imagesLoaded = 0;
    this.callbacks = [];
  }
}
//
function TEMPLATE_has_scrollbar(elem_id,tSwitch) 
{ 
	elem = document.getElementById(elem_id);
	if (elem.clientHeight >= elem.scrollHeight) {
		//if text does not need scrollbar
		document.getElementById("TEMPLATE_container_1").style.width="495px";
		if(tSwitch) // checks to see if it's coming from TEACHING page
		{
			tSwitch=null;
			document.getElementById("TEACH_area").style.width="475px";
		}
	} else {
		//if text needs scrollbar
		document.getElementById("TEMPLATE_container_1").style.width="475px";
		if(tSwitch) // checks to see if it's coming from TEACHING page
		{
			tSwitch=null;
			document.getElementById("TEACH_area").style.width="455px";
		}
	}
}
//
function TEMPLATE_setFocus(elem_id)
{
	document.getElementById(elem_id).focus();
}
//
function TEMPLATE_thispage(thepage, pagename){
	if(!pagename) pagename="";
	var lastchar=thepage.lastIndexOf('/')+1;
	var lastper=thepage.lastIndexOf('.');
	var cuthref=thepage.substring(lastchar,lastper);
	var cuthref2=cuthref.split("_s_");
	if(thepage.indexOf("_s_")<0){
		var newimg1=document.getElementById(cuthref).src.substring(0,document.getElementById(cuthref).src.length-4);
		var newimg2=newimg1+"_selected.gif";
		document.getElementById(cuthref).src=newimg2;
		document.getElementById(cuthref+"a").href="#";
		botlink=document.getElementById(cuthref+"bl");
		botlink.href="#";
		botlink.style.color="#BBB";
		botlink.style.cursor="text";
	} else {

		if(thepage.indexOf("_u_")<0){
			document.getElementById("pane_top_submenu").style.display="block";
			document.getElementById("pane_top_submenu").innerHTML="<a href='../../../hi_d/scripts/"+cuthref2[0]+".htm'>"+cuthref2[0].toUpperCase()+"</a> > "+pagename;
			document.getElementById("container").style.height="615px";
		} else {
			cuthref3=cuthref2[1].split("_u_");
			pagename2=pagename.split("<cn>");
			document.getElementById("pane_top_submenu").style.display="block";
			document.getElementById("pane_top_submenu").innerHTML="<a href='../../../hi_d/scripts/"+cuthref2[0]+".htm'>"+cuthref2[0].toUpperCase()+"</a> > "+"<a href='../../../hi_d/scripts/"+cuthref2[0]+"_s_"+cuthref3[0]+".htm'>"+pagename2[0].toUpperCase()+"</a> > "+pagename2[1];
			document.getElementById("container").style.height="615px";
		}
	}
}
//
function TEACHING_makeappear(t)
{
	var topElem = document.getElementById("TEACH_top");
	var areaElem = document.getElementById("TEACH_area");
	var headElem = document.getElementById("TEACH_head");
	var bodyElem = document.getElementById("TEACH_body");
	topElem.style.display="none";
	areaElem.style.display="block";
	if (t=="less"){
		headElem.innerHTML=less1
		bodyElem.innerHTML=less2;
	} else if (t=="work"){
		headElem.innerHTML=work1;
		bodyElem.innerHTML=work2;
	} else if (t=="song"){
		headElem.innerHTML=song1;
		bodyElem.innerHTML=song2;
	} else if (t=="test"){
		headElem.innerHTML=test1;
		bodyElem.innerHTML=test2;
	} else if (t=="kids"){
		headElem.innerHTML=kids1;
		bodyElem.innerHTML=kids2;
	}
	TEMPLATE_has_scrollbar('pane_right',1);
	headElem.style.height = headElem.scrollHeight + "px";
	bodyElem.style.height = bodyElem.scrollHeight + "px";
}
//
function ALBUMS_LYRICS_descappear(descnum){
	document.getElementById("ALBUM_LYRICS_descriptions").innerHTML=ulp[descnum];
	document.getElementById("ALBUM_LYRICS_descriptions").style.display="block";
	TEMPLATE_has_scrollbar('pane_right',null);
}
//
function ALBUMS_LYRICS_descdisappear(){
	if (!event.fromElement.contains(event.toElement)&&!document.getElementById('ALBUM_LYRICS_songs').contains(event.toElement)){
		document.getElementById("ALBUM_LYRICS_descriptions").innerHTML="";
		document.getElementById("ALBUM_LYRICS_descriptions").style.display="none";
		TEMPLATE_has_scrollbar('pane_right',null);
	}
}
//
function SHOWS_PREVIOUS_openclosereviews(remove){
	remove.style.display="none";
	var remove2=remove.id.substring(0,remove.id.length-1);
	var display=remove.id.substring(remove.id.length-1);
	if(remove2=="SHOWS_PREVIOUS_container_oc"){
		display2="SHOWS_PREVIOUS_container_rv"+display;
	} else {
		display2="SHOWS_PREVIOUS_container_oc"+display;
	}
	document.getElementById(display2).style.display="block";
	
}
function CONNECT_selector(){
	var b=getQueryVariable("convar");
	if(b){
		document.forms[0].attn.options[b].selected=true;
	} else {
		return false;
	}
}
//
function navLinkSwitch(imgObj){
	if(imgObj.src.lastIndexOf("_selected.gif")<0){
		oldURL=imgObj.src;
		if(oldURL.indexOf("_over.gif")<0){
			newURL=oldURL.replace(".gif","_over.gif");
		} else {
			newURL=oldURL.replace("_over.gif",".gif");
		}
		imgObj.src=newURL;
	}
}
//
function getQueryVariable(variable) { 
	var query = window.location.search.substring(1); 
	var vars = query.split("&"); 
	for (var i=0;i<vars.length;i++) { 
		var pair = vars[i].split("="); 
		if (pair[0] == variable) { 
			return pair[1]; 
		} 
	} 
} 



















