/**File Referenced by this Script**/
/**Library/index.html **/
/**Library/community/index.asp **/
/**************** Variables ******************/

var timer			//used for storing the intervalRAte
var eventMV = 0		//Event Move, this increments the y axis of the current event div layer
var eventBG = 235	//Event Begin, this incremebts the y axis of the next event div layer
var totalSZ = 0		//Total Size, this detects the total number of event div layers to scroll by
var moveAMNT = 0	//Move Amount, is the current div layers ID
var moveAMNT2  = 1	//Move Amount2, is the the div layers ID (the upcoming event)
var strHolder		//strHolder, contains the information from the the calendar script
var isMoving		//Lets the script know if the events are currently in motion or not
var slowDWN = .025	//slowDWN, will fire after a certain height to make the div layer slow down into it's proper position
var t2 = null		//just a holder for the timeout feature

/**************** End Variables **************/


/************************************************/
//					Trim						//
//Purpose: Remove any excess spaces from the 	//
//beginning and end of the string				//
/************************************************/

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

/************************************************/
//					Remove HTML					//
//Purpose: Remove any excess html from the 	    //
//beginning and end of the string				//
/************************************************/

function removeHTMLTags(input){
 		var strInputCode = input;
 		/* 
  			This line is optional, it replaces escaped brackets with real ones, 
  			i.e. < is replaced with < and > is replaced with >
 		*/	
 	 	strInputCode = strInputCode.replace(/&(lt|gt);/g, function (strMatch, p1){
 		 	return (p1 == "lt")? "<" : ">";
 		});
 		var strTagStrippedText = strInputCode.replace(/<(DOCTYPE|ACRONYM|ADDRESS|APPLET|AREA|B|BASE|BASEFONT|BGSOUND|BIG|BLOCKQUOTE|BODY|BUTTON|CAPTION|CENTER|CITE|CODE|COL|COLGROUP|COMMENT|DD|DEL|DFN|DIR|DIV|DL|DT|EM|EMBED|FIELDSET|FONT|FORM|FRAME|FRAMESET|HEAD|H1|H2|H3|H4|H5|H6|HR|HTML|I|IFRAME|IMG|INPUT|INS|ISINDEX|KBD|LABEL|LAYER|LAGEND|LI|LINK|LISTING|MAP|MARQUEE|MENU|META|NOBR|NOFRAMES|NOSCRIPT|OBJECT|OL|OPTION|P|PARAM|PLAINTEXT|PRE|Q|S|SAMP|SCRIPT|SELECT|SMALL|SPAN|STRIKE|STYLE|SUB|SUP|TABLE|TBODY|TD|TEXTAREA|TFOOT|TH|THEAD|TITLE|TR|TT|U|UL|VAR|WBR|XMP|  2){1}.*?>/i,'')
 		return strTagStrippedText 
}

/************************************************/
//				getCalendar						//
//Purpose: This gathers the information from 	//
//the calendar script and properly formats it	//
//so that the formatTXT.asp/formatTXT2.asp		// 
//can properly format it.						//
/************************************************/

function getCalendar(fieldVAL){ 
	strHolder = removeHTMLTags(trim(fieldVAL))
	strHolder = strHolder.replace(/%/g, "[%PER%]")			//replace % with a word so as not to mess up the asp
	strHolder = strHolder.replace(/ /g, "[%SPACE%]")		//same as above 
	strHolder = strHolder.replace(/&/g, "[%AMP%]")			//"
	strHolder = strHolder.replace(/"/g, "[%QUOTE%]")		//"
	strHolder = strHolder.replace(/'/g, "[%SINGLE%]")		//"
	strHolder = strHolder.replace(/’/g, "[%SINGLE%]")		//"
	strHolder = strHolder.replace(/#/g, "[%PWND%]")			//same as above
	strHolder = strHolder.replace(/\+/g, "[%PLUS%]")		//"
	strHolder = strHolder.replace(/\u00A0/g, "[%SPACE%]")	//"
	strHolder = strHolder.replace(/”/g, "[%QUOTE%]")		//"
	strHolder = strHolder.replace(/“/g, "[%QUOTE%]")		//"
	strHolder = strHolder.replace(/\n/g, "")				//"
	strHolder = strHolder.replace(/\r/g, "")				////same as above 
	txt = name + "=" + strHolder + "%20"
	//return Message	
	xmlHttp=GetXmlHttpObject();								//Creates xmlHttp session to send data to asp
	if (xmlHttp==null)
	  {		
	  alert ("Your browser does not support AJAX!");		//if null then inform the user that ajax is not supported
	  return;
	  } 
	 // alert(strHolder)
	xmlHttp.onreadystatechange=stateChanged;				//when the call recieves a response send it to "statechanged"
	t=setTimeout("exeHttp(xmlHttp)", 500)					//wait for 500 miliseconds then fire the call to execute the xmlhttp 
															//request
}

/************************************************/
//				State Changed					//
//Purpose: When the xml returns a response it 	//
//fires stateChanged.  This function will then 	//
//spit out the information that was returned	// 
//from the asp file.							//
/************************************************/

function stateChanged() { 
	if (xmlHttp.readyState==4){ 
		document.getElementById("populateList").innerHTML=xmlHttp.responseText;		//write out the response the txt
		document.getElementById("loadingIMG").style.display = "none"				//hide the temporary load image
		document.getElementById("populateList").style.display = "block"				//display the new div layer with the calendar info
		getSize()											//fire the get size function to obtain the number of div layers
	}
}

/************************************************/
//				Set Event						//
//Purpose: Set event sets the timer interval 	//
//which fires the function that moves the div	//
//layers containing the calendar events			// 
//												//
/************************************************/

function setEvent(id){
	if((totalSZ > 1) && (document.location.href.indexOf("/community/") == -1)){
		clearTimeout(t2)										//celar the timeout so that this function is not fired twice
		timer = setInterval("moveEvents()",1);					//set the interval at which to fire the function to increment the layers
		moveAMNT = id;	
	}										//set the move amount to the position within id
}

/************************************************/
//			Get XML Http Object()				//
//Purpose: this sets the proper xml values so 	//
//that information can be sent back properly	//
//to and from formatTXT.asp/formatTXT2.asp		// 
//												//
/************************************************/

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

/************************************************/
//				Execute Http					//
//Purpose: WFires 	//
//the calendar script and properly formats it	//
//so that the formatTXT.asp/formatTXT2.asp		// 
//can properly format it.						//
/************************************************/

function exeHttp(xmlHttp){
	var url
	if(document.location.href.indexOf("/community/") == -1)					//are we on the community page?
		url = "http://www.pct.edu/library/includes/ajax/formatTXT.asp"		//if not then we will want to execute this asp code script
	else{
		url = "http://www.pct.edu/library/includes/ajax/formatTXT2.asp"		//else we execute this code script 
	}
	xmlHttp.open("POST", url, true);										//we open the xml path and we post the information to the 
																			//script
	xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');	//set the xml header to allow posting
	var data = "file=q" + "&content=" + strHolder;							//set the data for to send
	xmlHttp.send(data);														//send the data
	clearTimeout(t)															//clear the time out that executed this code
}

/************************************************/
//					Get Size					//
//Purpose: Exactly as it says.  Get Size will	//
//count the number of event div layers.			//
//												// 
//												//
/************************************************/

function getSize(){
	var i = 1
	while(document.getElementById("event-" + i.toString())){						//While we are on a "real" layer
		totalSZ = i;																//increment the number of events
		i++;
	}
	if((totalSZ > 1) && (document.location.href.indexOf("/community/") == -1)){	//if we are not on the community page
		moveAMNT = 1																//set the first move to the first layer in the list
		t2=setTimeout("setEvent(1)", 7000)											//set a time out to call the first move
	}
}

/************************************************/
//					Pause						//
//Purpose: Pause, pauses the current animation	//
//when a user mouses over the event layer.		//
//												// 
//												//
/************************************************/

function pause(){
	if(isMoving){											//if the events are currently scrolling
		clearInterval(timer)								//clear out the set interval that causes it to scroll
		timer = null										//set the timer to null
	}
	else{													//else we are not scrolling
		clearTimeout(t2)									//so we simple clear out the set timeout
	}
}

/************************************************/
//					Resume						//
//Purpose: Resume, resumes the animation after 	//
//a users mouses out of the event layer.		//
//												// 
//												//
/************************************************/

function resume(){
	if(isMoving){											//was it moving last we stopped it?
		timer = setInterval("moveEvents()",1);				//if so then we simple set the interval to start running again
	}
	else{
		t2=setTimeout("setEvent(" + moveAMNT2 + ")", 3000)	//else it wasn't moving so we reset the set time out function
	}														//with a lower second counter as the 7 sec isn't necessary
}

/************************************************/
//					Move events					//
//Purpose: Does exactly as it sounds.  It moves	//
//the current event displaying and the upcoming	//
//event.  This is the meat of the javascript	// 
//as it controls the whole scrolling feature	//
/************************************************/

function moveEvents(){
		if(eventMV >= -200){								//has the div layer nearly reached it's final position of -235?
			eventMV -= 1.5									//if not we increment eventMV and eventBG by -1.5
			eventBG -= 1.5
		}
		else{												//else yes we are currenlty 34 points away from being at the -235 pos
			eventMV -= (34*slowDWN)							//increment the slow down by the points left * the current slowdown 
															//precentage.
			eventBG -= (34*slowDWN)							//same as eventMV
			slowDWN -= .025/80								//this subtracts a small increment from slowDWN. this is what actually
		}													//creates the slow down appearance
		isMoving = true;									//We are currently moving so set the boolean to true	
		moveAMNT2 = moveAMNT + 1							//this value holds the second div layer that contains the next calendar 	
															//event

		if(moveAMNT == totalSZ){										//if we have reached the end of our div layer str
			document.getElementById("event-" + moveAMNT.toString()).style.top = eventMV + "px"		//keep incrementing the current one
			document.getElementById("event-1").style.top = eventBG + "px"		//mvoe the first layer "event-1" back up into place
		}
		else{
			document.getElementById("event-" + moveAMNT.toString()).style.top = eventMV + "px"		//else we move the current layer
			document.getElementById("event-" + moveAMNT2.toString()).style.top = eventBG + "px"		//and we move the next layer
		}
		if (eventMV <= -235){								//if the eventMV is less then 235 then that means we are done moving
			eventMV = 0;									//reset all values back to there proper positions.
			eventBG = 235
			slowDWN = .025

			document.getElementById("event-" + moveAMNT.toString()).style.top = 235 + "px";
															//move the layer that was the current visible layer to it's original
															//starting position.  This position is just slightly out of view below
															//the current displayer evet layer.
			if (moveAMNT >= totalSZ) {						//if we have done past our total number of event div layers
				moveAMNT2 = 1;								//reset the value back to the first one
			}
			pause();										//puase the scrolling feature since we are at the new event
			isMoving = false;								//we are no longer moving
			t2=setTimeout("setEvent(" + moveAMNT2 + ")", 7000)		//set the time out to fire the next event scroll in 7 secs
		}
}

// JavaScript DocumentclassName i