/****************************
Copyright (c) 2013 Canadensys
Script to handle autocomplete
****************************/
/*global VASCAN, $, window*/
VASCAN.search = (function(){

  'use strict';

  var _private = {
    init: function(){
      this.typeahead();
    },
    typeahead: function(){
      $('.typeahead').typeahead([
        {
          name: 'scientific',
          remote: VASCAN.common.baseURL+'/search.json?q=%QUERY&t=taxon',
          header: '<h3 class="taxontype-name">'+VASCAN.common.getLanguageResource("autocomplete_title1")+'</h3>'
        },
        {
          name: 'vernacular',
          remote: VASCAN.common.baseURL+'/search.json?q=%QUERY&t=vernacular',
          header: '<h3 class="taxontype-name">'+VASCAN.common.getLanguageResource("autocomplete_title2")+'</h3>'
        }
        ]).on('typeahead:selected', this.dropdown_selected).focus().select();
    },
    dropdown_selected: function(){
      var lang = VASCAN.common.getParameterByName("lang"), param = (lang) ? "?lang=" + lang : "";
      window.location.href = VASCAN.common.baseURL+'/name/'+encodeURIComponent($(this).val())+param;
    }
  };
  return {
    init: function() {
      _private.init();
    }
  };
}());
@@ -208,16 +208,47 @@
 ate = %7B%0A
+    tt_input: $('.typeahead'),%0A
     init
@@ -251,32 +251,33 @@
 init: function()
+ 
 %7B%0A      this.typ
@@ -282,24 +282,50 @@
 ypeahead();%0A
+      this.trackSearch();%0A
     %7D,%0A    t
@@ -352,31 +352,29 @@
 %7B%0A      
-$('.typeahead')
+this.tt_input
 .typeahe
@@ -1175,16 +1175,271 @@
 +param;%0A
+    %7D,%0A    trackSearch: function() %7B%0A      var self = this;%0A      if(typeof _gaq !== 'undefined') %7B%0A        $('#search_button').on('click', function() %7B%0A          _gaq.push(%5B'_trackEvent', 'Search', 'Submitted', self.tt_input.val()%5D);%0A        %7D);%0A      %7D%0A
     %7D%0A  

Add search tracking in GA