//-------------------------------------------------------------------
// START: VARIABLES
//-------------------------------------------------------------------	
	
	// total time it will take the front/backgrounds to load, used for the timers
	var iLoadBackgroundDelayTotal = iLoadBackgroundDelay + iLoadBackgroundEaseSpeed;
	var iLoadForegroundDelayTotal = iLoadForegroundDelay + iLoadForegroundEaseSpeed;
	var iPlayUnloadDelayTotal = iPlayUnloadDelay + iPlayUnloadSpeed;
	var iPlayLoadDelayTotal = iPlayLoadDelay + iPlayLoadSpeed;
	var iThis = 1;
	var iThisBackground = 1;
	var iThisForeground = 1;
	var iPersonActive = 1;
	
	var bLoadComplete = false;
	var bUnloadComplete = false;
	
//-------------------------------------------------------------------
// START: FUNCTIONS
//-------------------------------------------------------------------

// JQUERY - START READY FUNCTIONS
$(document).ready(function(){
	
	//-------------------------------------------------------------------
	// JQUERY - Page Set Up	
	
	// writes the images into the page
	jQuery.fn.fncPageSetUp = function() {		
		
		// start loading the background
		jQuery.fn.fncLoadBackground();

	}; //fncPageSetUp
	
	// writes the images into the page
	jQuery.fn.fncLoadBackground = function() {
		// build it
		var sHTML = "<div class=\"box\" id=\"teambar_box_"+iThisBackground+"\"></div>";
					
		// apprend it
		$("#teambar_background").append(sHTML);
		
		// fade it in
		$("#teambar_box_"+iThisBackground).css({opacity:'0'}).animate({opacity:iLoadBackgroundOpacity}, iLoadBackgroundEaseSpeed, iLoadBackgroundEaseType, function() {});
		
		// should i reset the timer or move to the foreground?
		iThisBackground++;
		if (iThisBackground<=iMax) { // restart background timer
			setTimerBackground=setTimeout(jQuery.fn.fncLoadBackground,iLoadBackgroundDelayTotal);
			
			// should I start the foreground now?
			if (iLoadForegroundStartWhen==iThisBackground) {
				jQuery.fn.fncLoadForeground();
			}
		}
	}; //fncLoadBackground
	
	// writes the images into the page
	jQuery.fn.fncLoadForeground = function() {
		jQuery.fn.fncLoadForegroundItem(iThisForeground);
		
		iThisForeground++;
		if (iThisForeground<=iMax) { // restart forground timer
			setTimerForeground=setTimeout(jQuery.fn.fncLoadForeground,iLoadForegroundDelayTotal);
			
			if (iThisForeground==iPlaySpotlightWhen) { // spotlight the image playing
				
				// turn on the first image
				jQuery.fn.fncPlaySpotlightOn(1);
	
			}
		} else {	
			bLoadComplete=true;
			
			// start the play timer
			jQuery.fn.fncPlayMaster();
		}
	}; //fncLoadForeground
	
	jQuery.fn.fncLoadForegroundItem = function(iThisItem) {
		// build it
		var sHTML = "<a id=\"teambar_image_"+iThisItem+"\" href=\""+aPersonLink[iThisItem]+"\" title=\"view "+aPersonNameFirst[iThisItem]+"'s bio\"><img src=\""+aPersonImage[iThisItem]+"\" alt=\""+aPersonNameFirst[iThisItem]+" "+aPersonNameLast[iThisItem]+"\" /></a>";
		
		// append it
		$("#teambar_images").append(sHTML);	
		
		// fade it in
		$("#teambar_image_"+iThisItem).css({opacity:'0'}).animate({opacity:iPlayOpacityOff}, iLoadForegroundEaseSpeed, iLoadForegroundEaseType, function() {});
	}; //fncLoadForeground
	
	//-------------------------------------------------------------------
	// JQUERY - Play Functions
	
	// master controls for all playing
	jQuery.fn.fncPlayMaster = function() {
		
		// make sure it is finished loading
		if (bLoadComplete) {
			// set up next person
			iPersonUnloadMe=iPersonActive;
			iPersonLoadedCurrently=iPersonActive;
			iPersonActive++;
			if (iPersonActive>iMax) {iPersonActive=1;};
			iPersonLoadMe=iPersonActive;
			iUnloadCount=1;
			iLoadCount=2; // starts at 2, because 1 is spotlighted
			
			// remove spotlight
			$("#teambar_box_1").animate({opacity:iLoadBackgroundOpacity}, iPlayUnloadSpeed, sPlayUnloadType, function() {});
			$("#navItem"+iPersonUnloadMe).removeClass("on");
					
			//alert(iPersonUnloadMe + ' ' + iPersonLoadedCurrently + ' ' + iPersonActive + ' ' + iPersonLoadMe);
			
			jQuery.fn.fncPlayUnload();
		} else {
			// not loaded, try again
			setTimerPlayLoad=setTimeout(jQuery.fn.fncPlayMaster,iPlayLoadDelayTotal);
		}
		
	}; //fncPlayMaster
	
	// unloads the images
	jQuery.fn.fncPlayUnload = function() {
		if (iUnloadCount<iMax) {
			$("#teambar_image_"+iPersonUnloadMe).animate({opacity:0}, iPlayUnloadSpeed, sPlayUnloadType, function() {});
					
			iPersonUnloadMe++;
			if (iPersonUnloadMe>iMax) {iPersonUnloadMe=1;};
		}
		
		iUnloadCount++;
		
		// all unloaded?
		if (iUnloadCount<iMax) {
			bUnloadComplete=false;
			
			// remove the rest now?
			if ((iPlayUnloadRemainingWhen+1)==iUnloadCount) {
				$("#teambar_images a:gt(1)").animate({opacity:0}, iPlayUnloadSpeed, sPlayUnloadType, function() {});
				iUnloadCount=iMax;
			}
			
			// start the play unload timer
			setTimerPlayUnload=setTimeout(jQuery.fn.fncPlayUnload,iPlayUnloadDelayTotal);
	
		} else {
			bUnloadComplete=true;
						
			// unload former active
			$("#teambar_image_"+iPersonLoadedCurrently).remove()
			
			// reload removed person to the last spot
			jQuery.fn.fncLoadForegroundItem(iPersonLoadedCurrently);
			
			// spot light new active person
			jQuery.fn.fncPlaySpotlightOn(iPersonActive);
			
			// reload everyone else
			setTimerPlayLoad=setTimeout(jQuery.fn.fncPlayLoad,iPlayLoadDelayTotal);
			
		}
	} //fncPlayUnload
	
	jQuery.fn.fncPlayLoad = function() {
		// make sure everything is unloaded
		if (bUnloadComplete) {
			iPersonLoadMe++;
			if (iPersonLoadMe>iMax) {iPersonLoadMe=1;};
			
			// fade person back in
			$("#teambar_image_"+iPersonLoadMe).animate({opacity:iPlayOpacityOff}, iPlayLoadDelay, sPlayLoadType, function() {});
			
			iLoadCount++;
			if (iLoadCount<iMax) {
				bLoadComplete=false;
				
				// start the play load timer
				setTimerPlayLoad=setTimeout(jQuery.fn.fncPlayLoad,iPlayLoadDelayTotal);
			} else {
				bLoadComplete=true;
				
				jQuery.fn.fncPlayMaster();
			}
		} else {
			// start the play load timer
			setTimerPlayLoad=setTimeout(jQuery.fn.fncPlayLoad,iPlayLoadDelayTotal);
		}
	} //fncPlayLoad
	
	// turns on the "spotlight" image
	jQuery.fn.fncPlaySpotlightOn = function(iSpotlight) {
		$("#teambar_box_1").animate({opacity:iPlayOpacityOn}, iPlayLoadSpeed, sPlayLoadType, function() {});
		$("#teambar_image_"+iSpotlight).animate({opacity:iPlayOpacityOn}, iPlayLoadSpeed, sPlayLoadType, function() {});
		$("#navItem"+iSpotlight).addClass("on");
		
	}; //fncPageSetUp
	
}); // end jQuery load
