window.onload = setDisplayInit //begin the initialization when window loads

//initialize global variables
var divTag = null; //where to display the bios
var bioname = null;//the selected bio filename
var baseurl = "bios/arbmusicians.xml";//establish base url for non-mouseover function
var url;

function setDisplayInit (){
  var musicianList = document.getElementById('m_arbgroup');
  var musicians = musicianList.getElementsByTagName('area');
//define the names for the areas as an array and use this array to trigger the functions

  for(var i=0; i < musicians.length; i++){
    musicians[i].onmouseover = displayMusician;
    musicians[i].onmouseout = displayMusicianOff;
   }
  divTag = document.getElementById('bios');
  //defines where the bios are to be shown utilizing the established global variable
}

function displayMusician (){
        bioname = this.id;
        sendRequest();
        }


function displayMusicianOff (){
   bioname = "arbmusicians";
   sendRequest();
}

function sendRequest(){
    var request = null;
    if (window.XMLHttpRequest){
        request = new XMLHttpRequest();
        var testthis = "this is from Firefox";
        }
    else{
  	   request = new ActiveXObject("Microsoft.XMLHTTP");
   }
// only send if valid bio being requested
if (bioname != null && bioname != "" && bioname != "undefinied"){
    url = "bios/" + bioname +".xml";
    if (request) {
    /*if  there is a problem, check to ensure url is being passed properly here by
        commenting out to the next braces and inserting
        divTag.innerHTML = url
        */

        request.open("GET", url, true);
        request.onreadystatechange =
            function(){
                if(request.readyState == 4){
                    if(request.status == 200){
                        divTag.innerHTML = "";//clear any existing text
                        processXML(request.responseXML);
                        }
                     }
             }
        request.send(null);
        }
   else {
   alert("Sorry, your browser is outdated. Please update your browser to see the Alouette River Band's Bios");
    }
}
}

function processXML(xml_doc)
{
   // get the root element
	var root_elem = xml_doc.documentElement;

	// outer 'div' tag
	var createdDivTag = document.createElement("div");
	createdDivTag.className = "ajaxbio";

	// title
	var title = root_elem.getElementsByTagName("title")[0];
	var titleTag = document.createElement("h2");
	titleTag.className = "titlename";
	titleTag.appendChild(document.createTextNode(title.firstChild.nodeValue));
	createdDivTag.appendChild(titleTag);

	// get all 'para' tags
   var paraList = root_elem.getElementsByTagName("para");
	for (var i = 0; i < paraList.length; i++)
	{
		var para = paraList[i];
		var pTag = document.createElement("p");
		pTag.appendChild(document.createTextNode(para.firstChild.nodeValue));
		createdDivTag.appendChild(pTag);
	}


	createdDivTag.appendChild(pTag);
	divTag.appendChild(createdDivTag);
}


