$(function(){
  /*
    Section: Your code goes here...
  */
  $('#selector span').each(function(){
    $(this).click(function(){
      $('#selector ul').hide();
      $(this).next('ul').show();
    });
  });

  $('#selector-manufacturer a').each(function(){
    $(this).click(function()
    {
      var modelSlug = this.getAttribute("class");
      modelSlug = modelSlug ? modelSlug : this.getAttribute("className");

      bodyContent = $.ajax({
          //url: "/frontend_dev.php/boeingManufacturer/showModels",
          url: "/boeingManufacturer/showModels",
          type: "POST",
          data: ({slug : modelSlug}),
          dataType: "html",
          success: function(msg){
            $('#selector-model div').html(msg);
            document.getElementById('selector-model-show').innerHTML = msg;
            $('#selector-manufacturer ul').hide();
            $('#selector-model ul').show();
          }
        }
      );
      return false;
    });
  });

  /*
    Add clearfix class to top navigation
  */
  $('#rt-header .rt-site-page-navigation').addClass('clearfix');

  /*
    Add class to rt-site-page-navigation container
  */
  $('.inner-2 .rt-site-page-navigation').addClass("png_bg");
  $('.inner-2 .rt-site-page-navigation .here').addClass("png_bg");

  // Fix for IE for stacking indexes of selector elements
  $("#selector ul").parents().each(function()
  {
    var p = $(this);
    var pos = p.css("position");

    // If it's positioned,
    if(pos == "relative" || pos == "absolute" || pos == "fixed")
    {
      p.hover(function() {
        $(this).addClass("on-top");
      });
    }
  });

  /*
    Search Bar
  */
  var searchDefault = "Search...";
  var nameBox = $("#q");
  if(nameBox.attr("value") == "") nameBox.attr("value", searchDefault);
  nameBox.focus(function(){
    if($(this).attr("value") == searchDefault) $(this).attr("value", "");
  });
  nameBox.blur(function(){
    if($(this).attr("value") == "") $(this).attr("value", searchDefault);
  });

  /*
    Section: Spice up the form rows to be highlighted.
  */
  $('.rt-form-row textarea,.rt-form-row input,.rt-form-row select').focus(function(){
    $(this).parents('li').addClass('rt-highlight');
  }).blur(function(){
    $(this).parents('li').removeClass('rt-highlight');
  });
});
