if (typeof modelNavData != "undefined") {
  // Create drop-down menus
  $('#carline ul.model_list').each(function() {
    var $$ = $(this);
    var carline = modelNavData[$$.parents('li').attr('id')];
    if (carline) {
      $$.children('li').each(function() {
        var $$ = $(this);
        var model = $$.attr('id');
        var menuContent = carline[model];
        if (menuContent) {
          // Insert content into menu table cell
          $$.find('tr.model_menu_content td.center').html(menuContent);
          this.hasContent = true;
        }
      });
    }
  });

  // Use javascript docroot path for menu link images
  $('.model_menu_content img').each(function() {
    $(this).attr('src', function() {
      return this.src.replace(/.*\/images(.*)/, global_staticpath_images + "$1");
    });
  });

}

$(function() {

  // Initialize model bar rollover graphics
  $('#carline > li > a > img').each(function() {
    var loSrc = this.src;
    var hiSrc = loSrc.replace(/\.lo\./, ".hi.");
    createGraphicLink(this, loSrc, hiSrc);
  });

  // Highlight model bar items on hover
  $('#carline > li').hover(
    function() {
      highlightCarline(this);
    },
    function() {
      var $$ = $(this);
      resetLinkHilite($$.find("img").get(0));
      $$.children("ul").hide();
    }
  );

  // Show drop-down menu for model items
  $('#carline ul.model_list > li').hover(
    function() {
      var $$ = $(this);
      if (!this.pngFixed && jQuery.fn.pngFix) {
        // Fix PNG transparency in IE6
        $$.find('tr.model_menu_head tr.bottom, tr.model_menu_content, tr.model_menu_foot').pngFix();
        this.pngFixed = true;
      }
      if (this.hasContent) {
        $$.find('table.model_menu').show();
      }
    },
    function() {
      $(this).find('table.model_menu').hide();
    }
  );

  // Hide the drop-down menu when entering the top right cell,
  // as it covers the model to the right of the current one
     $('#carline tr.model_menu_head tr.top td:last-child').mouseover(function() {
         $(this).parents('table.model_menu').hide();
     });

     
     /*$('#carline > li.highlighted').each(function() {
    	 highlightCarline(this);
     });*/
     
     
});

/**
 * highlight carline in model nav
 * @param pObj object to invoke display on
 * @return none
 */
function highlightCarline(pObj){
  var $$ = $(pObj);
  var modelImg = $$.find("img").get(0);
  /* showModelHilite() contains an aoa-specific callback hook,
     so we must keep using it */
  showModelHilite(modelImg.alt, modelImg);
  $$.children("ul").show();	
}

