Merge jb-mr1-dev into aosp/master - do not merge

Change-Id: Icf16741de4c0d248e5ffe3ef3b31ce6ce51c4c9f
diff --git a/core/version_defaults.mk b/core/version_defaults.mk
index 1cc4e3c..09eeb67 100644
--- a/core/version_defaults.mk
+++ b/core/version_defaults.mk
@@ -41,7 +41,7 @@
   # which is the version that we reveal to the end user.
   # Update this value when the platform version changes (rather
   # than overriding it somewhere else).  Can be an arbitrary string.
-  PLATFORM_VERSION := 4.2.42.42.42
+  PLATFORM_VERSION := 4.2.1.2.4.8.16.32.64
 endif
 
 ifeq "" "$(PLATFORM_SDK_VERSION)"
diff --git a/tools/droiddoc/templates-sdk/assets/css/default.css b/tools/droiddoc/templates-sdk/assets/css/default.css
index f56fc98..4c4cdee 100644
--- a/tools/droiddoc/templates-sdk/assets/css/default.css
+++ b/tools/droiddoc/templates-sdk/assets/css/default.css
@@ -129,11 +129,14 @@
 em {
   font-style: italic; }
 
-acronym {
+acronym,
+.tooltip-link {
   border-bottom: 1px dotted #555555;
   cursor: help; }
 
-acronym:hover {
+acronym:hover,
+.tooltip-link:hover {
+  color: #7aa1b0;
   border-bottom-color: #7aa1b0; }
 
 img.with-shadow,
@@ -445,21 +448,23 @@
     border:1px solid #DADADA;
     border-bottom:0;
   }
-      
+
   .training-nav-top a.next-page-link {
     border-left:0;
     width:123px;
   }
       
+  .paging-links a.disabled,
   .training-nav-top a.disabled,
   .content-footer a.disabled {
-    color:#999;
+    color:#bbb;
   }
       
+  .paging-links a.disabled:hover,
   .training-nav-top a.disabled:hover,
   .content-footer a.disabled:hover {
     cursor:default;
-    color:#999 !important;
+    color:#bbb !important;
   }
       
   .training-nav-top a.start-class-link,
@@ -467,6 +472,78 @@
     width:262px;
   }
   
+  /* list of classes on course landing page */
+  ol.class-list {
+    list-style:none;
+    margin-left:0;
+  }
+  ol.class-list>li {
+    margin:0 0 15px;
+    padding:5px 0 0;
+    overflow:hidden;
+    border-top:1px solid #ccc;
+  }
+  ol.class-list li a.title {
+    font-size:16px;
+    margin:0;
+    clear:left;
+    display:block;
+    height:32px;
+    padding:0 4px;
+  }
+  ol.class-list li a.title h2 {
+    color:inherit;
+    margin:0 0 10px;
+    display:block;
+    float:left;
+    width:675px;
+  }
+  ol.class-list li a.title span {
+    display:none;
+    float:left;
+    font-size:18px;
+    font-weight:bold;
+    background: transparent url(../images/styles/disclosure_right.png) no-repeat scroll 50% 50%;
+    width: 10px;
+    height: 32px;
+  }
+  ol.class-list li a.title:hover {
+    background:#ddd;
+    color:#258AAF !important;
+  }
+  ol.class-list li a.title:hover span {
+    display:block;
+  }
+  
+  #jd-content
+  ol.class-list li img {
+    float:left;
+    clear:left;
+    width:64px;
+    margin:0 20px 0 0;
+  }
+  ol.class-list li p.description {
+    float:left;
+    display:block;
+    width:250px;
+    margin:0;
+  }
+  ol.class-list li p.description.article {
+    width: 550px;
+  }
+  ol.class-list ol {
+    float:left;
+    width:320px;
+    margin:0 0 0 30px;
+    list-style:none;
+    margin:0 0 0 20px;
+  }
+  ol.class-list div.lessons li {
+    margin:0 0 6px;
+    line-height:16px;
+  }
+  
+  
   .hide {
     display:none !important;
   }
@@ -483,6 +560,49 @@
     float:right;
     text-transform:uppercase;
   }
+  
+  
+  
+  /* inner-doc tabs w/ title */
+  
+div#title-tabs-wrapper {
+  border-bottom:1px solid #ccc;
+  margin:20px 0 30px;
+}
+h1.with-title-tabs {
+  display:inline-block;
+  margin:0 0 -1px 0;
+  padding:0 60px 0 0;
+  border-bottom:1px solid #F9F9F9;
+}
+ul#title-tabs {
+  list-style:none;
+  padding:0;
+  height:29px;
+  margin:0;
+  font-size:16px;
+  line-height:26px;
+  display:inline-block;
+  vertical-align:bottom;
+}
+ul#title-tabs li {
+  display:block;
+  float:left;
+  margin-right:40px;
+  border-bottom: 3px solid transparent;
+}
+ul#title-tabs li.selected {
+  border-bottom: 3px solid #93C;
+}
+ul#title-tabs li a {
+  color:#333;
+}
+ul#title-tabs li a:hover,
+ul#title-tabs li a:active {
+  color:#93C !important;
+}
+
+
 
 /* content body */
 @-webkit-keyframes glowheader {
@@ -938,9 +1058,12 @@
 dd p {
   margin:10px 0 0;
 }
-ul p,
-ol p {
-  margin:5px 0 0;
+li p,
+li pre,
+li ul,
+li ol {
+  margin-top:5px;
+  margin-bottom:5px;
 }
 pre strong, pre b, a strong, a b, a code {
     color: inherit;
@@ -1418,18 +1541,14 @@
     color: #444;
 }
 a.button, a.button:visited, a.button-secondary, a.button-secondary:visited {
-    height: 28px;
-    line-height: 28px;
     margin-right: 16px;
-	font-weight: 400;
+	 font-weight: 400;
     min-width: 54px;
     outline: 0;
     padding: 8px 15px;
     text-align: center;
 }
 .button, .button-secondary {
-    height: 34px;
-    line-height: 34px;
     margin-right: 16px;
 	font-weight: 400;
     min-width: 54px;
@@ -1455,6 +1574,9 @@
     background-image: none;
     border-color: #30b7e6;
 }
+a.button.big.subtitle {
+  line-height:18px;
+}
 .button-secondary:hover, a.button-secondary:hover {
     border-color: #dbdbdb;
     background-color: #f3f3f3;
@@ -1469,7 +1591,7 @@
     color: #33B5E5 !important;
 }
 .button-secondary:active, a.button-secondary:active {
-    border-color: #dadada;
+   border-color: #dadada;
 	background: #ebebeb; /* Old browsers */
 	/* IE9 SVG, needs conditional override of 'filter' to 'none' */
 	background:
@@ -1510,12 +1632,20 @@
   font-size:20px;
   display:inline-block;
 }
+.button.big span.small {
+  font-size:14px;
+}
+.button-caption {
+  margin-top:10px;
+  font-size:12px;
+  font-style:italic;
+}
 
 .button.disabled,
 .button.disabled:hover,
 .button.disabled:active {
   background:#ebebeb;
-  color:#999;
+  color:#999 !important;
   border-color:#999;
   cursor:default;
 }
@@ -1832,15 +1962,54 @@
     border-color: #eff2f9;
 }
 */
+
+/* SDK TOS styles */
+
+div.sdk-terms {
+  white-space: pre-wrap;
+  word-wrap: break-word;
+  font-family: inherit;
+  font-size: inherit;
+  padding: 10px;
+  height: 370px;
+  width: 738px;
+  border: 1px solid #444;
+  background: transparent;
+  overflow:auto;
+  margin:0 0 10px;
+}
+
+div.sdk-terms.fullsize {
+  padding: 0;
+  height: auto;
+  width: auto;
+  border:none;
+}
+
+div.sdk-terms h3,
+div.sdk-terms h2 {
+  margin:0;
+}
+
+div#sdk-terms-form {
+  padding:0 0 0 10px;
+}
+
+div#sdk-terms-form input {
+  display:inline;
+  margin:4px 4px 4px 0;
+}
+
+
 /* --------------------------------------------------------------------------
 Code Style
 */
 pre {
-	margin:0 0 1em 0;
-	padding: 1em;
-	overflow: auto;
-	border: solid 1px #ddd;
-	background: #f7f7f7;	
+  margin:0 0 1em 0;
+  padding: 1em;
+  overflow: auto;
+  border: solid 1px #ddd;
+  background: #f7f7f7;	
 }
 .str { color: #080; }
 .kwd { color: #008; }
@@ -2332,6 +2501,29 @@
   line-height:30px;
 }
 
+.expandable {
+  height:34px;
+  padding-left:20px;
+  position:relative;
+}
+.expandable:before {
+  content: '';
+  background-image: url(../images/styles/disclosure_down.png);
+  background-repeat:no-repeat;
+  background-position: -12px -9px;
+  width: 20px;
+  height: 20px;
+  display: inline-block;
+  position: absolute;
+  top: 0;
+  left: 0; }
+}
+.expandable.expanded:before {
+  background-image: url(../images/styles/disclosure_up.png);
+}
+
+
+
 /* -----------------------------------------------
 Dialog box for popup messages 
 */
diff --git a/tools/droiddoc/templates-sdk/assets/js/docs.js b/tools/droiddoc/templates-sdk/assets/js/docs.js
index d18c490..f1fbfff 100644
--- a/tools/droiddoc/templates-sdk/assets/js/docs.js
+++ b/tools/droiddoc/templates-sdk/assets/js/docs.js
@@ -28,7 +28,7 @@
   $('.scroll-pane').jScrollPane( {verticalGutter:0} );
   
   // add HRs below all H2s (except for a few other h2 variants)
-  $('h2').not('#qv h2').not('#tb h2').not('.sidebox h2').not('#devdoc-nav h2').css({marginBottom:0}).after('<hr/>');
+  $('h2').not('#qv h2').not('#tb h2').not('.sidebox h2').not('#devdoc-nav h2').not('h2.norule').css({marginBottom:0}).after('<hr/>');
   
   // set search's onkeyup handler here so we can show suggestions 
   // even while search results are visible
@@ -135,6 +135,7 @@
 
   // select current page in sidenav and set up prev/next links if they exist
   var $selNavLink = $('#nav').find('a[href="' + pagePath + '"]');
+  var $selListItem;
   if ($selNavLink.length) {
     $selListItem = $selNavLink.closest('li');
 
@@ -156,11 +157,9 @@
 false; // navigate across topic boundaries only in design docs
     if ($prevListItem.length) {
       if ($prevListItem.hasClass('nav-section')) {
-        if (crossBoundaries) {
-          // jump to last topic of previous section
-          $prevLink = $prevListItem.find('a:last');
-        }
-      } else {
+        // jump to last topic of previous section
+        $prevLink = $prevListItem.find('a:last');
+      } else if (!$selListItem.hasClass('nav-section')) {
         // jump to previous topic in this section
         $prevLink = $prevListItem.find('a:eq(0)');
       }
@@ -177,18 +176,8 @@
       }
     }
 
-    if ($prevLink.length) {
-      var prevHref = $prevLink.attr('href');
-      if (prevHref == SITE_ROOT + 'index.html') {
-        // Don't show Previous when it leads to the homepage
-      } else {
-        $('.prev-page-link').attr('href', $prevLink.attr('href')).removeClass("hide");
-      }
-    } 
-
     // set up next links
     var $nextLink = [];
-    var startCourse = false;
     var startClass = false;
     var training = $(".next-class-link").length; // decides whether to provide "next class" link
     var isCrossingBoundary = false;
@@ -206,53 +195,103 @@
         $('.topic-start-link').text($nextLink.text().toUpperCase());
       }
       
-      // Handle some Training specialties
-      if ($selListItem.parent().is("#nav") && $(".start-course-link").length) {
-        // this means we're at the very top of the TOC hierarchy
-        startCourse = true;
-      } else if ($(".start-class-link").length) {
-        // this means this page has children but is not at the top (it's a class, not a course)
+      // If the selected page has a description, then it's a class or article homepage
+      if ($selListItem.find('a[description]').length) {
+        // this means we're on a class landing page
         startClass = true;
       }
     } else {
       // jump to the next topic in this section (if it exists)
       $nextLink = $selListItem.next('li').find('a:eq(0)');
       if (!$nextLink.length) {
-        if (crossBoundaries || training) {
-          // no more topics in this section, jump to the first topic in the next section
-          $nextLink = $selListItem.parents('li:eq(0)').next('li.nav-section').find('a:eq(0)');
-          isCrossingBoundary = true;
+        isCrossingBoundary = true;
+        // no more topics in this section, jump to the first topic in the next section
+        $nextLink = $selListItem.parents('li:eq(0)').next('li.nav-section').find('a:eq(0)');
+        if (!$nextLink.length) {  // Go up another layer to look for next page (lesson > class > course)
+          $nextLink = $selListItem.parents('li:eq(1)').next('li.nav-section').find('a:eq(0)');
         }
       }
     }
-    if ($nextLink.length) {
-      if (startCourse || startClass) {
-        if (startCourse) {
-          $('.start-course-link').attr('href', $nextLink.attr('href')).removeClass("hide");
-        } else {
-          $('.start-class-link').attr('href', $nextLink.attr('href')).removeClass("hide");
-        }
-        // if there's no training bar (below the start button), 
-        // then we need to add a bottom border to button
-        if (!$("#tb").length) {
-          $('.start-course-link').css({'border-bottom':'1px solid #DADADA'});
-          $('.start-class-link').css({'border-bottom':'1px solid #DADADA'});
-        }
-      } else if (training && isCrossingBoundary) {
-        $('.content-footer.next-class').show();
-        $('.next-page-link').attr('href','')
-                            .removeClass("hide").addClass("disabled")
-                            .click(function() { return false; });
-       
-        $('.next-class-link').attr('href',$nextLink.attr('href'))
-                            .removeClass("hide").append($nextLink.html());
-        $('.next-class-link').find('.new').empty();
-      } else {
-        $('.next-page-link').attr('href', $nextLink.attr('href')).removeClass("hide");
+
+    if (startClass) {
+      $('.start-class-link').attr('href', $nextLink.attr('href')).removeClass("hide");
+
+      // if there's no training bar (below the start button), 
+      // then we need to add a bottom border to button
+      if (!$("#tb").length) {
+        $('.start-class-link').css({'border-bottom':'1px solid #DADADA'});
       }
+    } else if (isCrossingBoundary && !$('body.design').length) {  // Design always crosses boundaries
+      $('.content-footer.next-class').show();
+      $('.next-page-link').attr('href','')
+                          .removeClass("hide").addClass("disabled")
+                          .click(function() { return false; });
+     
+      $('.next-class-link').attr('href',$nextLink.attr('href'))
+                          .removeClass("hide").append($nextLink.html());
+      $('.next-class-link').find('.new').empty();
+    } else {
+      $('.next-page-link').attr('href', $nextLink.attr('href')).removeClass("hide");
+    }
+
+    if (!startClass && $prevLink.length) {
+      var prevHref = $prevLink.attr('href');
+      if (prevHref == SITE_ROOT + 'index.html') {
+        // Don't show Previous when it leads to the homepage
+      } else {
+        $('.prev-page-link').attr('href', $prevLink.attr('href')).removeClass("hide");
+      }
+    } 
+
+    // If this is a training 'article', there should be no prev/next nav
+    // ... if the grandparent is the "nav" ... and it has no child list items...
+    if (training && $selListItem.parents('ul').eq(1).is('[id="nav"]') &&
+        !$selListItem.find('li').length) {
+      $('.next-page-link,.prev-page-link').attr('href','').addClass("disabled")
+                          .click(function() { return false; });
     }
     
   }
+  
+  
+  
+  // Set up the course landing pages for Training with class names and descriptions
+  if ($('body.trainingcourse').length) {
+    var $classLinks = $selListItem.find('ul li a').not('#nav .nav-section .nav-section ul a');
+    var $classDescriptions = $classLinks.attr('description');
+    
+    var $olClasses  = $('<ol class="class-list"></ol>');
+    var $liClass;
+    var $imgIcon;
+    var $h2Title;
+    var $pSummary;
+    var $olLessons;
+    var $liLesson;
+    $classLinks.each(function(index) {
+      $liClass  = $('<li></li>');
+      $h2Title  = $('<a class="title" href="'+$(this).attr('href')+'"><h2>' + $(this).html()+'</h2><span></span></a>');
+      $pSummary = $('<p class="description">' + $(this).attr('description') + '</p>');
+      
+      $olLessons  = $('<ol class="lesson-list"></ol>');
+      
+      $lessons = $(this).closest('li').find('ul li a');
+      
+      if ($lessons.length) {
+        $imgIcon = $('<img src="'+toRoot+'assets/images/resource-tutorial.png" alt=""/>');
+        $lessons.each(function(index) {
+          $olLessons.append('<li><a href="'+$(this).attr('href')+'">' + $(this).html()+'</a></li>');
+        });
+      } else {
+        $imgIcon = $('<img src="'+toRoot+'assets/images/resource-article.png" alt=""/>');
+        $pSummary.addClass('article');
+      }
+
+      $liClass.append($h2Title).append($imgIcon).append($pSummary).append($olLessons);
+      $olClasses.append($liClass);
+    });
+    $('.jd-descr').append($olClasses);
+  }
+
 
 
 
@@ -384,11 +423,11 @@
 
   // Set up tooltips
   var TOOLTIP_MARGIN = 10;
-  $('acronym').each(function() {
+  $('acronym,.tooltip-link').each(function() {
     var $target = $(this);
     var $tooltip = $('<div>')
         .addClass('tooltip-box')
-        .text($target.attr('title'))
+        .append($target.attr('title'))
         .hide()
         .appendTo('body');
     $target.removeAttr('title');
@@ -1052,6 +1091,22 @@
 }
 
 
+/* New version of expandable content */
+function toggleExpandable(link,id) {
+  if($(id).is(':visible')) {
+    $(id).slideUp();
+    $(link).removeClass('expanded');
+  } else {
+    $(id).slideDown();
+    $(link).addClass('expanded');
+  }
+}
+
+function hideExpandable(ids) {
+  $(ids).slideUp();
+  $(ids).prev('h4').find('a.expandable').removeClass('expanded');
+}
+
 
 
 
@@ -1883,11 +1938,18 @@
 
   if (selectedLevel < minLevel) {
     var thing = ($("#jd-header").html().indexOf("package") != -1) ? "package" : "class";
-    $("#naMessage").show().html("<div><p><strong>This " + thing + " is not available with API level " + selectedLevel + ".</strong></p>"
-                              + "<p>To use this " + thing + ", you must develop your app using a build target "
-                              + "that supports API level " + $("#doc-api-level").attr("class") + " or higher. To read these "
-                              + "APIs, change the value of the API level filter above.</p>"
-                              + "<p><a href='" +toRoot+ "guide/appendix/api-levels.html'>What is the API level?</a></p></div>");
+    $("#naMessage").show().html("<div><p><strong>This " + thing
+              + " requires API level " + minLevel + " or higher.</strong></p>"
+              + "<p>This document is hidden because your selected API level for the documentation is "
+              + selectedLevel + ". You can change the documentation API level with the selector "
+              + "above the left navigation.</p>"
+              + "<p>For more information about specifying the API level your app requires, "
+              + "read <a href='" + toRoot + "training/basics/supporting-devices/platforms.html'"
+              + ">Supporting Different Platform Versions</a>.</p>"
+              + "<input type='button' value='OK, make this page visible' "
+              + "title='Change the API level to " + minLevel + "' "
+              + "onclick='$(\"#apiLevelSelector\").val(\"" + minLevel + "\");changeApiLevel();' />"
+              + "</div>");
   } else {
     $("#naMessage").hide();
   }
diff --git a/tools/droiddoc/templates-sdk/docpage.cs b/tools/droiddoc/templates-sdk/docpage.cs
index 63abceb..3feb00f 100644
--- a/tools/droiddoc/templates-sdk/docpage.cs
+++ b/tools/droiddoc/templates-sdk/docpage.cs
@@ -7,7 +7,8 @@
   elif:about ?>about<?cs
   elif:design ?>design<?cs
   elif:distribute ?>distribute<?cs
-  /if ?>" itemscope itemtype="http://schema.org/Article">
+  /if ?><?cs
+  if:page.trainingcourse ?> trainingcourse<?cs /if ?>" itemscope itemtype="http://schema.org/Article">
 <a name="top"></a>
 <?cs include:"header.cs" ?>
 
@@ -16,7 +17,7 @@
 ?>class="col-13" id="doc-col"<?cs else 
 ?>class="col-12" id="doc-col"<?cs /if ?> >
 
-<?cs if:(design||training||walkthru) ?><?cs # header logic for docs that provide previous/next buttons ?>
+<?cs if:(design||training||walkthru) && !page.trainingcourse ?><?cs # header logic for docs that provide previous/next buttons ?>
   <?cs if:header.hide ?>
   <?cs else ?>
   <div class="layout-content-row content-header <?cs if:header.justLinks ?>just-links<?cs /if ?>">
@@ -51,16 +52,8 @@
             ja-lang="開始する"
             es-lang="Empezar"               
             >Get started</a>
-        <a href="#" class="start-course-link hide"
-            zh-TW-lang="第一堂課"
-            zh-CN-lang="第一课"
-            ru-lang="Первый урок"
-            ko-lang="첫 번째 강의"
-            ja-lang="最初のクラス"
-            es-lang="Primera clase"               
-            >First class</a>
       </div>
-    <?cs else ?>
+    <?cs elif:!page.trainingcourse ?>
       <div class="paging-links layout-content-col span-4" itemscope itemtype="http://schema.org/SiteNavigationElement">
         <a href="#" class="prev-page-link hide"
             zh-TW-lang="上一堂課"
@@ -101,7 +94,17 @@
         <?cs /if ?>
       </div>
     <?cs else ?>
-      <h1 itemprop="name"><?cs var:page.title ?></h1>
+      <?cs if:tab1 ?><div id="title-tabs-wrapper"><?cs /if ?>
+        <h1 itemprop="name" <?cs if:tab1 ?>class="with-title-tabs"<?cs /if ?>><?cs var:page.title ?></h1><?cs
+          if:tab1 ?><ul id="title-tabs">
+              <li class="selected"><a href="<?cs var:tab1.link ?>"><?cs var:tab1 ?></a></li>
+              <?cs if:tab2 ?>
+              <li><a href="<?cs var:tab2.link ?>"><?cs var:tab2 ?></a></li><?cs /if ?>
+              <?cs if:tab3 ?>
+              <li><a href="<?cs var:tab3.link ?>"><?cs var:tab3 ?></a></li><?cs /if ?>
+            </ul>
+          <?cs /if ?>
+      <?cs if:tab1 ?></div><!-- end tab-wrapper --><?cs /if ?>
     <?cs /if ?>
   <?cs /if ?>
 <?cs /if ?><?cs # end if design ?>
@@ -128,7 +131,7 @@
         </div>
         <?cs if:!fullscreen ?>
         <div class="paging-links layout-content-col col-4">
-          <?cs if:(design||training||guide||walkthru) && !page.landing && !footer.hide ?>
+          <?cs if:(design||training||guide||walkthru) && !page.landing && !page.trainingcourse && !footer.hide ?>
             <a href="#" class="prev-page-link hide"
                 zh-TW-lang="上一堂課"
                 zh-CN-lang="上一课"
diff --git a/tools/droiddoc/templates-sdk/package.cs b/tools/droiddoc/templates-sdk/package.cs
index e246e31..ea676b9 100644
--- a/tools/droiddoc/templates-sdk/package.cs
+++ b/tools/droiddoc/templates-sdk/package.cs
@@ -8,7 +8,7 @@
   elif:design ?>design<?cs
   elif:distribute ?>distribute<?cs
   /if ?>">
-  <div id="doc-api-level" class="<?cs var:class.since ?>" style="display:none"></div>
+  <div id="doc-api-level" class="<?cs var:package.since ?>" style="display:none"></div>
   <a name="top"></a>
 <?cs include:"header.cs" ?>
 
diff --git a/tools/droiddoc/templates-sdk/sdkpage.cs b/tools/droiddoc/templates-sdk/sdkpage.cs
index 8de6668..170231f 100644
--- a/tools/droiddoc/templates-sdk/sdkpage.cs
+++ b/tools/droiddoc/templates-sdk/sdkpage.cs
@@ -76,7 +76,6 @@
 #
 ?>
 
-
   <table class="download" id="download-table">
     <tr>
       <th>Platform</th>
@@ -87,16 +86,16 @@
   <tr>
     <td>Windows</td>
     <td>
-  <a onClick="_gaq.push(['_trackEvent', 'Tools', 'Download NDK', 'Link <' + <?cs var:ndk.win_download ?> + '>']);"
+  <a onClick="return onDownload(this)"
      href="http://dl.google.com/android/ndk/<?cs var:ndk.win_download ?>"><?cs var:ndk.win_download ?></a>
     </td>
     <td><?cs var:ndk.win_bytes ?> bytes</td>
     <td><?cs var:ndk.win_checksum ?></td>
   </tr>
-  <tr class="alt-color">
+  <tr>
     <td>Mac OS X (intel)</td>
     <td>
-  <a onClick="_gaq.push(['_trackEvent', 'Tools', 'Download NDK', 'Link <' + <?cs var:ndk.mac_download ?> + '>']);"
+  <a onClick="return onDownload(this)"
      href="http://dl.google.com/android/ndk/<?cs var:ndk.mac_download ?>"><?cs var:ndk.mac_download ?></a>
     </td>
     <td><?cs var:ndk.mac_bytes ?> bytes</td>
@@ -105,7 +104,7 @@
   <tr>
     <td>Linux 32/64-bit (x86)</td>
     <td>
-  <a onClick="_gaq.push(['_trackEvent', 'Tools', 'Download NDK', 'Link <' + <?cs var:ndk.linux_download ?> + '>']);"
+  <a onClick="return onDownload(this)"
      href="http://dl.google.com/android/ndk/<?cs var:ndk.linux_download ?>"><?cs var:ndk.linux_download ?></a>
     </td>
     <td><?cs var:ndk.linux_bytes ?> bytes</td>
@@ -116,6 +115,56 @@
   <?cs ########  HERE IS THE JD DOC CONTENT ######### ?>
   <?cs call:tag_list(root.descr) ?>
 
+
+  
+<script>
+  function onDownload(link) {
+
+    $("#downloadForRealz").html("Download " + $(link).text());
+    $("#downloadForRealz").attr('href',$(link).attr('href'));
+
+    $("#tos").fadeIn('slow');
+
+    location.hash = "download";
+    return false;
+  }
+
+
+  function onAgreeChecked() {
+    if ($("input#agree").is(":checked")) {
+      $("a#downloadForRealz").removeClass('disabled');
+    } else {
+      $("a#downloadForRealz").addClass('disabled');
+    }
+  }
+
+  function onDownloadNdkForRealz(link) {
+    if ($("input#agree").is(':checked')) {
+      $("#tos").fadeOut('slow');
+      
+      $('html, body').animate({
+          scrollTop: $("#Installing").offset().top
+        }, 800, function() {
+          $("#Installing").click();
+      });
+     
+      return true;
+    } else {
+      $("label#agreeLabel").parent().stop().animate({color: "#258AAF"}, 200,
+        function() {$("label#agreeLabel").parent().stop().animate({color: "#222"}, 200)}
+      );
+      return false;
+    }
+  }
+
+  $(window).hashchange( function(){
+    if (location.hash == "") {
+      location.reload();
+    }
+  });
+
+</script>
+
   <?cs else ?>
 <?cs # end if NDK ... 
 #
@@ -138,8 +187,74 @@
 <?cs ########  HERE IS THE JD DOC CONTENT FOR ONLINE ######### ?>
 <?cs call:tag_list(root.descr) ?>
 
-<div class="wrap">
-<div class="pax col-13 online" style="display:none">
+
+
+
+<h4><a href='' class="expandable"
+  onclick="toggleExpandable(this,'.pax');hideExpandable('.myide,.reqs');return false;"
+  >DOWNLOAD FOR OTHER PLATFORMS</a></h4>
+  
+  
+<div class="pax col-13 online" style="display:none;margin:0;">
+
+  
+<p class="table-caption"><strong>ADT Bundle</strong></p>
+  <table class="download">
+    <tr>
+      <th>Platform</th>
+      <th>Package</th>
+      <th>Size</th>
+      <th>MD5 Checksum</th>
+  </tr>
+  <tr>
+    <td>Windows 32-bit</td>
+    <td>
+  <a onClick="return onDownload(this)" id="win-bundle32"
+     href="http://dl.google.com/android/adt/<?cs var:sdk.win32_bundle_download ?>"><?cs var:sdk.win32_bundle_download ?></a>
+    </td>
+    <td><?cs var:sdk.win32_bundle_bytes ?> bytes</td>
+    <td><?cs var:sdk.win32_bundle_checksum ?></td>
+  </tr>
+  <tr>
+    <td>Windows 64-bit</td>
+    <td>
+  <a onClick="return onDownload(this)" id="win-bundle64"
+     href="http://dl.google.com/android/adt/<?cs var:sdk.win64_bundle_download ?>"><?cs var:sdk.win64_bundle_download ?></a>
+    </td>
+    <td><?cs var:sdk.win64_bundle_bytes ?> bytes</td>
+    <td><?cs var:sdk.win64_bundle_checksum ?></td>
+  </tr>
+  <tr>
+    <td><nobr>Mac OS X 64-bit</nobr></td>
+    <td>
+  <a onClick="return onDownload(this)" id="mac-bundle64"
+     href="http://dl.google.com/android/adt/<?cs var:sdk.mac64_bundle_download ?>"><?cs var:sdk.mac64_bundle_download ?></a>
+    </td>
+    <td><?cs var:sdk.mac64_bundle_bytes ?> bytes</td>
+    <td><?cs var:sdk.mac64_bundle_checksum ?></td>
+  </tr>
+  <tr>
+    <td>Linux 32-bit</td>
+    <td>
+  <a onClick="return onDownload(this)" id="linux-bundle32"
+     href="http://dl.google.com/android/adt/<?cs var:sdk.linux32_bundle_download ?>"><?cs var:sdk.linux32_bundle_download ?></a>
+    </td>
+    <td><?cs var:sdk.linux32_bundle_bytes ?> bytes</td>
+    <td><?cs var:sdk.linux32_bundle_checksum ?></td>
+  </tr>
+  <tr>
+    <td>Linux 64-bit</td>
+    <td>
+  <a onClick="return onDownload(this)" id="linux-bundle64"
+     href="http://dl.google.com/android/adt/<?cs var:sdk.linux64_bundle_download ?>"><?cs var:sdk.linux64_bundle_download ?></a>
+    </td>
+    <td><?cs var:sdk.linux64_bundle_bytes ?> bytes</td>
+    <td><?cs var:sdk.linux64_bundle_checksum ?></td>
+  </tr>
+  </table>
+
+
+<p class="table-caption"><strong>SDK Tools Only</strong></p>
   <table class="download">
     <tr>
       <th>Platform</th>
@@ -150,7 +265,7 @@
   <tr>
     <td rowspan="2">Windows</td>
     <td>
-  <a onclick="onDownload(this,false)" href="http://dl.google.com/android/<?cs var:sdk.win_download
+  <a onclick="return onDownload(this)" href="http://dl.google.com/android/<?cs var:sdk.win_download
 ?>"><?cs var:sdk.win_download ?></a>
     </td>
     <td><?cs var:sdk.win_bytes ?> bytes</td>
@@ -159,17 +274,17 @@
   <tr>
     <!-- blank TD from Windows rowspan -->
     <td>
-  <a onclick="onDownload(this,false)" id="win-sdk" href="http://dl.google.com/android/<?cs
+  <a onclick="return onDownload(this)" id="win-tools" href="http://dl.google.com/android/<?cs
 var:sdk.win_installer
 ?>"><?cs var:sdk.win_installer ?></a> (Recommended)
     </td>
     <td><?cs var:sdk.win_installer_bytes ?> bytes</td>
     <td><?cs var:sdk.win_installer_checksum ?></td>
   </tr>
-  <tr class="alt-color">
-    <td>Mac OS X (intel)</td>
+  <tr>
+    <td>Mac OS X</td>
     <td>
-  <a onclick="onDownload(this,false)" id="mac-sdk" href="http://dl.google.com/android/<?cs
+  <a onclick="return onDownload(this)" id="mac-tools" href="http://dl.google.com/android/<?cs
 var:sdk.mac_download
 ?>"><?cs var:sdk.mac_download ?></a>
     </td>
@@ -177,9 +292,9 @@
     <td><?cs var:sdk.mac_checksum ?></td>
   </tr>
   <tr>
-    <td>Linux (i386)</td>
+    <td>Linux</td>
     <td>
-  <a onclick="onDownload(this,false)" id="linux-sdk" href="http://dl.google.com/android/<?cs
+  <a onclick="return onDownload(this)" id="linux-tools" href="http://dl.google.com/android/<?cs
 var:sdk.linux_download
 ?>"><?cs var:sdk.linux_download ?></a>
     </td>
@@ -187,50 +302,144 @@
     <td><?cs var:sdk.linux_checksum ?></td>
   </tr>
   </table>
+
+</div><!-- end pax -->
+
+
+
+</div><!-- end col-13 for lower-half content -->
+  
+  
   
   
 <script>
-  function onDownload(link,fromButton) {
-    $("#filename").text($(link).html());
-    $("#next-steps").fadeIn('slow');
-    $("#intro").fadeOut('slow');
-    $('.pax').slideUp();
-    $('.reqs').slideUp();
-    // Deliver Analytics event
-    if (fromButton) {
-      _gaq.push(['_trackEvent', 'Tools', 'Download SDK', 'Button <' + text($(link).html()) + '>']);
-    } else {
-      _gaq.push(['_trackEvent', 'Tools', 'Download SDK', 'Link <' + text($(link).html()) + '>']);
-    }
+  if (location.hash == "#Requirements") {
+    $('.reqs').show();
+  } else if (location.hash == "#ExistingIDE") {
+	 $('.ide').show();
   }
-  
-  
+
   var os;
-  var $link;
+  var bundlename;
+  var $toolslink;
+
   if (navigator.appVersion.indexOf("Win")!=-1) {
     os = "Windows";
-    $link = $('#win-sdk');
+    bundlename = '#win-bundle';
+    $toolslink = $('#win-tools');
   } else if (navigator.appVersion.indexOf("Mac")!=-1) {
     os = "Mac";
-    $link = $('#mac-sdk');
+    bundlename = '#mac-bundle';
+    $toolslink = $('#mac-tools');
   } else if (navigator.appVersion.indexOf("Linux")!=-1) {
     os = "Linux";
-    $link = $('#linux-sdk');
+    bundlename = '#linux-bundle';
+    $toolslink = $('#linux-tools');
   }
 
   if (os) {
     $('#not-supported').hide();
-    $('#download-button').show();
-    $('#download-button').text("Download the SDK for " + os);
-    $('#download-button').click(function() {onDownload($link.get());}).attr('href', $link.attr('href'),true);
+
+    /* set up primary adt download button */
+    $('#download-bundle-button').show();
+    $('#download-bundle-button').append("Download the SDK <br/><span class='small'>ADT Bundle for " + os + "</span>");
+    $('#download-bundle-button').click(function() {return onDownload(this,true,true);}).attr('href', bundlename);
+
+    /* set up sdk tools only button */
+    $('#download-tools-button').show();
+    $('#download-tools-button').append("Download the SDK Tools for " + os);
+    $('#download-tools-button').click(function() {return onDownload(this,true);}).attr('href', $toolslink.attr('href'));
   } else {
     $('.pax').show();
   }
+  
+  
+  function onDownload(link, button, bundle) {
+  
+    /* set text for download button */
+    if (button) {
+      $("#downloadForRealz").html($(link).text());
+    } else {
+      $("#downloadForRealz").html("Download " + $(link).text());
+    }
+    
+    /* if it's a bundle, show the 32/64-bit picker */
+    if (bundle) {
+      $("#downloadForRealz").attr('bundle','true');
+      if ($("#downloadForRealz").text().indexOf("Mac") == -1) {
+        $("p#bitpicker").show();
+      } else {
+        /* mac is always 64 bit, so set it checked */
+        $("p#bitpicker input[value=64]").attr('checked', true);
+      }
+      /* save link name until the bit version is chosen */
+      $("#downloadForRealz").attr('name',$(link).attr('href'));
+    } else {
+      /* if not using bundle, set download button to ignore bitpicker and set url */
+      $("#downloadForRealz").attr('bundle','false');
+      $("#downloadForRealz").attr('href',$(link).attr('href'));
+      /* set picker checked as a fake default */
+      $("p#bitpicker input[value=64]").attr('checked', true);
+      $("a#next-link").html("Setting Up an Existing IDE").attr('href',toRoot + 'sdk/installing/index.html');
+    }
+
+    $("#tos").fadeIn('fast');
+    $("#landing").fadeOut('fast');
+
+    location.hash = "download";
+    return false;
+  }
+
+
+  function onAgreeChecked() {
+    /* verify that the TOS is agreed and a bit version is chosen */
+    if ($("input#agree").is(":checked") && $("#bitpicker input:checked").length) {
+      
+      /* if downloading the bundle */
+      if ($("#downloadForRealz").attr('bundle')) {
+        /* construct the name of the link we want based on the bit version */
+        linkId = $("a#downloadForRealz").attr("name") + $("#bitpicker input:checked").val();
+        /* set the real url for download */
+        $("a#downloadForRealz").attr("href", $(linkId).attr("href"));
+      }
+      
+      /* reveal the download button */
+      $("a#downloadForRealz").removeClass('disabled');
+    } else {
+      $("a#downloadForRealz").addClass('disabled');
+    }
+  }
+
+  function onDownloadForRealz(link) {
+    if ($("input#agree").is(':checked') && $("#bitpicker input:checked").length) {
+      $("div.sdk-terms").slideUp();
+      $("#sdk-terms-form,.sdk-terms-intro").fadeOut('slow');
+      $("#next-steps").fadeIn('slow');
+      $("h1#tos-header").text('Get Ready to Code!');
+      return true;
+    } else {
+      $("label#agreeLabel,#bitpicker input").parent().stop().animate({color: "#258AAF"}, 200,
+        function() {$("label#agreeLabel,#bitpicker input").parent().stop().animate({color: "#222"}, 200)}
+      );
+      return false;
+    }
+  }
+
+  $(window).hashchange( function(){
+    if (location.hash == "") {
+      location.reload();
+    }
+  });
 
 </script>
 
-</div><!-- end pax -->
-</div><!-- end wrap -->
+
+
+</div><!-- end the wrapper used for relative/absolute positions  -->
+<?cs # THIS DIV WAS OPENED IN INDEX.JD ?>
+
+
+
 
   <?cs else ?> <?cs # end if online ?>