﻿var openedCategory = 0;
var ajax = null;
var l2 = 0;
var l3 = 0;

function expandCategory(categoryID) {
  // Make sure that we have a category ID and that it points to a valid DIV to expand
  var d = document.getElementById("category" + categoryID);
  if(categoryID < 1 || !categoryID || d == null)
    return false;
          
  // Close the previously opened category, if any
  if(openedCategory > 0) {
    var dd = document.getElementById("category" + openedCategory);
    dd.style.display = 'none';
  }
        
  // Display the given category
  d.style.display = 'inline';
  
  // Take away the red area for the previous category
  var e = document.getElementById('c' + openedCategory);
  if(e == null) return;
  e.className = "";
  
       
  // Mark that the category has been displayed
  openedCategory = categoryID;

  // Add red highlighting for the new category
  var e = document.getElementById('c' + openedCategory);
  if(e == null) return;
  e.className = "active";
        
  return false;
}

function loadVideo(filename) {
  if(!filename) return;
  
  filename = "videos/" + filename;
  
  var player = document.getElementById('player');
  var playertd = document.getElementById('playertd');
  if(player == null) return;
  
  var n = document.createElement('EMBED');
  n.src = filename;
  n.autoplay = "no";
  n.height = 160;
  n.width = 250;
  n.id = "player";
  
  playertd.removeChild(player);
  playertd.appendChild(n);  
}

function getNavigation(levelTwoID, levelThreeID) {
  var str;
  l2 = levelTwoID;
  l3 = levelThreeID;
  if(levelTwoID && levelThreeID) { // Have both, getting fourth-level
    str = "type=4L4N&id=" + levelThreeID;
    ajax = new Ajax.Request("categoryhelper.aspx", {method:'get', parameters: str, asynchronous: true, evalScripts: true, onComplete:getBack4LNav});    
  } else if(levelTwoID) { // Have second, getting third
    str = "type=3L4N&id=" + levelTwoID;
    ajax = new Ajax.Request("categoryhelper.aspx", {method:'get', parameters: str, asynchronous: true, evalScripts: true, onComplete:getBack3LNav});    
  }
}

function getBack4LNav() {
  return;  // THIS DOES NOT WORK YET.  FIX ME!!!
  
  
  
  var idLine = "id=" + openedCategory + ";" + l2 + ";" + l3 + ";";
  var allURLS = "";

  var options = ajax.transport.responseText.split("\n");
  for(var i = 0; i < options.length; i++) {
    var temp = options[i].split("|");
    var id = temp[0];     var type = temp[1];    var name = temp[2];
    
    var tmpIDLine = idLine + id + ";0";
    
    var url = "<LI><A HREF=\"index.aspx?" + tmpIDLine + "\">" + name + "</A></LI>\n";
    allURLS += url;
  }
  
  if(allURLS)
    allURLS = "<ul class=\"subSections\">\n" + allURLS + "\n<div style=\"clear: both;\"></div></ul><BR><BR>";
    
  var ctrl = document.getElementById('subSubNavigation');
  if(ctrl == null) return;
  ctrl.innerHTML = allURLS;
  ctrl.style.display = "block";
}

function getBack3LNav() {
  var idLine = "id=" + openedCategory + ";" + l2 + ";"
  var allURLS = "";

  var options = ajax.transport.responseText.split("\n");
  for(var i = 0; i < options.length; i++) {
    var temp = options[i].split("|");
    var id = temp[0];     var type = temp[1];    var name = temp[2];
    
    var tmpIDLine = idLine + id + ";0";
    
    var onc = "";
    if(type == "CONTAINER")
      onc = " onClick=\"getNavigation(" + l2 + "," + id +");  return false;\"";
    
    var url = "<LI><A HREF=\"index.aspx?" + tmpIDLine + "\"" + onc + ">" + name + "</A></LI>\n";
    allURLS += url;
  }
  
  if(allURLS)
    allURLS = "<ul class=\"sections\">\n" + allURLS + "\n" + "<div id=\"subSubNavigation\"></div><div style=\"clear: both;\"></div></ul><BR><BR>";
    
  var ctrl = document.getElementById('subNavigation');
  if(ctrl == null) return;
  ctrl.innerHTML = allURLS;
  ctrl.style.display = "block";
}
