// ------------------------------------------------------------
// 
// ------------------------------------------------------------
$(document).ready(
	function ()
	{
		initPortfolioList();
	}
);

// ------------------------------------------------------------
// 
// ------------------------------------------------------------
function initPortfolioList ()
{
	$("#portfolio li.client dl dd.actions a.toggle, #portfolio li.client dl dd.expanded a.toggle").click(handleClientToggle);
	
	$("#portfolio li.client dl dd.actions a.toggle, #portfolio li.client dl dd.expanded a.toggle").each(
		function ()
		{
			this.onclick = function () { return false; };
		}
	);
};

// ------------------------------------------------------------
// 
// ------------------------------------------------------------
function handleClientToggle (e)
{
	this.blur();
	
	var parentEl = $(this).parents("dl.client");
	var expandedEl = $("dd.expanded", parentEl);
	var expandedHeight = expandedEl.height();
	
	if (expandedEl.is(":visible"))
	{
		expandedEl.animate({
			height: 0
		}, 800, "swing", function ()
		{
			expandedEl.hide();
			expandedEl.css("height", expandedHeight);
		});
		
		$("dd.actions a.toggle", parentEl).html("Expand Portfolio");
	}
	else
	{
		expandedEl.css("height", 0);
		//expandedEl.show();
		expandedEl.css("display", "block");
		
		expandedEl.animate({
			height: expandedHeight
		}, 800, "swing", function ()
		{
		
		});

		$("dd.actions a.toggle", parentEl).html("Collapse Portfolio");
		
		$("dd.expanded li img", parentEl).each(
			function ()
			{
				if ($(this).attr("src") != $(this).attr("live"))
				{
					$(this).attr("src", $(this).attr("live"));
				};
			}
		);
	};
		
	if ($(this).parents(".expanded").length)
	{
		if ($.browser.safari)
		{
			window.scrollTo(0, $($(this).attr("href")).offset().top - 20);
		}
		else
		{		
			$.scrollTo({
				top: $($(this).attr("href")).offset().top - 20,
				left: 0
			}, {
				axis: "y",
				duration: 800,
				easing: "swing"
			});
		};
	};
	
	return false;
};
