
		function buildNavigation( dataProvider )
		{
			var path = document.location.toString().split('/');
			var cat 	= path[4];
			var slug 	= path[5];
		
			var index = 0;
		  
			var dynamic_ul = new Element('ul', {'id':'categories_nav'});
			var static_ul = new Element('ul', {'id':'case_studies_nav'});
			
			$each( dataProvider,
				function( category, category_index )
				{
					var h1 = new Element('h1', { 'class': 'toggler' });
					var a = new Element('a', { 'href':category.link, 'html':category.label });
					    a.addEvent('click', function(e)
					    {
					      /* prevent the accordian from animating before the page refresh */
					      e = new Event(e).stop();
					      document.location = e.target.href;
					    });
      			  h1.adopt(a);
					
					if( category.active=='1' || ( cat=='' && category_index==0 ) )
					{
						h1.addClass('active');
						index = category_index;
 					}
					
					var ul = new Element('ul');
					
					$each( category.data,
						function( project, project_index )
						{
							var li = new Element('li', { id:'sortable-'+project.id });
									li.adopt( new Element('a', { 'href':project.link, 'html':project.nav_title ? project.nav_title : project.project_name }) );
							
							if( project.active=='1' || ( !slug && project_index==0 ) )
								li.addClass('active');
							
							ul.adopt( li );
						});
					
					if( category.label!="CASE STUDIES" )
      		  var projects_s = new Sortables( ul, {
      				constrain: false,
      				clone: true,
      		    onComplete: function( e )
      		      {
      						saveOrder( "/portfolio/projects/save_order", projects_s.serialize() );
      					}
      				});
      		else
    			  var casestudy_s = new Sortables( ul, {
      				constrain: false,
      				clone: true,
      		    onComplete: function( e )
      		      {
      						saveOrder( "/portfolio/case_study/save_order", casestudy_s.serialize() );
      					}
      				});
    			
      		var cat_li = new Element('li', { id:'sortable-'+category.id });
              cat_li.adopt( h1 );
              cat_li.adopt( new Element('div',{'class':'list'}).adopt( ul ) );
          
          if( category.label!="CASE STUDIES" )
            dynamic_ul.adopt( cat_li );
          else
            static_ul.adopt( cat_li );
			});
			
			$('accordion').adopt( dynamic_ul );
			$('accordion').adopt( static_ul );
    
			var options = {};
					options[ slug ? 'show' : 'display' ] = index;
			
			var accordion = new Accordion('h1.toggler', 'div.list', $('accordion'), options );
			
			var cat_s = new Sortables( dynamic_ul, {
				constrain: false,
				clone: true,
				handle:'h1.toggler',
		    onComplete: function( e ){
						saveOrder( "/portfolio/categories/save_order", cat_s.serialize() );
					}
				});
		}

    function saveOrder( url, o )
  	{
  		var newOrder = o.join('|').replace(/sortable-/g,'');
  		var jsonRequest = new Request.JSON(
  	  {
  	   	url:url
  	  }).post({ 'order':newOrder });
  	}

		function pageIntro( full_intro )
		{
			if( $('project_detail') )
			{
			  $('image').set('tween',{ duration:400 });
  			$('image').tween('opacity', [0,1]);
  			
  			var myEffect = new Fx.Morph( $('image'), { duration:700 });
  					myEffect.start({ 'opacity':[0,1] });

  			var myEffect = new Fx.Morph( $('copy'), { duration:700 });
  					myEffect.start({ 'opacity':[0,1] });
			}

			if( $('casestudy') )
			{
				$each( $$('#clientlist .market'),
					function( el, index )
					{
						var myEffect = new Fx.Morph( el, { duration:300+(index*300) });
								myEffect.start({ 'opacity':[0, 1] });
					});
			}
	
			if( full_intro )
				$each( $$('#col_left li'),
					function( el, index )
					{
						var myEffect = new Fx.Morph( el, { duration:500+(index*100) });
								myEffect.start({
									'line-height'	: [50, 28],
									'opacity'		: [0, 1]
								});
					});
		}

		window.addEvent('domready',
			function()
			{
				var path = document.location.toString().split('/');
				var cat 	= path[4];
				var slug 	= path[5];
				
				pageIntro(cat=='');
	
			  var jsonRequest = new Request.JSON(
			  {
			    url: "/portfolio/menu",
			    onComplete:
			      function( response )
			      {
			        buildNavigation( response );
			      }
			    }).post({ 'category_slug':cat, 'project_slug':slug });
			});