// JavaScript Document

var currentMidImage = 0;
var firstTimeThrough = true;

/*************************************/
/* intialize the thumbnail code      */
/*************************************/

//var myElementsEffects;
var oldStep = 0;

	window.addEvent('domready', function() {								
		if(document.getElementById('imageFader')){
			loadXML();
		}
		if(document.getElementById('midImageRotationContainer')){
			loadMidXML();
		}
	});



/*************************************************************************/
/*                       This loads the XML                              */
/*************************************************************************/

// LOAD XML FOR RIGHT SIDE
function loadXML()
{
var timestamp = new Date();
var uri = "/fileadmin/_lcu/XML/imageHolder.xml";
var uniqueURI = uri + (uri.indexOf("?") > 0 ? "&" : "?")+ "timestamp="+ timestamp.getTime();
	try
	{
		if (window.ActiveXObject)
		{
			var errorHappendHere = "Check Browser and security settings";
			xmlDoc2 = new ActiveXObject("Microsoft.XMLDOM");
			xmlDoc2.async=false;
			xmlDoc2.onreadystatechange=verify2;
			xmlDoc2.load(uniqueURI);
			imageRotator();
		}
		else if(window.XMLHttpRequest)
		{
			var errorHappendHere = "Error handling XMLHttpRequest request";
			var d = new XMLHttpRequest();
			d.open("GET", uniqueURI, false);
			d.send(null);
			xmlDoc2=d.responseXML;
			imageRotator();
		} else {
			var errorHappendHere = "Error.";
			xmlDoc2 = document.implementation.createDocument("","",null);
			xmlDoc2.onreadystatechange=verify2;
			xmlDoc2.async=false;
			xmlDoc2.load(uniqueURI);
			xmlDoc2.onload=imageRotator();
		}
	}	
	catch(e)
	{
		//alert(errorHappendHere);
	}
}
// END LOAD XML FOR RIGHT SIDE
// LOAD XML FOR MIDDLE
function loadMidXML()
{
var timestamp = new Date();
if(pageid == 14){
	//Why LCU
	var uri = "/fileadmin/_lcu/XML/aboutLCU/mid/14.xml";
}else if(pageid == 15 || pageid == 16){
	//Message from the President
	var uri = "/fileadmin/_lcu/XML/aboutLCU/mid/15.xml";
}else if(pageid == 17){
	//Our History
	var uri = "/fileadmin/_lcu/XML/aboutLCU/mid/17.xml";
}else if(pageid == 18){
	//Accreditation
	var uri = "/fileadmin/_lcu/XML/aboutLCU/mid/18.xml";
}else if(pageid == 19 || pageid == 20 || pageid == 2208){
	//Spiritual Life
	var uri = "/fileadmin/_lcu/XML/aboutLCU/mid/19.xml";
}else if(pageid == 23 || pageid == 24 || pageid == 27 || pageid == 30 || pageid == 2267 || pageid == 2268 || pageid == 2269 || pageid == 2270 || pageid == 2271 || pageid == 2272 || pageid == 2273 || pageid == 2274 || pageid == 2275 || pageid == 2276){
	//Administration
	var uri = "/fileadmin/_lcu/XML/aboutLCU/mid/23.xml";
}else if(pageid == 31 || pageid == 2293 || pageid == 2294){
	//Green Initatives
	var uri = "/fileadmin/_lcu/XML/aboutLCU/mid/31.xml";
}else if(pageid == 222){
	//Technology Advancement
	var uri = "/fileadmin/_lcu/XML/aboutLCU/mid/222.xml";
}else if(pageid == 38){
	//Diversity Programs
	var uri = "/fileadmin/_lcu/XML/aboutLCU/mid/38.xml";
}else if(pageid == 37 || pageid == 39 || pageid == 43 || pageid == 42 || pageid == 40 || pageid == 41){
	//Human Resources
	var uri = "/fileadmin/_lcu/XML/aboutLCU/mid/37.xml";
}else if(pageid == 36){
	//Our Faculty
	var uri = "/fileadmin/_lcu/XML/aboutLCU/mid/36.xml";
}else if(pageid == 370){
	//Our Staff
	var uri = "/fileadmin/_lcu/XML/aboutLCU/mid/370.xml";
}else if(pageid == 1869){
	//News
	var uri = "/fileadmin/_lcu/XML/aboutLCU/mid/1869.xml";
}else if(pageid == 103){
	//Maps and Directions
	var uri = "/fileadmin/_lcu/XML/aboutLCU/mid/103.xml";
}else{
	var uri = "/fileadmin/_lcu/XML/interiorRotator1.xml";
}
var uniqueURI = uri + (uri.indexOf("?") > 0 ? "&" : "?")+ "timestamp="+ timestamp.getTime();
	try
	{
		if (window.ActiveXObject)
		{
			var errorHappendHere = "Check Browser and security settings";
			xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
			xmlDoc.async=false;
			xmlDoc.onreadystatechange=verify;
			xmlDoc.load(uniqueURI);
			midImageRotator();
		}
		else if(window.XMLHttpRequest)
		{
			var errorHappendHere = "Error handling XMLHttpRequest request for mid col image + "+ pageid;
			var d = new XMLHttpRequest();
			d.open("GET", uniqueURI, false);
			d.send(null);
			xmlDoc=d.responseXML;
			midImageRotator();
		} else {
			var errorHappendHere = "Error.";
			xmlDoc = document.implementation.createDocument("","",null);
			xmlDoc.onreadystatechange=verify;
			xmlDoc.async=false;
			xmlDoc.load(uniqueURI);
			xmlDoc.midImageRotator=midImageRotator();
		}
	}	
	catch(e)
	{
		//alert(errorHappendHere);
	}
}
// END OF LOAD XML FOR MIDDLE
function verify()
{
  // 0 Object is not initialized
  // 1 Loading object is loading data
  // 2 Loaded object has loaded data
  // 3 Data from object can be worked with
  // 4 Object completely initialized
  if (xmlDoc.readyState != 4)
  {
    return false;
  }
}
function verify2()
{
  // 0 Object is not initialized
  // 1 Loading object is loading data
  // 2 Loaded object has loaded data
  // 3 Data from object can be worked with
  // 4 Object completely initialized
  if (xmlDoc2.readyState != 4)
  {
    return false;
  }
}





var midImageRotator = function midImageRotator()
{
	// array of all of the image paths to be loaded
	var images=new Array;
	// variable to build all of the heading images within the innerHTML
	var topHeadingCode="";
	// create an object with all of the image nodes
	var xmlTopNodes=xmlDoc.getElementsByTagName("node")[0].getElementsByTagName("image"); 
	numTopNodes = xmlTopNodes.length;
	// assign the number of nodes found to a global level variable
	numberOfHeadings = numTopNodes;
	// loop through the images
	
	for(var x=0; x<numberOfHeadings; x++){
		// get the value of the image source
		var newImage = xmlDoc.getElementsByTagName("node")[0].getElementsByTagName("image")[x].getElementsByTagName("source")[0].childNodes[0].nodeValue;
		// get the value of the image alt text
		var newAlt = xmlDoc.getElementsByTagName("node")[0].getElementsByTagName("image")[x].getElementsByTagName("altTag")[0].childNodes[0].nodeValue;
		// add to the final code
		topHeadingCode+='<img src="' + newImage + '" border="0" id="midImg'+x+'" alt="'+newAlt+'" title="' + newAlt + '" />';	
		// populate the images array
		images[x]=newImage;
	}

	document.getElementById('midImageRotationContainer').innerHTML = topHeadingCode;
	for (x=0; x<numberOfHeadings; x++){	
		document.getElementById('midImg'+x).style.zIndex = 100+x;
		document.getElementById('midImg'+x).style.left = "0px";
												       
	}
	currentMidImg = numTopNodes-1;
	
	// Preloader of large images
	if(document.getElementById('midImg1')){
	new Asset.images(images, {
		onComplete: function(){
			timedMidCount();
		}
	});
	}
}
function timedMidCount()
{
	// get number of image nodes
	var xmlMidNodes=xmlDoc.getElementsByTagName("node")[0].getElementsByTagName("image"); 
	numMidNodes = xmlMidNodes.length;
	// determine browser type
	var browser=navigator.appName;
	var transitionDuration = 1500;// set timing for transitions. It is set to fade out in 1.5 seconds
	var transitionTiming = 8000; // set the time in between transitions. It is set to transition in 8 seconds

	document.getElementById('midImg'+0).style.left = "0px";
		var myElementsEffects = new Fx.Elements($$(('img#midImg'+currentMidImg)),{duration: transitionDuration});
		myElementsEffects.start({
			0 : { //let's change the first element's opacity
				'left': [0,-550]
			}
		});
	// increase the value of the currentMidImage
	
	currentMidImg--;
	
	if(currentMidImg <0){
		document.getElementById('midImg0').style.left="10px";
		currentMidImg = numMidNodes-1;
		
		for(x=0; x<numMidNodes; x++){
			document.getElementById('midImg'+x).style.left = "0px";
		}
	}
	setTimeout("timedMidCount()",transitionTiming);
}

/*********************************************************************/
/*  This function loads the images. If imageMode in the XML is set   */
/*  to rotate, the images will rotate through on a timer. If it is   */
/*  not set to random, an image is selcted to display at random.     */
/*         *** We do not recommend editing this function ***         */
/*********************************************************************/

var imageRotator = function imageRotator()
{
	var imageMode=xmlDoc2.getElementsByTagName("node")[0].getAttribute('imageMode');
	// check to see which image mode is set
	if(imageMode=="rotate")
	{
		// array of all of the image paths to be loaded
		var images2=new Array;
		// variable to build all of the heading images within the innerHTML
		var topHeadingCode2="";
		// create an object with all of the image nodes
		var xmlTopNodes2=xmlDoc2.getElementsByTagName("node")[0].getElementsByTagName("image"); 
		// find out how many top nodes there are
		var numTopNodes2=xmlTopNodes2.length; 
		// assign the number of nodes found to a global level variable
		numberOfHeadings2 = numTopNodes2;
		// loop through the images
		for(var x=0; x<numberOfHeadings2; x++){
			// get the value of the image source
			var newImage2 = xmlDoc2.getElementsByTagName("node")[0].getElementsByTagName("image")[x].getElementsByTagName("source")[0].childNodes[0].nodeValue;
			// get the value of the image alt text
			var newAlt2 = xmlDoc2.getElementsByTagName("node")[0].getElementsByTagName("image")[x].getElementsByTagName("altText")[0].childNodes[0].nodeValue;
			// add to the final code
			topHeadingCode2+='<img src="' + newImage2 + '" border="0" id="heading'+x+'" alt="'+newAlt2+'" />';	
			// populate the images array
			images2[x]=newImage2;
		}
		// set the global currentProfile number to the randome number generated
		currentHeading2 = 0;
		// put everything together and create the image
		document.getElementById('imageFader').innerHTML = topHeadingCode2;
		// Preloader of large images
		new Asset.images(images2, {
			onComplete: function(){
				timedCount();
			}
		});
		
	}else{  // this else fires off if imageMode is set to refresh
		// create an object with all of the image nodes
		var xmlTopNodes=xmlDoc2.getElementsByTagName("node")[0].getElementsByTagName("image"); 
		// find out how many top nodes there are
		var numTopNodes=xmlTopNodes.length; 
		// Pull in a random number based on the number of nodes
		var randomNumber=Math.floor(Math.random()*numTopNodes);
		// get the value of the image source
		var newImage = xmlDoc2.getElementsByTagName("node")[0].getElementsByTagName("image")[randomNumber].getElementsByTagName("source")[0].childNodes[0].nodeValue;
		// get the value of the image alt text
		var newAlt = xmlDoc2.getElementsByTagName("node")[0].getElementsByTagName("image")[randomNumber].getElementsByTagName("altText")[0].childNodes[0].nodeValue;
		// add to the final code
		topHeadingCode+='<img src="' + newImage + '" border="0" id="headingRefresh" alt="'+newAlt+'" />';	
		// add the html to the page
		document.getElementById('imageFader').innerHTML = topHeadingCode;
	}
}
// starting z-index
var counter=2;
// timed loop for heading images
function timedCount()
{	
	// determine browser type
	var browser=navigator.appName;
	var transitionDuration = 1500;// set timing for transitions. It is set to fade out in 1.5 seconds
	var transitionTiming = 8000; // set the time in between transitions. It is set to transition in 8 seconds
	// time in between loops
	setTimeout("timedCount()",transitionTiming);
	// determin which heading to work with
	var newId = "heading" + currentHeading2;
	// make sure opacity starts at 0
	if (browser=="Netscape"){
		document.getElementById(newId).style.opacity = '0';
	}else if(browser=="Microsoft Internet Explorer"){
		document.getElementById(newId).style.filter='alpha(opacity=00)';
	}
	// set the z index of the new heading to be on top
	document.getElementById(newId).style.zIndex=counter;
	// only chang the first heading if this is the first time through the loop
	if(firstTimeThrough){
		var myElementsEffects2 = new Fx.Elements($$('#imageFader img#heading0'),{duration: transitionDuration});
		myElementsEffects2.start({
			'0': { //let's change the first element's opacity
				'opacity': [0,1]
			}
		});
		firstTimeThrough = false;
	}else{
		// set the new heading's opacity from 0 to 1
		var myElementsEffects2 = new Fx.Elements($$('#imageFader img#heading'+currentHeading2),{duration: transitionDuration});
		myElementsEffects2.start({
			'0': { //change the headings's opacity
				'opacity': [0,1]
			}
		});
	}
	// reset the current Heading value appropriately if it reaches the end of the images or not
	if(currentHeading2 == numberOfHeadings2-1){
		currentHeading2 = 0;
	}else{
		currentHeading2++;	
	}
	counter++;
}