
  /* FamilyFun.com navigation (javascript version)
   * Developed by Nazaret Aslanian for Disney Online.
   */

  
  /* nav data
  ================================================================================================================== */
  
  // NOTE - all apostrophes (') in the data should be replaced with &#146; for a curved apostrophe *Note the &#39; for the straight apostrophe causes javascript errors
  
  var nav = [

    [ "crafts", "http://familyfun.go.com/arts-and-crafts/", "left", [
        [ "Holiday & Seasonal", "http://familyfun.go.com/arts-and-crafts/season/" ],
        [ "Crafts by Age", "http://familyfun.go.com/arts-and-crafts/crafts-by-age" ],
        [ "Quick & Easy", "http://familyfun.go.com/arts-and-crafts/quick-and-easy" ],
        [ "Classroom", "http://familyfun.go.com/arts-and-crafts/classroom" ],
        [ "Kids&#146; Room", "http://familyfun.go.com/arts-and-crafts/kids-rooms" ],
        [ "How-to Videos", "http://familyfun.go.com/utilities/global/feature/fftv-archive-video-player/" ],
        [ "Search All Crafts", "http://familyfun.go.com/arts-and-crafts/season/tool/craftfinder_tlp/" ]
      ]
    ],

    [ "parties", "http://familyfun.go.com/parties/", "left", [
        [ "Birthdays", "http://familyfun.go.com/parties/birthday/" ],
        [ "Parties by Age", "http://familyfun.go.com/parties/parties-by-age/" ],
        [ "Party Themes", "http://familyfun.go.com/parties/party-themes/" ],
        [ "Party Games", "http://familyfun.go.com/parties/party-games/" ],
        [ "Holiday &amp; Seasonal", "http://familyfun.go.com/parties/holiday-seasonal/" ],
        [ "Search All Parties", "http://familyfun.go.com/parties/birthday/tool/partyplanner_tlp/" ]
      ]
    ],

    [ "recipes", "http://familyfun.go.com/recipes/", "left", [
        [ "Quick Dinners", "http://familyfun.go.com/recipes/quickdinners/" ],
        [ "Cooking with Kids", "http://familyfun.go.com/recipes/kids/" ],
        [ "Cakes & Cupcakes", "http://familyfun.go.com/recipes/cakescupcakes/" ],
        [ "Holiday & Seasonal", "http://familyfun.go.com/recipes/special/" ],
        [ "How-to Videos", "http://familyfun.go.com/utilities/global/feature/fftv-archive-video-player/" ],
        [ "Search All Recipes", "http://familyfun.go.com/recipes/family/tool/RecipeFinder/" ]
      ]
    ],

    [ "games", "http://familyfun.go.com/games/", "left", [
        [ "Indoor & Outdoor Games", "http://familyfun.go.com/games/indoor-outdoor-games/" ],
        [ "Holiday Games", "http://familyfun.go.com/games/holiday-games/" ],
        [ "Birthday & Party Games", "http://familyfun.go.com/games/birthday-party-games/" ],
        [ "Games by Age", "http://familyfun.go.com/games/games-by-age/" ],
        [ "Online Games", "http://familyfun.go.com/games/online-games/gamesindex/classic-games/" ],
        [ "Search All Games", "http://familyfun.go.com/games/indoor-outdoor-games/tool/game_finder_tlp/" ]
      ]
    ],

    [ "travel", "http://familyfun.go.com/family-travel/", "left", [
        [ "Destinations", "http://familyfun.go.com/family-travel/places/" ],
        [ "Activities & Attractions", "http://familyfun.go.com/family-travel/road-trips/" ],
        [ "Disney Vacations", "http://familyfun.go.com/family-travel/disney/specialfeature/disneytravel_tlp/" ],
        [ "Camping Trips", "http://familyfun.go.com/family-travel/places/specialfeature/camping/" ],
        [ "Your Great Vacations", "http://familyfun.go.com/family-travel/your-great-vacations/" ],
        [ "Search All Travel", "http://familyfun.go.com/family-travel/places/tool/vacationfinder_tlp/" ]
      ]
    ],

    [ "printables", "http://familyfun.go.com/printables/", "left", [
        [ "Coloring Pages", "http://familyfun.go.com/printables/coloring-pages" ],
        [ "Games & Puzzles", "http://familyfun.go.com/printables/games/" ],
        [ "Paper Crafts", "http://familyfun.go.com/printables/craft-templates/" ],
        [ "Holiday & Seasonal", "http://familyfun.go.com/printables/season/" ]
      ]
    ],

    [ "halloween", "http://familyfun.go.com/halloween/", "left", [
        [ "New This Year", "http://familyfun.go.com/arts-and-crafts/season/specialfeature/new-halloween-costumes-treats/" ],
        [ "Costumes", "http://familyfun.go.com/arts-and-crafts/season/specialfeature/halloween_ms_costumes/" ],
        [ "Creepy Cuisine", "http://familyfun.go.com/recipes/special/specialfeature/halloween_ms_food/" ],
        [ "Haunted Crafts", "http://familyfun.go.com/arts-and-crafts/season/specialfeature/halloween_ms_crafts/" ],
        [ "Pumpkin Carving", "http://familyfun.go.com/arts-and-crafts/season/specialfeature/halloween_ms_pumpkins/" ],
        [ "Spooky Printables", "http://familyfun.go.com/printables/season/specialfeature/halloween-printables-ms/" ],
        [ "All Holidays", "http://familyfun.go.com/holidays/" ] 
      ]
    ],

    [ "how-to videos", "http://familyfun.go.com/utilities/global/feature/fftv-archive-video-player/", "right", [
        [ "Featured Playlist", "http://familyfun.go.com/utilities/global/feature/fftv-archive-video-player/fftv-archive-video-player.html?dl_section=featured" ],
        [ "Top 10", "http://familyfun.go.com/utilities/global/feature/fftv-archive-video-player/fftv-archive-video-player.html?dl_section=mostviewed" ],
        [ "Budget Crafts", "http://familyfun.go.com/utilities/global/feature/fftv-archive-video-player/fftv-archive-video-player.html?dl_section=channel&dl_channel=FamilyFun%20Minute" ],
        [ "Cakes & Cupcakes", "http://familyfun.go.com/utilities/global/feature/fftv-archive-video-player/fftv-archive-video-player.html?dl_section=channel&dl_channel=Cakes%20and%20Cupcakes" ],
        [ "Crafts & Activities", "http://familyfun.go.com/utilities/global/feature/fftv-archive-video-player/fftv-archive-video-player.html?dl_section=channel&dl_channel=At%20the%20Craft%20Table" ],
        [ "Holiday Recipes", "http://familyfun.go.com/utilities/global/feature/fftv-archive-video-player/fftv-archive-video-player.html?dl_section=channel&dl_channel=In%20the%20Kitchen" ],
        [ "Halloween", "http://familyfun.go.com/utilities/global/feature/fftv-archive-video-player/fftv-archive-video-player.html?dl_section=channel&dl_channel=Halloween" ]
      ]
    ],

    [ "magazine", "http://familyfun.go.com/magazine/", "right", [
        [ "Past Issues", "http://familyfun.go.com/utilities/global/specialfeature/famfunmag_links-arch/" ],
        [ "FAQ", "http://familyfun.go.com/utilities/global/feature/familyfunmag_aboutmag/familyfunmag_aboutmag.html" ],
        [ "Reader Panel", "http://familyfun.go.com/utilities/global/feature/familyfunmag_aboutmag/familyfunmag_aboutmag.html#panel" ],
        [ "Advertising", "http://familyfun.go.com/arts-and-crafts/season/feature/familyfun-media-kit/" ],
        [ "Subscription Help", "https://w1.buysub.com/servlet/CSGateway?cds_mag_code=FAF" ],
        [ "Subscribe Now", "https://w1.buysub.com/servlet/OrdersGateway?cds_mag_code=FAF&cds_page_id=39095&cds_response_key=I9FWW2" ]
      ]
    ]
  ];



  // data starts from 1 (instead of 0) - this will be adjusted in function setActiveTabs
  var highlighting = [
  
    [ 7, 1, "/arts-and-crafts/season/specialfeature/new-halloween-costumes-treats/" ],
    [ 7, 2, "/arts-and-crafts/season/specialfeature/halloween_ms_costumes/" ],
    [ 7, 3, "/recipes/special/specialfeature/halloween_ms_food/" ],
    [ 7, 4, "/arts-and-crafts/season/specialfeature/halloween_ms_crafts/" ],
    [ 7, 5, "/arts-and-crafts/season/specialfeature/halloween_ms_pumpkins/" ],
    [ 7, 6, "/printables/season/specialfeature/halloween-printables-ms/" ],
    [ 7, 7, "/holidays/" ],    
    [ 7, 0, "/halloween/" ],
    [ 9, 4, "/arts-and-crafts/season/feature/familyfun-media-kit/" ],

    [ 8, 1, "/utilities/global/feature/fftv-archive-video-player/fftv-archive-video-player.html?dl_section=featured" ],
    [ 8, 2, "/utilities/global/feature/fftv-archive-video-player/fftv-archive-video-player.html?dl_section=mostviewed" ],
    [ 8, 3, "/utilities/global/feature/fftv-archive-video-player/fftv-archive-video-player.html?dl_section=channel&dl_channel=FamilyFun%20Minute" ],
    [ 8, 4, "/utilities/global/feature/fftv-archive-video-player/fftv-archive-video-player.html?dl_section=channel&dl_channel=Cakes%20and%20Cupcakes" ],
    [ 8, 5, "/utilities/global/feature/fftv-archive-video-player/fftv-archive-video-player.html?dl_section=channel&dl_channel=At%20the%20Craft%20Table" ],
    [ 8, 6, "/utilities/global/feature/fftv-archive-video-player/fftv-archive-video-player.html?dl_section=channel&dl_channel=In%20the%20Kitchen" ],
    [ 8, 7, "/utilities/global/feature/fftv-archive-video-player/fftv-archive-video-player.html?dl_section=channel&dl_channel=Halloween" ],
    [ 8, 0, "/utilities/global/feature/fftv-archive-video-player/" ],

    [ 1, 7, "/arts-and-crafts/season/tool/craftfinder_tlp/" ],
    [ 1, 1, "/arts-and-crafts/season/" ],
    [ 1, 2, "/arts-and-crafts/crafts-by-age" ],
    [ 1, 3, "/arts-and-crafts/quick-and-easy" ],
    [ 1, 4, "/arts-and-crafts/classroom" ],    
    [ 1, 5, "/arts-and-crafts/kids-rooms" ],
    [ 0, 0, "/utilities/global/feature/streaming-test/" ],
    [ 1, 0, "/jas.familyfun.go.com/crafts" ],
    [ 1, 0, "/jas.familyfun.go.com/arts-and-crafts" ],
    [ 1, 0, "/arts-and-crafts/" ],


    [ 2, 6, "/parties/birthday/tool/partyplanner_tlp/" ],
    [ 2, 1, "/parties/birthday/" ],
    [ 2, 2, "/parties/parties-by-age/" ],
    [ 2, 3, "/parties/party-themes/" ],
    [ 2, 4, "/parties/party-games/" ],
    [ 2, 5, "/parties/holiday-seasonal/" ],
    [ 2, 0, "/parties/" ],


    [ 3, 1, "/recipes/quickdinners/" ],
    [ 3, 2, "/recipes/kids/" ],
    [ 3, 3, "/recipes/cakescupcakes/" ],
    [ 3, 4, "/recipes/special/" ],
    [ 0, 0, "/utilities/global/feature/streaming-test/" ],
    [ 3, 6, "/recipes/family/tool/RecipeFinder/" ],
    [ 3, 0, "/jas.familyfun.go.com/recipefinder/" ],
    [ 3, 0, "/recipes/" ],
    [ 3, 0, "http://family.go.com/contests/cake-recipes/" ],


    [ 6, 1, "/printables/coloring-pages" ],
    [ 6, 2, "/printables/games/" ],
    [ 6, 3, "/printables/craft-templates/" ],
    [ 6, 4, "/printables/season/" ],
    [ 6, 0, "/printables/" ],


    [ 4, 6, "/games/indoor-outdoor-games/tool/game_finder_tlp/" ],
    [ 4, 1, "/games/indoor-outdoor-games/" ],
    [ 4, 2, "/games/holiday-games/" ],
    [ 4, 3, "/games/birthday-party-games/" ],
    [ 4, 4, "/games/games-by-age/" ],
    [ 4, 5, "/games/online-games/gamesindex/classic-games/" ],
    [ 4, 0, "/games/" ],


    [ 5, 6, "/family-travel/places/tool/vacationfinder_tlp/" ],
    [ 5, 4, "/family-travel/places/specialfeature/camping/" ],
    [ 5, 1, "/family-travel/places/" ],
    [ 5, 2, "/family-travel/road-trips/" ],
    [ 5, 3, "/family-travel/disney/" ],
    [ 5, 5, "/family-travel/your-great-vacations/" ],
    [ 5, 0, "/family-travel/" ],


    [ 9, 1, "/utilities/global/specialfeature/famfunmag_links-arch/" ],
    [ 9, 2, "/utilities/global/feature/familyfunmag_aboutmag/familyfunmag_aboutmag.html" ],
    [ 9, 3, "/utilities/global/feature/familyfunmag_aboutmag/familyfunmag_aboutmag.html#panel" ],
    [ 9, 4, "/arts-and-crafts/season/feature/familyfun-media-kit/" ],
    [ 9, 0, "/magazine/" ],
    [ 9, 0, "/utilities/global/specialfeature/famfunmag_links_0506/" ]        // special case
  ];




  
  /* EVENT HANDLING SETUP
  ================================================================================================================== */
  
  
  var highlightHandle,                              // callback handles (function pointers)
      unHighlightHandle;
  
  var currentTab;                                   // current top nav tab

  var tabToHighlight,
      tabTo_Un_Highlight;

  var highlightDelay = 250;                         // timer delays
      unHighlightDelay = 850;



  function cancelHighlight() { if( highlightHandle ) clearTimeout( highlightHandle ); }
  function cancelUnHighlight() { if( unHighlightHandle ) clearTimeout( unHighlightHandle ); }


  function startHighlight( tab )
  {
    cancelHighlight();                              // cancel any other highlight that may have been initiated
    cancelUnHighlight();                            /* cancel any un-highlight that may have been initiated (because 
                                                       highlighting has a lower delay than un-highlighting, the current 
                                                       highlighted tab gets unhighlighted without this call - it shouldn't, 
                                                       but the javascript events are a little convoluded) */
    
    tabToHighlight = tab;
    highlightHandle = setTimeout( "highlight()", highlightDelay );
  }



  function startUnHighlight( tab )
  {    
    cancelHighlight();
    cancelUnHighlight();
    
    unHighlightHandle = setTimeout( "unHighlight()", unHighlightDelay );
  }



  function highlight()
  {
    if( currentTab && currentTab.id != tabToHighlight.id )
    {
      //currentTab.className = tabOff;      
      unHighlight();
    }
        
    currentTab = tabToHighlight;    
    if( currentTab.id.charAt( currentTab.id.length - 1 ) != activeTabIndex )       // leave the active tab as is
      currentTab.className = tabOn;
    
    // hide current sub-tab and show this one
    var oldSubTab = document.getElementById( "subTab" + activeTabIndex ),
        newSubTab = document.getElementById( "subTab" + currentTab.id.charAt( tabToHighlight.id.length - 1 ) );
    
    if( oldSubTab ) oldSubTab.style.display = 'none';
    newSubTab.style.display = '';    
    
    highlightHandle = null;                         // we're done with this highlight, so set the handle to null
  }



  function unHighlight() 
  { 
    if( currentTab )
    {
      if( currentTab.id.charAt( currentTab.id.length - 1 ) != activeTabIndex )     // leave the active tab as is
        currentTab.className = tabOff; 
      
      // hide current sub-tab and show active one if exists
      var currentSubTab = document.getElementById( "subTab" + currentTab.id.charAt( tabToHighlight.id.length - 1 ) ),
          activeSubTab = document.getElementById( "subTab" + activeTabIndex );
      
      currentSubTab.style.display = 'none';
      if( activeSubTab ) activeSubTab.style.display = '';
      
      currentTab = null;
    }
    
    unHighlightHandle = null;                         // we're done with this un-highlight, so set the handle to null
  }





  
  /* RENDERING SECTION
  ================================================================================================================== */
  
  var output = "",                    // output will be collected here
      navImagePath,
      commonImagePath;
  
  var activeTabIndex = -1,
      activeSubTabIndex = -1;
  
  var subTabPadding = 18;
  
  if( (window.location.href + "").indexOf( "https://" ) == -1 )
  { 
    output = '<link rel="stylesheet" href="http://familyfun.go.com/DailyResources/css/nav.css" type="text/css">';
    navImagePath = 'http://familyfun.go.com/DailyResources/images/nav/';
    commonImagePath = 'http://familyfun.go.com/Resources/familyfun2005/images/COMMON/';
  }
  else
  {
    output = '<link rel="stylesheet" href="https://global.go.com/secure/familyfun/Resources/nav/nav.css" type="text/css">';
    navImagePath = "https://global.go.com/secure/familyfun/Resources/nav/images/";
    commonImagePath = "https://global.go.com/secure/familyfun/Resources/nav/images/";
  }
  
  
  function render()
  {     
    var topTabClass,                  // CSS variables
        subTabStyle,                  // for entire sub tab (row)
        subTabItemStyle;              // for sub tab item
    
    setActiveTabs();
    
    output += '<table id="' + navID + '" width="100%" cellpadding="0" cellspacing="0" border="0">';
    output += '  <tr>';
    if( wide ) output += '<td width="128" class="navPadding" style="text-align: right !important;"><img src="' + navImagePath + topTabSeparator + '"></td>';
    
    // top level nav
    
    for( i = 0; i < nav.length; i++ )
    {
      topTabClass = ( i == activeTabIndex ) ? tabSelected : tabOff;
    
      output += '<td id="tab' + i + '" class="' + topTabClass + '" onmouseover="try { startHighlight( this ); } catch( err ) {}" onmouseout="try { startUnHighlight( this ); } catch( err ) {}" onclick="flashLinkTrack( \'TopNav/' + nav[ i ][ 0 ] + '\', \'SOLUTIONCENTER\' ); window.location = \'' + nav[ i ][ 1 ] + '\'">&nbsp;<a href="' + nav[ i ][ 1 ] + '">' + nav[ i ][ 0 ] + '</a>&nbsp;</td>';
      
      if( i != nav.length - 1 ) output += '<td class="' + tabOff + '"><img src="' + navImagePath + topTabSeparator + '"></td>';
    }
    
    if( wide ) output += '<td width="128" class="navPadding" style="text-align: left !important;"><img src="' + navImagePath + topTabSeparator + '"></td>';
    output += '  </tr>';
    output += '</table>';
    
    output += '<div id="subNav">';
    
    // 2nd level nav
    
    for( i = 0; i < nav.length; i++ )
    {
      subTabStyle = ( i == activeTabIndex ) ? 'display: ;' : 'display: none;';
      
      output += '<div onmouseover="try { cancelUnHighlight(); } catch( err ) {}" onmouseout="try { startUnHighlight( document.getElementById( \'tab' + i + '\' ) ); } catch( err ) {}" id="subTab' + i + '" style="' + subTabStyle + '; text-align: ' + nav[ i ][ 2 ] + ';">';
      
      // padding
      if( nav[ i ][ 2 ] == "left" ) output += '<img src="' + commonImagePath + 'spacer_1px.gif" width="' + subTabPadding + '" height="1" border="0">';
      
      for( n = 0; n < nav[ i ][ 3 ].length; n++ )
      {
         subTabItemStyle = ( i == activeTabIndex && n == activeSubTabIndex ) ? 'class="subNav_selected"' : '';
         
         output += '<a ' + subTabItemStyle + 'href="' + nav[ i ][ 3 ][ n ][ 1 ] + '" onclick="flashLinkTrack( \'TopNav/' + nav[ i ][ 0 ] + '\', \'' + nav[ i ][ 3 ][ n ][ 0 ] + '\' );">' + nav[ i ][ 3 ][ n ][ 0 ] + '</a>';
         
         if( n != nav[ i ][ 3 ].length - 1 ) output += '&nbsp;&nbsp;&nbsp;<img src="' + navImagePath + 'separator_subTab.gif" />&nbsp;&nbsp;&nbsp;'
      }
      
      // padding
      if( nav[ i ][ 2 ] == "right" ) output += '<img src="' + commonImagePath + 'spacer_1px.gif" width="' + subTabPadding + '" height="1" border="0">';
      
      output += '</div>';
      
    }
    
    output += '</div>';
    
    document.write( output );
  }
  
  
  function setActiveTabs()
  { 
    for( var i = 0; i < highlighting.length; i++ )
    {
      if( window.location.toString().indexOf( highlighting[ i ][ 2 ] ) != -1 )
      {
        activeTabIndex = highlighting[ i ][ 0 ] - 1;         // adjust to start from 0 (data starts from 1)
        activeSubTabIndex = highlighting[ i ][ 1 ] - 1;
        return;
      }
    }
  }
  
  
  
  var tabOff,                         // CSS class + ID names
      tabOn,
      tabSelected,
      navID;
  
  var topTabSeparator;                // image names
  
  var wide = false;

  function insertNav( isHome, isWide )
  {
    if( isHome != null && isHome == true )
    {
      navID = 'nav_HOME';
      
      tabOff = 'topNavTab_HOME';
      tabOn = 'topNavTab_ro_HOME';
      tabSelected = 'topNavTab_selected_HOME';
      
      topTabSeparator = 'separator_HOME.jpg';
    }
    else
    {
      navID = 'nav';
      
      tabOff = 'topNavTab';
      tabOn = 'topNavTab_ro';
      tabSelected = 'topNavTab_selected';
      
      topTabSeparator = 'separator.jpg';
    }
    
    if( isWide != null ) wide = isWide;
    if( wide ) subTabPadding += 128;
    
    render();    
  }
