// JavaScript Document
$(document).ready(function(){
						   
//$get the origaina image embeded in the page to use as the default one
var theOrigImage=$('#bannerImage').html();
var origWidth= $(theOrigImage).attr('width');		
var origHeight= $(theOrigImage).attr('height');	

var origText= $('.leadParagraph').html(); 

//clears the existing div
$('#bannerImage').empty();
//alert(origText);
var theXML; 
// gets the xml
$.ajax({
type: "GET",
url: "people.php",
dataType: "xml",
success: function(xml) {

theXML=xml;
//start of the loop
$(xml).find('person').each(function(){
var name = $(this).attr('name');
var jobTitle = $(this).attr('Jobtitle');
var imgurl = $(this).attr('img');	
var description = $(this).find('description').text();	
 
//starts off the image slide show
 $('<div class="items" ></div>').html('<img width="450" height="300" src="'+imgurl+'" alt="'+name+'"/> <h3>'+name+'</h3> ').appendTo('#bannerImage');
 
 //puts in the people cards
$('<div class="people borderBox" ></div>').html('<h3>'+name+'</h3><p >'+jobTitle+'</p><a href="#topPage"><img width="100" height="67" src="'+imgurl+'" alt="'+name+'"/></a>').appendTo('#theTeam');
 
 
});//end of the person loop

$('#bannerImage').cycle({ 'fx':'scrollLeft','speed':'slow','timeout': '4000'});	

$('.people').click(function () {
var theName=$(this).find('h3').text();
//alert(theName);
callItem(theName);
//return false;
});	


}//end of sucess function

});//end of ajax function
						   

function callItem(theItem){
	var theItem=theItem;
	var reqItem = $(theXML).find( "person[ name="+theItem+"]");	
	var theIndex=reqItem.index();
	var theDec= reqItem.find('description').text();	
//$('<h2 ></h2>').html(theItem).appendTo('#mainContent');
		$('#mainContent h2').empty();
		$('.leadParagraph').empty();
	$('.leadParagraph').before('<h2>'+theItem+'</h2>');

	
	
	$('.leadParagraph').append(theDec);
$('#bannerImage').cycle(theIndex);  
$('#bannerImage').cycle('pause'); 
	//alert(theItem);
}

	
						   
 
});//end of dom ready

