

HomeManager = {
	currId:null,
	
	loadInProgress:false,
	
	loadingImg:null,
	
	audioData:{collaborative:{width:301, title:"Hear more about David's client story.", file:"mp3/David-Collaborative.mp3"},
			   trust:{width:298, title:"Hear more about Scott's client story.", file:"mp3/Scott-Trust.mp3"},
			   proactive:{width:288, title:"Hear more about Joe's client story.", file:"mp3/Joe-Pro-Active-Equalized.mp3"},
			   problemSolving:{width:288, title:"Hear more about Jay's client story.", file:"mp3/Jay-ProblemSolving.mp3"},
			   creative:{width:304, title:"Hear more about Joyce's client story.", file:"mp3/Joyce-Creative.mp3"},
			   expertise:{width:316, title:"Hear more about Howard's client story.", file:"mp3/Howard-Expertise.mp3"}},
	
	updateMain:function(id) {
		HomeManager.updateThumb(id);
		HomeManager.loadImage(id);
		HomeManager.currId = id;
	},
	
	updateThumb:function(id) {
		if (HomeManager.currId != null) {
			var thumb = $(".peopleMenu ." + HomeManager.currId + " a.thumb");
			thumb.removeClass("selected");
			thumb.addClass("isActive");
			$(".loader").remove();
		}
		thumb = $(".peopleMenu ." + id + " a.thumb");
		thumb.addClass("selected");
		thumb.removeClass("isActive");
		thumb.append("<img src='images/global/ajax-loader.gif' class='loader' />");
	},
	
	loadImage:function(id) {
		if (HomeManager.loadInProgress) {
			// alert ("load in progress");
			// delete HomeManager.loadingImg.load;
			// delete HomeManager.loadingImg;
			$(HomeManager.loadingImg).remove();
		}
		
		HomeManager.loadingImg = new Image();
		
		$(HomeManager.loadingImg)
			.load(function() {
				// Hide the image once loaded.
				$(this).hide();
				$("#textStreamOuter").remove();
				$(".mainBlock img").remove();
				$(".mainBlock").append(this);
				$(this).fadeIn("slow");
				$(".loader").remove();
				
				// Load up the audio player.
				var data = HomeManager.audioData[HomeManager.currId];
				var params = {
					wmode: "transparent",
					allowscriptaccess: "always"
				};
				var flashvars = {
					track: data.file,
					title: data.title
				};
				
				swfobject.embedSWF("flash/audioPlayer.swf", "audioPlayerInner", data.width, "42", "8.0.0", null, flashvars, params);
				
				// Add placement class.
				$("#audioPlayerOuter")
					.removeClass()
					.addClass(HomeManager.currId);
				
				HomeManager.loadInProgress = false;
			})
			.error(function() {
				alert ("Image could not be loaded.");
			})
			.attr("src", "images/home/lg_" + id + ".jpg");
			
		HomeManager.loadInProgress = true;
	}
}


// When DOM is ready.

$(document).ready(function() {
	// Set-up our peopleMenu functionality.
	$(".peopleMenu a").bind("click", function(evt) {
		var id = $(evt.target).attr("rel");
		HomeManager.updateMain(id);
		evt.preventDefault();
	});
	
	// Check to see if a specific audio clip was requested.
	if ($.jqURL.get('section')) {
		HomeManager.updateMain($.jqURL.get('section'));
	} else {
		var params = {
			wmode: "transparent"
		};
		var flashvars = { };
		// Otherwise, embed the text stream animation.
		swfobject.embedSWF("flash/textStream.swf", "textStreamInner", "928", "50", "8.0.0", null, flashvars, params);
	}
});

