$(document).ready(function () {

  $('video,audio').mediaelementplayer();

  $('#banners').bannerSlider();

  $('.megamenu-trigger').each(function () {
    $(this).parent('li').hover(function () {
      if (!$(this).find('a').hasClass("active")) {
        $(this).find('a').addClass("hover");
      }
      $(this).find('div.mega-menu').show();
    }, function () {
      $(this).find('div.mega-menu').hide();
      $(this).find('a').removeClass("hover");
    });
  });

  InitializeTableStyles();
});

$(window).bind('scroll', function () {
  var nav = $('body');
  var top = $(this).scrollTop();

  if (top < 170 && nav.hasClass('stick') === true) {
    nav.removeClass('stick');
  } else if (top >= 170 && nav.hasClass('stick') === false) {
    nav.addClass('stick');
  }
});

function initializeGoogleMap(mapId, latitude, longitude, zoom, title) {
  yepnope([{ load: 'http://www.google.com/jsapi', callback: function () {
    google.load("maps", "3", {
      callback: function () {
        var myLatlng = new google.maps.LatLng(latitude, longitude);
        var myOptions = {
          zoom: zoom,
          center: myLatlng,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        }

        var map = new google.maps.Map(document.getElementById(mapId), myOptions);

        var infowindow = new google.maps.InfoWindow({
          content: title,
          maxWidth: 200
        });

        var marker = new google.maps.Marker({
          position: myLatlng,
          map: map,
          title: title
        });

        google.maps.event.addListener(marker, 'mouseover', function () {
          infowindow.open(map, marker);
        });
      },
      other_params: "sensor=false"
    });
  }
  }]);
}

//
// Style table borders.
//
function InitializeTableStyles() {
  //remove borders from last table cell on each row.
  var lastTableCells = $("div.table-wrapper table tr");
  lastTableCells.each(function () {
    $(this).find("td:last").css("border", "none");
  })
}

function ClearField(field, defaultVal) {
  if ($(field).val() == defaultVal) {
    $(field).val("");
  }
}
