$(document).ready(doLoad);
function doLoad(){
		
	$("#search-results").tabs({ fxSlide: true});
	
	var q = $(document).getUrlParam("q");
	
	if(q !== null && q.length > 0){
		doSearch(q,'1');		 
	}else{
		$('#sidebar').hide();
	}
	
	$('a#stutab').one("click",function(){
		doSearch(q,'2');
	});
}

function doSearch(q,t){
	$('#load').show();
	
	var url = 'http://www.westga.edu/assets/lib/people-json.php';
	
	var tpl = function(){
		if(t=='1'){
			   return [
					'address',{'class':"vcard"},[
						'span',{'class':"fn"}, this.FIRST_NAME+' '+this.LAST_NAME,
						'span',{'class':"org"}, this.SEARCH,
						'a',{'href':"mailto:"+this.EMAIL,'class':"email"}, this.EMAIL,
						'span',{'class':"tel"}, this.PHONE_NUMBER
				]];
		}else{			
			   return [
					'address',{'class':"vcard"},[
						'span',{'class':"fn"}, this.FIRST_NAME+' '+this.LAST_NAME,
						'a',{'href':"mailto:"+this.EMAIL,'class':"email"}, this.EMAIL
				]];
		}
	}	
	
	var role = (t=='1')?"faculty":"student";
	var params = {"t":role,"q":q,"p":"1"};
		
	$.getJSON(url,params,function(data){						
		if(data.people.length == 0){ // No results
			var lsRegExp = /\+/g;
			$('#section-'+t).append('<p style="text-align:center">No Results for <em>'+unescape(q.replace(lsRegExp, " "))+'</em></p>');
			$('#section-'+t).append('<p style="text-align:center">Try Searching by last name only</p>');			
		}else{ //more than one result							
			$('#section-'+t).tplAppend(data.people, tpl);
			$('#section-'+t).append('<p style="text-align:center"><a href="index_people-search.php?q='+q+'&role='+role+'">get full results</a></p>');
		}
		$('#load').hide();
	});
}