/**
 * Load events for American Logistics Company
 *
 * Requires jquery.js
 *
 * Thomas Nicolosi
 * Red Bus Corporation
 * thomas @redbuscorp.com
 *
 * Rev. 1.0.0
 * July 19, 2010
 */
var subNavHover = function(){
  $(".sub-header ul li:not(:last-child) a").hover(function(){
        var theLink = $(this);
        theLink.parent("li").addClass("active");
        },
        function(){
        var theLink = $(this);
        theLink.parent("li").removeClass("active");
        });
  $(".sub-header ul li:last-child a").hover(function(){
        var theLink = $(this);
        theLink.parent("li").addClass("active");
        var theItem = theLink.parent("li");
        theItem.parent("ul").addClass("active");
        },
        function(){
        var theLink = $(this);
        theLink.parent("li").removeClass("active");
        var theItem = theLink.parent("li");
        theItem.parent("ul").removeClass("active");
        });
}
var fixLast = function(){
  $("ul.topnav li:last-child").addClass("last");
  $("#info .sub-banner div:last-child").addClass("last");
  $("#section .sub-banner div:last-child").addClass("last");
  $(".footer ul.footer-nav li:last-child").addClass("last");
}
var currentPageHighlight = function(match, menuItems){
  var items = menuItems.map(function(i){
                return $(this);
                });
  for (i = 0; i < items.length; i++) {
    if ( items[i].attr('title') === match ) {
      items[i].parent('li').addClass('current-page');
      }
    if( items[i].attr('title') === match && i === items.length - 1 ){
      items[i].parents('ul').addClass('current-page');
      }
    }
  };

$(document).ready(function(){
  //sub-nav behavior:
  subNavHover();
  fixLast();
  var navMatch = thisPageName;
  var navLinks = $('#section div.sub-header ul li a');
  currentPageHighlight(navMatch, navLinks);
  //---------------------------------------
  //Add fancybox popup form to document links.
  //---------------------------------------
  $('.contact-form-link a').click(function(event){
      event.preventDefault();
      //Grab the link to the document.
      window.docLink = $(this).attr('href');
      //Function to add the document link to the contact info page.
      $.fancybox({
              'autoDimensions' : 'false',
              'href' : '/contact-form.aspx',
              'width' : 400,
              'height' : 400,
              'type' : 'iframe'                            
              });
    });
  //--------------------------------------
  //Validate popup contact forms
  //--------------------------------------
  //$("#fancybox-frame").contents().find("#aspnetForm").validate();
  //rotating image and text banners on home page:
  $("ul.rotating-home-banner li").rotatingFade({delayTime: 5000, fadeTime: 10, pageIdentifier: thisPageName, activePage: 'Home'});
  //rotating banner on ParaTransit page
  $("ul.rotating-home-banner li").rotatingFade({delayTime: 5000, fadeTime: 10, pageIdentifier: thisPageName, activePage: 'ParaTransit'});
  //section contact us popup windows:
  $('span.contact-popup a').fancybox({
                                      'autoDimensions' : 'false',
                                      'width' : 325,
                                      'height' : 325,
                                      'type' : 'iframe'
                                      });
  //section analysis popup windows:
  $('span.analysis-form a').fancybox({
                                      'autoDimensions' : 'false',
                                      'width' : 325,
                                      'height' : 450,
                                      'type' : 'iframe'
                                      });
  });


