/*
At some point the called functions should probably be changed to work more like the client helper ones.
*/

function parse_location() {
  var loc = window.location;
  var chunks = (loc.toString()).split('#');

  //see if there's a real url in there
  var tmp = (loc.toString()).split('/');
  
  //alert(tmp.length+' '+chunks.length);
  
  var real_url = false;
  if(Number(tmp.length) >= 4 && chunks.length == 1) {
    real_url = true;
  }
  
  //alert(real_url);
  if(!chunks[1] && !real_url) {
    //return 'about/firm';
    return null;
  }
  
  return chunks[1];
}

function load_r3a_window(newLocation) {
  var loc = newLocation;

  if($('splash')) {
    Element.hide('splash');
  }
  
  
  chunks = loc.toString().split('/');
  
  //so we have all of out request parameters in 'chunks'
  //Start figuring out what to do with them
  
  
  switch(chunks[0]) {
    case 'about':
      if(chunks[1]) {
        load_about(chunks[1]);
      }
    break;
    
    case 'awards':
      if(!chunks[1]) {
        load_award_menu();
      }
      else {
        load_award(chunks[1]);
      }
    break;
    
    case 'news':
      if(!chunks[1]) {
        load_news_menu();
      }
      else {
        load_news(chunks[1]);
      }
    break;
    
    case 'people':
      load_people();      
    break;
    
    case 'category':
      if(chunks[1]) {
        load_subcats(chunks[1]);
      }
    
    break;
    
    case 'project':
      if(chunks[1]) {
        load_project(chunks[1]);
      }
    
    break;
    
    
  }  
}

function load_about(key) {
  if($('slot-1')) {
    Element.hide('slot-1');  
  }
  
  new Ajax.Updater('slot-1', '/about_page/'+key, {asynchronous:true
  , evalScripts:true, onComplete:function(request, json){new Effect.Appear('slot-1', {queue:'end'});dhtmlHistory
  .add('about/'+key)}, onLoading:function(request, json){select_menu_item(key+'_link')}}); return false
}

function load_award_menu() {
  new Ajax.Updater('slot-1', '/award/menu', {asynchronous:true, evalScripts
  
  :true, onComplete:function(request, json){new Effect.Appear('slot-1', {queue:'end'});dhtmlHistory.add
  
  ('awards')}, onLoading:function(request, json){select_menu_item('award_link')}}); return false;
}

function load_award(key)
{
new Ajax.Updater('slot-2', 'award/show/id/'+key, {asynchronous

:true, evalScripts:true, onComplete:function(request, json){new Effect.Appear('slot-2', {queue

:'end'});dhtmlHistory.add('award/'+key)}, onLoading:function(request, json){select_menu_item('award-'+key+'-link'

, 'subcats-menu-container')}}); return false;
}

function load_news_menu()
{
  new Ajax.Updater('slot-1', '/news/menu', {asynchronous:true, evalScripts
  
  :true, onComplete:function(request, json){new Effect.Appear('slot-1', {queue:'end'});dhtmlHistory.add
  
  ('news')}, onLoading:function(request, json){select_menu_item('news_link')}}); return false;
 
}

function load_news(key) {
  new Ajax.Updater('slot-2', 'news/show/id/'+key, {asynchronous
  
  :true, evalScripts:true, onComplete:function(request, json){new Effect.Appear('slot-2', {queue
  
  :'end'});dhtmlHistory.add('news/'+key)}, onLoading:function(request, json){select_menu_item('news-'+key+'-link'
  
  , 'subcats-menu-container')}}); return false;
  
}

function load_people()
{
  new Ajax.Updater('slot-2', '/people/staff', {asynchronous:true, evalScripts:true
  
  , onComplete:function(request, json){new Effect.Appear('slot-2', {queue:'end'});if (dhtmlHistory
  
  .isFirstLoad()) {dhtmlHistory.add('people/staff')}}, onLoading:function(request, json){select_menu_item
  
  ('', 'subcats-menu-container')}}); return false;
}

function load_subcats(key)
{
  new Ajax.Updater('slot-1', '/portfolio/subcats/id/'+key, {asynchronous:true
  , evalScripts:true, onComplete:function(request, json){new Effect.Appear('slot-1', {queue:'end'});dhtmlHistory
  .add('category/'+key)}, onLoading:function(request, json){select_menu_item('main_cat_'+key+'_link')}}); return false
}

function load_project(key)
{
new Ajax.Updater('slot-2', 'portfolio/project/id/'+key, {asynchronous

:true, evalScripts:true, onComplete:function(request, json){new Effect.Appear('slot-2', {queue

:'end'});dhtmlHistory.add('project/'+key)}, onLoading:function(request, json){select_menu_item('project-'+key+'-link'

, 'subcats-menu-container')}}); return false;
}