$(document).ready( function($) {

	$('dl').each(function() {
		var dlLeft = $(this).clone(false).insertBefore($(this));
		var dlRight = $(this).clone(false).insertBefore($(this));
		
		dlLeft.addClass('left').children().remove();
		dlRight.addClass('right').children().remove();
		
		var count = -1;
		var addto = dlLeft;
		
		$(this).children('dd').css('display','none');
		
		$(this).children().each(function() {
			if($(this).is('dt')) {
				count++;
			} 
			
			addto = ((count%2) == 0)?dlLeft:dlRight;
			
			if($(this).is('dt')) {
				$(this).clone(true).appendTo(addto);
			} else {
				$(this).clone(true).appendTo(addto).prev().addClass('has-definition');
			}

		});		

		$('<div class="br"><br /></div>').insertAfter($(this));
		$(this).remove();

	});

	if(jQuery.url.attr("anchor") && $('#'+jQuery.url.attr("anchor")).length > 0 ) {
		var targetOffset = $('#'+jQuery.url.attr("anchor")).offset().top;
		$('html, body').animate({scrollTop: targetOffset}, 0);
	}

	$('.has-definition').each(function() {
		$(this).css('cursor', 'pointer')
		.bind('click', function() {
			$(this)
			.toggleClass('active')
			.next().animate(
				{
                	height: "toggle",
                	opacity:"toggle"
              	}, 
			  	'normal');
		});
	});	
	
	function filterPath(string) {
		return string
			.replace(/^\//,'')
			.replace(/(index|default).[a-zA-Z]{3,4}$/,'')
			.replace(/\/$/,'');
	}
	var locationPath = filterPath(location.pathname);
	$('a[href*=#]').each(function() {
		var thisPath = filterPath(this.pathname) || locationPath;
		if (  locationPath == thisPath
		&& (location.hostname == this.hostname || !this.hostname)
		&& this.hash.replace(/#/,'') ) {
			var $target = $(this.hash), target = this.hash;
			if (target) {
				var targetOffset = $target.offset().top;
				$(this).click(function(event) {
					event.preventDefault();
					$('html, body').animate({scrollTop: targetOffset}, 750, function() {
						location.hash = target;
					});
				});
			}
		}
	});

	$('a.external').click(function(){
		window.open(this.href);
		return false;
	});

	$('#carousel a').each(function() {
//		$(this).
		
	});

});