// JavaScript Document


/*** JQuery Version Control **/
function get_Newsroom(intArticleCount){
	var arrResults = new Array();
	var src ='http://news.temple.edu/rss/homepagenewsitems.xml';
	$.ajax({
		url: 'scripts/proxy.inc.asp?url='+src+'&mimeType=text/xml',
		//If the url is hosted outside of Temple servers, define and use a proxy//
		/*	Sample: url: proxy+'http://news.temple.edu/rss/news.xml'
			Where proxy is 'pathtolocalfile/proxy.inc.asp?url='+src+'&mimeType=text/xml'
			AND src is a variable that is defined and escaped (Eg:  var src = escape('http://www.domain.com/file.xml);)
		 */
		beforeSend: function(){
			//Empty the existing unordered list
			$('.newsfeed').empty();
		},
		success: function(data) {
			var arrItems = $(data).find('item');							
			if(arrItems.length>0){			

				for(var i=0; i<intArticleCount;i++){
					var strClass = 'article';
					var strTitle = $(arrItems[i]).find('title').text();
					var strDesc = $(arrItems[i]).find('description').text();
					var strExtLink = $(arrItems[i]).find('link').text();
					

					arrResults.push(new Array(strClass,strExtLink,strTitle,strDesc));
				}
				for(i=0;i<arrResults.length;i++){
					var eleH3 = $('<h3>'+arrResults[i][2]+'</h3>');
					//var eleP = $('<p>'+arrResults[i][3]+'</p>');
					var eleAnchor = $('<a>');
						$(eleAnchor).attr({
							'href':arrResults[i][1],
							'target':'_blank'
						});
						$(eleAnchor).append($(eleH3));
						//$(eleAnchor).append($(eleP));					
					//var eleLI = $('<li>').addClass(arrResults[i][0]);	
					var eleLI = $('<p>').addClass(arrResults[i][0]);
						$(eleLI).append($(eleAnchor));
						$('.newsfeed').append($(eleLI));
						$('.newsfeed li:first-child').addClass('first-child');
						$('.newsfeed li:last-child').addClass('last-child');
				}
			};
		},
		complete: function(){}
	});
}

//Object
function photoFadeAutomated(){
	var object = this;
	//Core HTML Elements
	object.eleUl = null;
	object.arrLi = null;
	object.intLiCount = null;
	
	object.intContainerHeight = null;
	
	//Image Indexing Variables
	object.intActiveIndex = 0;
	object.intNextIndex = 1;
	
	//Caption Variables
	object.arrColumnClasses = new Array('col1','col2','col3');
	object.intColumns = 3;
	
	object.arrCaption = new Array();
	
	
	//Animation Core Variables
	object.intTransitionTime = 750;
	object.intDisplayTime = 5000;
	
	//Cookie Variables
	object.strCookieName = 'AdmissionsSplashAnimation';
	object.intCookieIndex = $.readCookie(object.strCookieName);
	object.intCookieDuration = 7;  //in days
	
	
	//Object Methods
	object.ColumnSort = function(intCurPos){
		var intColGroup = null;
		var intCaptionCount = 	intCurPos +1;
		
		intColGroup = intCaptionCount;
		
		if(intCaptionCount > object.intColumns){
			var intFloor = Math.floor(intCaptionCount/object.intColumns);
			intColGroup = intCaptionCount-(intFloor*object.intColumns);
			if(intColGroup==0){ intColGroup = object.intColumns;}
		}
		return(intColGroup-1);
	}
	
	object.Rotate = function(){
		$(object.arrLi[object.intActiveIndex]).delay(object.intDisplayTime).animate(
			{'opacity':'0'},
			object.intTransitionTime,
			function(){
				$(this).css({'z-index':0});
				$(this).find('div').css('height',0);
				$(this).find('p').remove();
				
				$(object.arrLi[object.intNextIndex]).css({'z-index':1});
				
				
				$(object.arrLi[object.intNextIndex]).find('div').animate({'height':object.intContainerHeight},{duration:750,complete:function(){$(this).append('<p>'+object.arrCaption[object.intActiveIndex]+'</p>');}});
				
				object.intActiveIndex++;
				if(object.intActiveIndex>=object.intLiCount){
					object.intActiveIndex = 0;
				}
				
				object.intNextIndex = (object.intActiveIndex*1)+1;
				if(object.intActiveIndex==(object.intLiCount*1)-1){
					object.intNextIndex = 0;
				}
				
				$(object.arrLi[object.intNextIndex]).css({'opacity':100});
				
				$.setCookie(object.strCookieName, object.intActiveIndex, {
       				duration: object.intCookieDuration
    			});
				
				
								
				object.Rotate();
			}
		);
	}

	object.Initialize = function(eleUl){
		object.eleUl = $(eleUl);
		
		if(object.eleUl){			
			//Get HTML Element Data		
			object.intContainerHeight = $(object.eleUl).parent().height();
			object.arrLi = object.eleUl.find('li').css({'opacity':0,'z-index':0}).each(function(index){
					//var strCaption = $(this).find('img').attr('alt');
					object.arrCaption.push($(this).find('img').attr('alt'));
					var strCaptionClass = object.arrColumnClasses[object.ColumnSort(index)];			
					$(this).append('<div class="'+strCaptionClass+'"></div>');
					$(this).find('div').css('height',0);
					//$(this).find('div p').css('opacity',0);
				});
			object.intLiCount = object.arrLi.length;
			
				if(object.intCookieIndex){
					object.intActiveIndex = (object.intCookieIndex*1)+1;
						if(object.intActiveIndex>=object.intLiCount){
							object.intActiveIndex = 0;
						}
					
					object.intNextIndex = (object.intActiveIndex*1)+1;
						if(object.intActiveIndex==(object.intLiCount*1)-1){
							object.intNextIndex = 0;
						}
				}
				
				$(object.arrLi[object.intActiveIndex]).css({'z-index':1,'opacity':100});
				$(object.arrLi[object.intNextIndex]).css({'z-index':0,'opacity':100});
				$(object.arrLi[object.intActiveIndex]).find('div').animate({'height':object.intContainerHeight},{duration:750,complete:function(){$(this).append('<p>'+object.arrCaption[object.intActiveIndex]+'</p>');}});
				
				$.setCookie(object.strCookieName, object.intActiveIndex, {
					duration: object.intCookieDuration
				});
				
				//Run Rotate Method
				object.Rotate();
		}
	}
}

//Initializer
$(document).ready(function(){
	get_Newsroom(3);
	$('ul.photoFadeAutomated').each(function(){
		var objCrossfade = new photoFadeAutomated();
		objCrossfade.Initialize(this);
	});
	
	
	//Previously existing code in the website
	//ALERTS
	/*******************************
	$.get('/wwwpages/AppDev/alert.asp',function(txt){					
	
		//alert("alert get");
	
		 if(txt.length > 2)
		 {
			alert("alert found");
			//$('div#alert').html('<a href="alert.html">' + txt + '</a>');
			
			$('div#alert').show();
		 }
		 else {
			alert("alert not found");
			$('div#alert').hide();
		 }
		});
	*******************************/
	
	$('#selection3').attr('checked','checked');
	
	function syncInputs()
	{
		$('#basic_query').attr('value', $('#q').attr('value'));	
	}
	
	$('#q').keyup(function(e) {
		  //alert(e.keyCode);
		  syncInputs();				      
	});

	function changeAction(zvalue,method)
	{				
		$('#searchform').attr('action', zvalue);
		$('#searchform').attr('method', method);
		//SearchType
		$('#basic_query').attr('value', $('#q').attr('value'));
		//alert($('#searchform').attr('action'));
	}
	
	$('#selection1').bind('click',function(){
		changeAction(this.value, 'GET');
	});
	$('#selection2').bind('click',function(){
		changeAction(this.value, 'POST');
	});
	
});

   <!-- SCRIPT FOR GOOGLE SEARCH -->
	function submitSwitchboard() {
		var strQ  = document.searchform.q.value;
		if (trim(strQ) != '') {
			document.gong_form.q.value=strQ;
			document.google_form.q.value='Temple University '+strQ;
			if (document.searchform.selection1.checked) {
				document.gong_form.submit();
				}
			if (document.searchform.selection2.checked) {
				document.directory_form.submit();
				}
			if (document.searchform.selection3.checked) {
				document.google_form.submit();
				}
			}
		return false;
		}

	function trim(stringToTrim) {
		return stringToTrim.replace(/^\s+|\s+$/g,"");
	}

		function trim(stringToTrim) {
		return stringToTrim.replace(/^\s+|\s+$/g,"");
	}

	function rollOn(x) {
		return true;
	}
	
	function rollOff(x) {
		return true;
	}

