function Array_indexOf(array, item, fromIndex) {
  var length = array.length;
  if (fromIndex == null) {
    fromIndex = 0;
  } else if (fromIndex < 0) {
    fromIndex = Math.max(0, length + fromIndex);
  }
  for (var i = fromIndex; i < length; i++) {
    if (array[i] === item) return i;
  }
  return -1;
};

function toggleMe(ele) {
  var e = ele.parentNode;
  e.className = (e.className == 'active')? 'inactive' : 'active';
}

function nextPage() {
  document.location = (document.location.href+'').replace(/(.*)\/.*$/,'$1/'+ currentPage.nextModule +'.html');
  return false;
}

function prevPage() {
  document.location = (document.location.href+'').replace(/(.*)\/.*$/,'$1/'+ currentPage.prevModule +'.html');
  return false;
}


/*
 * HOW TO ADD MORE MODULES
 * 
 * 1) Make a duplicate of any of the mod*.html files.
 *    Change the ID attribute of the body tag to the root filename you chose.
 * 
 * 2) To hook up the SIDEBAR:
 *    Duplicate one of the LI.ins blocks in the sidebar of all files.
 *    Add all your new links to this block.
 *    Add a unique ID to it.
 *    Change the className of the BODY tag to be 
 *        the same keyword as the ID of your new sidebar section
 *        only for the pages that you want to default to open that section.
 * 
 * 4) Make sure the LI tag around every link in the sidebar 
 *    has an ID tag the same as the root filename of the file it links to, plus the letter "l"
 *    EG: <li id="mylinkl"><a href="mylink.html">MyLink </a></li>
 * 
 * 3) To hook up the NEXT / PREV functionality:
 *    Add the root filename of the new files into the ModulePages array.
 * 
 * 4) To hook up the FLASH:
 *    Add a new "case" row to the switch statement. 
 *    Replace all the values with the correct values for your new page.
 * 
 */


var ModulePages = [
  'index'
  ,"mod1_1","mod1_2","mod1_3","mod1_4","mod1_5","mod1_6","mod1_7","mod1_8","mod1_9","mod1_10","mod1_11","mod1_12","mod1_13"
  //,"mod2_1"//,"mod2_2","mod2_3","mod2_4","mod2_5","mod2_6"
  //,"mod3_1"//,"mod3_2","mod3_3","mod3_4","mod3_5"
  //,"mod4_1","mod4_2","mod4_3"//,"mod4_4","mod4_5"
  //,"mod5_1","mod5_2"//,"mod5_3","mod5_4","mod5_5"
  //,"mod6_1","mod6_2"//,"mod6_3","mod6_4","mod6_5"
  //,"mod7_1"
];


var currentPage = {};
var theFlash;
function init() {if (!document.getElementById) return false;
  
  var bod = document.getElementsByTagName('body')[0];
  
  currentPage.raw        = bod.getAttribute('id');
  currentPage.prevModule = ModulePages[Array_indexOf(ModulePages, currentPage.raw)-1] || ModulePages[ModulePages.length-1];
  currentPage.nextModule = ModulePages[Array_indexOf(ModulePages, currentPage.raw)+1] || ModulePages[0];
  
  try{document.getElementById(bod.className).className='active';}catch(e){};// This turns on the element with the same ID as the className of the BODY
  try{document.getElementById(bod.id +'l').className='on';}catch(e){};// This turns on the link whose ID starts the same as the ID of the BODY
  
  switch(currentPage.raw)
  {
    
    case 'mod1_2': theFlash = new SWFObject("http://video.serena.com/serenacourseware/mariner/getting_started/navigating_ui/navigating_ui_skin.swf"			  , "flash0", "721", "571", "7", "#000000"); break;
    case 'mod1_3': theFlash = new SWFObject("http://video.serena.com/serenacourseware/mariner/getting_started/default_users/default_users_skin.swf"           , "flash0", "721", "571", "7", "#000000"); break;
    case 'mod1_4': theFlash = new SWFObject("administrator/new_user/new_user_skin.swf"        		          , "flash0", "721", "571", "7", "#000000"); break;
    case 'mod1_5': theFlash = new SWFObject("http://video.serena.com/serenacourseware/mariner/portfolio_manager/visibility/visibility_skin.swf"             , "flash0", "721", "571", "7", "#000000"); break;
    case 'mod1_6': theFlash = new SWFObject("http://video.serena.com/serenacourseware/mariner/project_manager/create_project/create_project_skin.swf" 		  , "flash0", "721", "571", "7", "#000000"); break;
    case 'mod1_7': theFlash = new SWFObject("http://video.serena.com/serenacourseware/mariner/project_manager/task_plan/task_plan_skin.swf"                   , "flash0", "721", "571", "7", "#000000"); break;
    case 'mod1_8': theFlash = new SWFObject("http://video.serena.com/serenacourseware/mariner/project_manager/import_msp/import_msp_skin.swf"                 , "flash0", "721", "571", "7", "#000000"); break;
    case 'mod1_9': theFlash = new SWFObject("http://video.serena.com/serenacourseware/mariner/resource_manager/utilization/utilization_skin.swf"              , "flash0", "721", "571", "7", "#000000"); break;
    case 'mod1_10': theFlash = new SWFObject("http://video.serena.com/serenacourseware/mariner/individual_contributor/timesheets/timesheets_skin.swf"          , "flash0", "721", "571", "7", "#000000"); break;
	case 'mod1_11': theFlash = new SWFObject("http://video.serena.com/serenacourseware/mariner/executive/viewing_reports/viewing_reports_skin.swf"             , "flash0", "721", "571", "7", "#000000"); break;
	case 'mod1_12': theFlash = new SWFObject("http://video.serena.com/serenacourseware/mariner/administrator/xcelerator/xcelerator_skin.swf"          		   , "flash0", "721", "571", "7", "#000000"); break;
	case 'mod1_13': theFlash = new SWFObject("http://video.serena.com/serenacourseware/mariner/administrator/widget_space/widget_space_skin.swf"          	   , "flash0", "721", "571", "7", "#000000"); break;
	default : theFlash = null;
  }
  if (theFlash) theFlash.write('flash');
}
