jQuery(function($) {
	var 
		initialHeaderWidth = 163,
		expandedHeaderWidth = 117,
		itemWidth = 230, 
		duration = 'fast';
	var toggleElement = function(el)
	{
		if(el.hasClass('expanded'))
		{
				$('.accordion h1').animate({width: initialHeaderWidth + 'px'}, duration);
				$('.accordion article').animate({width: initialHeaderWidth + 'px'}, duration);
				$('.accordion section').animate({'margin-left': initialHeaderWidth + 'px'}, duration);
				el.removeClass('expanded');
		}
		else
		{
			if(!$('.accordion .expanded').length)
			{
				$('.accordion h1').animate({width: expandedHeaderWidth + 'px'}, duration);
				$('.accordion section').animate({'margin-left': expandedHeaderWidth + 'px'}, duration);
			}
			else
			{
				$('.accordion .expanded').removeClass('expanded');
			}
			$('.accordion article').stop(true, false);
			$('.accordion article').animate({width: expandedHeaderWidth + 'px'}, duration);
			el.stop(true, false).animate({width: (expandedHeaderWidth+itemWidth) + 'px'}, duration).addClass('expanded');
		}
	}
	
	$('#content').addClass('accordion');
	$('a.internal').click(function() {
		var el = $($(this).attr('href'));
		if(!el.length)
		{
			return;
		}
		toggleElement(el);
		if(pageTracker)
			pageTracker._trackPageview('/' + $(this).attr('href').substr(1));
	});
	var anchor = parseUri(document.location.href).anchor;
	if(anchor.length && $('#' + anchor).length)
	{
		toggleElement($('#' + anchor));
		if(pageTracker)
			pageTracker._trackPageview('/' + anchor);
		$('.accordion article, .accordion section, .accordion h1').stop(true, true);
	}
});

// parseUri 1.2.2
// (c) Steven Levithan <stevenlevithan.com>
// MIT License

function parseUri (str) {
	var	o   = parseUri.options,
		m   = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
		uri = {},
		i   = 14;

	while (i--) uri[o.key[i]] = m[i] || "";

	uri[o.q.name] = {};
	uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
		if ($1) uri[o.q.name][$1] = $2;
	});

	return uri;
};

parseUri.options = {
	strictMode: false,
	key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
	q:   {
		name:   "queryKey",
		parser: /(?:^|&)([^&=]*)=?([^&]*)/g
	},
	parser: {
		strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
		loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
	}
};

