
function initScreen()
{
  setTimeout("window.scrollTo(0,1);", 100); 
}
function updateOrientation()
{
  initScreen();
} 

function externalLinks() {
 if (!document.getElementsByTagName)
 {
   return;
 }
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
   {
     anchor.target = "_blank";
   }
 }
}

$(document).ready(function()
{

  $('.animate_title').click(function() {
 
    if(typeof sections_height == "undefined")
    {
      sections_height = $('#nav').height();
    }

    var $marginLefty;
    if(this.id != 'back_title')
    {
     $marginLefty = $('#' + this.id + '_items');
    }
    else
    {
     $marginLefty = $('#' + $('#section').html().toLowerCase() + '_items');
    }
    $('#nav').height($('#' + this.id + '_items').height());
    if(this.id != 'back_title')
    {
      $('#section').html(this.id.substr(0, 1).toUpperCase() + this.id.substr(1));
      $('#section').show();
    }
    else
    {
     $('#section').hide();
     $('#nav').height(sections_height);
    }
    $marginLefty.animate({
     marginLeft: parseInt($marginLefty.css('marginLeft'),10) == 0 
       ? $marginLefty.outerWidth()
       : 0,
    });

    $('#back_title').toggle();
    
  });
  
  $('.animate_body').click(function() {
 
    if(typeof section_height == "undefined")
    {
      section_height = $('#nav').height();
    }
   
    var $marginLefty;
    if(this.id != 'back_body')
    {
     $marginLefty = $('#' + this.id + '_body');
    }
    else
    {
      $marginLefty = $('#' + $('#section').attr('class'));
    }
    $('#nav').height($('#' + this.id + '_body').height());
    if(this.id != 'back_body')
    {
     $('#section').html($('#' + this.id + ' .title').html());
     $('#section').attr('class', this.id + '_body');
     $('#section').show();
    }
    else
    {
      var section = $('#section').attr('class').split('_');
      $('#section').html(section[0].substr(0, 1).toUpperCase() + section[0].substr(1));
      $('#nav').height(section_height);
    }
    $marginLefty.animate({
     marginLeft: parseInt($marginLefty.css('marginLeft'),10) == 0 
       ? $marginLefty.outerWidth()
       : 0,
    });

    $('#back_body').toggle();
    $('#back_title').toggle();    
    
  });
  
  externalLinks();
  
});

