var CONFIG_CORP_NAV_BAR = {
  primary_class: 'nav-main',
  sub_class: 'nav-sub',
  tabs: [
    { 
      label: 'Home',
      href: '/index.html',
      sub_tabs: [
        {
          label: '',
          href: ''
        }
      ]
    },
    {
      label: 'Advertiser Products',
      href: '/advertise/index.html',
      sub_tabs: [
        {
          label: 'Premium Listings',
          href: '/advertise/advertise_premium.html'
        },
        {
          label: 'Zvents Media Network',
          href: '/company/media.html'
        }
      ]
    },
    {
      label: 'Media Products',
      href: '/products/index.html',
      sub_tabs: [
        {
          label: 'Zvents Media Platform',
          href: '/products/zvents_media_platform.html'
        },
        {
          label: 'Mobile API',
          href: '/products/mobile_api.html'
        },
        {
          label: 'Zvents Media Network',
          href: '/company/media.html'
       },
        {
          label: 'Content Aggregation',
          href: '/products/content.html'
        }
      ]
    },
    { 
      label: 'Local Marketing',
      href: '/marketing/index.html',
      sub_tabs: [
        {
          label: 'Event Promotion',
          href: '/marketing/event_promotion.html'
        },
				{
          label: 'Business Promotion',
          href: '/marketing/business_promotion.html'
        }
      ]
    },
    { 
      label: 'Company',
      href: '/company/index.html',
      sub_tabs: [
        {
          label: 'Management',
          href: '/company/management.html'
        },
        {
          label: 'Press Center',
          href: '/company/press.html'
        },
        {
          label: 'Jobs',
          href: '/company/jobs.html'
        },
        {
          label: 'The Lab',
          href: '/developers/thelab.html'
        }
      ]
    },
    { 
      label: 'Contact Us',
      href: '/contact/',
      sub_tabs: [
        {
          label: '',
          href: ''
        }        
      ]
    }
  ]
}

function ZNavBar(config, selected_tab){
  var fragments = [];
  var sub_tabs = null;

  function renderTab(tab, selected_tab){
    fragments.push('<li');

    if (tab.label == selected_tab) {
    /* go ahead and save reference to the sub tab list
     * so we don't have to find it later when they need to
     * be rendered.
     */
      sub_tabs = tab.sub_tabs;
      fragments.push(' class="on" ');
    }
    fragments.push('><a href="' + tab.href + '">' + tab.label + '</a></li>');
  }

  function renderTabs(tabs, div_class, selected_tab){
    fragments.push('<div class="' + div_class + '"><ul>');
    
    for (var i=0; i<tabs.length; i++){
        renderTab(tabs[i], selected_tab);
    }
    
    fragments.push('</ul><div class="clearout"></div></div>');
  }

  /* Render primary tabs */
  renderTabs(config.tabs, config.primary_class, selected_tab);
  
  /* Render sub tabs */
  renderTabs(sub_tabs, config.sub_class);

  document.write(fragments.join(''));
}

function corpNavBar(selected){
  ZNavBar(CONFIG_CORP_NAV_BAR, selected);
}

