// JavaScript Document


/*** JQuery Version Control **/
//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(){
	$('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){					
		 if(txt.length > 2)
		 {
		
		$('div#alert').html('<a href="alert.html">' + txt + '</a>');
		$('div#alert').show();
		 }
		 else {
		$('div#alert').hide();
		 }
		});
	
	$('#selection3').attr('checked','true');
	
	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 -->
   <!-- Added 12/20/2010 by Jeremy Shafer -->
	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 rollOn(x) {
		return true;
	}
	
	function rollOff(x) {
		return true;
	}
	
	
