
$(document).ready(function(){
	
	// relative path based on where these images are viewed, not this file
	$.imgpreload(['img/home/logo.gif','img/home/couch.jpg'],
	{
		all: function()
		{
			$(".zero").css({opacity: 0}).show();
			startHomePageAnimations();
			$("#hp-container").addClass("no-bg");
		}
	});
	
	current_highlight = 1;
	
});


function startHomePageAnimations()
{
	// fade in couch photo
	$("#couch").animate(
		{opacity: 1},
		{
			duration: 1000,
			easing: 'easeInSine',
			queue: false,
			complete: function()
			{
				// fade in triad logo
				$("#hp-logo").animate(
					{opacity: 1},
					{
						duration: 500,
						easing: 'easeInSine',
						queue: false,
						complete: function()
						{
							// this doesn't seem so graceful but...fade in each example one by one
							$("#example-1").animate(
								{ opacity: 1 },
								{
									duration: 450,
									easing: 'easeInSine',
									queue: false,
									complete: function()
									{
										$("#example-2").animate(
											{ opacity: 1 },
											{
												duration: 450,
												easing: 'easeInSine',
												queue: false,
												complete: function()
												{
													$("#example-3").animate(
														{ opacity: 1 },
														{
															duration: 450,
															easing: 'easeInSine',
															queue: false,
															complete: function()
															{
																$("#example-4").animate(
																	{ opacity: 1 },
																	{
																		duration: 450,
																		easing: 'easeInSine',
																		complete: function()
																		{
																			// start highlights
																			highlightExamples();
																		}
																	}
																);
															}
														}
													);
												}
											}
										);
									}
								}
							);
						}
					}
				);
			}
		}
	);
}


function highlights()
{
	
	// find out how many examples there are
	var total_examples = $(".portfolio-examples").length;
	
	// if you're on the last example, start from teh beginning, else go to the next
	if ( current_highlight == total_examples )
	{
		clearInterval(rotating);
		$(".portfolio-examples").removeClass("highlight");
	}
	else
	{
		current_highlight++;
		$(".portfolio-examples").removeClass("highlight");
		$("#example-" + current_highlight).addClass("highlight");	
	}
	
}


function highlightExamples()
{
	rotating = setInterval("highlights();", 3000);
}
