(function() {
  
  function isSafari() {
    return /^((?!chrome).)*safari/i.test(navigator.userAgent);
  }

  var Site = function() {
    
  };
  
  Site.equalHeight = function(group) {
  	var tallest = 0;
  	group.each(function() {
    	var thisHeight = $(this).height();
      // var paddingTop = parseInt($(this).css('padding-top').replace('px', ''), 10);
      // var paddingBottom = parseInt($(this).css('padding-bottom').replace('px', ''), 10);
  	  thisHeight = thisHeight;
    	if(thisHeight > tallest) { tallest = thisHeight; }
  	});
  	group.height(tallest + 20);
  };
  
  Site.prototype = { 
       
    domReady: function() {
      //are we using FF? 
      if (!(window.mozInnerScreenX == null)) { 
        $(document.body).addClass('firefox'); 
        jQuery('#contact-info .phone > a').attr('href', '#');
      }
	if (isSafari()) {$(document.body).addClass('safari');}
	if (navigator.appVersion.indexOf("Win")!=-1) {$(document.body).addClass('windows');}
		
	$('#freeform_companys_products_services').maxlength({max: 100});	
	
      
      this.$mainSideNav = $('#main-side-nav');
      //inject the arrow for the current item
      this.$mainSideNav.find('li.active a').append('<i class="icon-arrow show-for-tablet show-for-small"></i>');
      this.$mainSideNav.find('li.parent-active a').append('<i class="icon-arrow  show-for-tablet show-for-small"></i>');
      
      this.$mainNav = $('#main-nav');
      //fix the issue that structure can't add a class to the ul under a li that has children
      this.$mainNav.find('li.has-dropdown ul').addClass('dropdown');
      this.$mainNav.find('.top-bar-section li.has-dropdown').append('<i class="icon-arrow hide-for-larger-than-tablet show-for-tablet show-for-small"></i>');  
      this.$mainNav.find('.top-bar-section li.has-dropdown li.has-dropdown i.icon-arrow').removeClass('hide-for-larger-than-tablet');
      
      var lastLi = this.$mainNav.find('.top-bar-section > ul > li:gt(4)');
      if (lastLi.hasClass("has-dropdown")) {lastLi.find('.dropdown').addClass('right');}
      
      var $videoPlayer = jQuery('#video-player');
      if ($videoPlayer.length) {
        var $videos = $videoPlayer.find('> div');
        $videos.not(':lt(1)').hide();
        jQuery('#rider-tutorial-videos ul a.show-video').click(function() {
          $videos.hide();
          var $link = jQuery(this);
          jQuery($link.attr('href'), $videoPlayer).show();
          return false;
        });
      }
      
      var $faqs = jQuery('.faqs-list');
      if ($faqs.length) {
        var $questions = $faqs.find('dt');
        var $answers = $faqs.find('dd');
        $questions.click(function() {
          var $question = jQuery(this);
          $answers.hide();
          $question.next('dd').show();
        });
      }
      
    }
  };
  
  
  
  window.Site = Site;  
})();

$(function() {
  new Site().domReady();
});