$(function() {
  //Find and add links to lightbox named images
  $("a.lightbox img").each(function( index ) {
    $(this).unwrap();
    $(this).wrap("<a class='lightbox' title='"+$(this).attr("alt")+"' href='"+$(this).attr("src")+"'></a>");
  });
  $(".thumbnail-frame img").each(function( index ) {
    var thisSrc = $(this).attr("src");
    var thisExt = getExtension(thisSrc);
    var thisHref = $(this).parent("a").attr("href");
    thisHref = thisHref.replace('.html',thisExt);
    $(this).parent("a").attr('href',thisHref);
  });
  function getExtension(source) {
    var extension = source.substr( (source.lastIndexOf('.') +1) );
    switch(extension) {
      case 'jpg':
        return '.jpg';
      case 'jpeg':
        return '.jpeg';
      case 'png':
        return '.png';
      case 'gif':
        return '.gif';
      case 'pdf':
        return '.pdf'
    }
  };
  //Init magnific popup
  $("body").magnificPopup({
    delegate: 'a.lightbox',
    type: 'image',
    gallery:{enabled:true},
    removalDelay: 300,
    mainClass: 'mfp-fade'
  });
  //Init Lightbox for Photo Album Page
  if($(".album-wrapper").length) {
    $(".album-wrapper").magnificPopup({
      delegate: 'a',
      type: 'image',
      gallery:{enabled:true},
      removalDelay: 300,
      mainClass: 'mfp-fade'
    });
  } else {
    //do nothing
  }
});

//Notify Function
var notify = function(message,type){
  $("#notify").addClass("notify "+type).html(message).fadeIn(300);
  setTimeout(function(){
    $("#notify").fadeOut(600, function() { $(this).removeClass("notify"); });
  }, 15000);
};
/*
Tipue Search Copyright (c) 2015 Tipue

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

// List of pages for Live mode
pages = pages.split("href='");
var tipuesearch_pages = [];
if (!baseUrl.match("/$")) {
  baseUrl += "/";
}
jQuery.each(pages, function(index, value) {
  if(index > 0) {
    var newArr = this.split("'");
    if(newArr[0] != './') {
      newArr = newArr[0];
      //newArr = newArr.replace(/\.\.\//g,'');
      //newArr = baseUrl+newArr;
      tipuesearch_pages.push(newArr);
    }
  }
});

/*
Tipue Search 5.0
Copyright (c) 2015 Tipue
Tipue Search is released under the MIT License
http://www.tipue.com/search
*/
/*
Stop words
Stop words list from http://www.ranks.nl/stopwords
*/
var tipuesearch_stop_words = ["zzzzzz"];
//var tipuesearch_stop_words = ["a", "about", "above", "after", "again", "against", "all", "am", "an", "and", "any", "are", "aren't", "as", "at", "be", "because", "been", "before", "being", "below", "between", "both", "but", "by", "can't", "cannot", "could", "couldn't", "did", "didn't", "do", "does", "doesn't", "doing", "don't", "down", "during", "each", "few", "for", "from", "further", "had", "hadn't", "has", "hasn't", "have", "haven't", "having", "he", "he'd", "he'll", "he's", "her", "here", "here's", "hers", "herself", "him", "himself", "his", "how", "how's", "i", "i'd", "i'll", "i'm", "i've", "if", "in", "into", "is", "isn't", "it", "it's", "its", "itself", "let's", "me", "more", "most", "mustn't", "my", "myself", "no", "nor", "not", "of", "off", "on", "once", "only", "or", "other", "ought", "our", "ours", "ourselves", "out", "over", "own", "same", "shan't", "she", "she'd", "she'll", "she's", "should", "shouldn't", "so", "some", "such", "than", "that", "that's", "the", "their", "theirs", "them", "themselves", "then", "there", "there's", "these", "they", "they'd", "they'll", "they're", "they've", "this", "those", "through", "to", "too", "under", "until", "up", "very", "was", "wasn't", "we", "we'd", "we'll", "we're", "we've", "were", "weren't", "what", "what's", "when", "when's", "where", "where's", "which", "while", "who", "who's", "whom", "why", "why's", "with", "won't", "would", "wouldn't", "you", "you'd", "you'll", "you're", "you've", "your", "yours", "yourself", "yourselves"];
// Word replace
var tipuesearch_replace = {'words': [
  {'word': 'tipua', 'replace_with': 'tipue'},
  {'word': 'javscript', 'replace_with': 'javascript'},
  {'word': 'jqeury', 'replace_with': 'jquery'}
]};
// Weighting
var tipuesearch_weight = {'weight': [
  {'url': 'http://tipue.dev/search', 'score': 200},
  {'url': 'http://tipue.dev/about', 'score': 100},
  {'url': 'http://tipue.dev/tos', 'score': -1200}
]};
// Stemming
var tipuesearch_stem = {'words': [
  {'word': 'e-mail', 'stem': 'email'},
  {'word': 'javascript', 'stem': 'jquery'},
  {'word': 'javascript', 'stem': 'js'}
]};
// Internal strings
var tipuesearch_string_1 = 'No title';
var tipuesearch_string_2 = 'Showing results for';
var tipuesearch_string_3 = 'Search instead for';
var tipuesearch_string_4 = '1 result';
var tipuesearch_string_5 = 'results';
var tipuesearch_string_6 = 'Prev';
var tipuesearch_string_7 = 'Next';
var tipuesearch_string_8 = 'Nothing found';
var tipuesearch_string_9 = 'Common words are largely ignored';
var tipuesearch_string_10 = 'Search too short';
var tipuesearch_string_11 = 'Should be one character or more';
var tipuesearch_string_12 = 'Should be';
var tipuesearch_string_13 = 'characters or more';




/*
Tipue Search 5.0
Copyright (c) 2015 Tipue
Tipue Search is released under the MIT License
http://www.tipue.com/search
*/


(function($) {

  $.fn.tipuesearch = function(options) {

    var set = $.extend( {

      'show'                   : 7,
      'newWindow'              : false,
      'showURL'                : false,
      'showTitleCount'         : true,
      'minimumLength'          : 3,
      'descriptiveWords'       : 75,
      'highlightTerms'         : true,
      'highlightEveryTerm'     : false,
      'mode'                   : 'static',
      'liveDescription'        : '*',
      'liveContent'            : '*',
      'contentLocation'        : 'tipuesearch/tipuesearch_content.json',
      'debug'                  : false

    }, options);

    return this.each(function() {

      var tipuesearch_in = {
        pages: []
      };
      $.ajaxSetup({
        async: true
      });
      var tipuesearch_t_c = 0;
      if (set.mode == 'live')
      {
        //for (var i = 0; i < tipuesearch_pages.length; i++)
        $.each(tipuesearch_pages, function(index, value)
        {
          $.get(tipuesearch_pages[index])
            .done(function(html)
                  {
            //var cont = $(set.liveContent, html).text();//problem line
            var cont = html;
            cont=cont.replace(/<.+?>/g,"");
            cont = cont.replace(/\s+/g, ' ');

            //var a=$(".stacks_top", html).html();
            var a = html;
            if (a.indexOf("stacks_top'>") >= 0) {
              a = a.split("stacks_top'>").slice(1).join('stacks_top');
            } else {
              a = a.split('nnn-content" id="content">').slice(1).join('nnn-content');
            }
            //if (a == undefined){a=$(".nnn-content", html).html();}
            //if search description is defined
            if (a.indexOf("live-search-description") >= 0) {
              a = a.split('<div class="live-search-description"></div>').slice(1).join('<div class="live-search-description"></div>');
            }


            a=a.replace(/\s+/g," ");
            a=a.replace(/<ul.+?ul>/g,"");
            a=a.replace(/<h2 class="slogan".+?h2>/g,"");
            a=a.replace(/<style.+?style>/g,"");
            a=a.replace(/<script.+?script>/g,"");
            a=a.replace(/<.+?>/g,"");
            //a=$(a).text();

            var t_1 = html.toLowerCase().indexOf('<title>');
            var t_2 = html.toLowerCase().indexOf('</title>', t_1 + 7);
            if (t_1 != -1 && t_2 != -1)
            {
              var tit = html.slice(t_1 + 7, t_2);
            }
            else
            {
              var tit = tipuesearch_string_1;
            }

            tipuesearch_in.pages.push(
              {
                "title": tit,
                "text": a,
                "tags": cont,
                "url": tipuesearch_pages[index]
              });
          });
        });
      }

      if (set.mode == 'json')
      {
        $.getJSON(set.contentLocation)
          .done(function(json)
                {
          tipuesearch_in = $.extend({}, json);
        });
      }

      if (set.mode == 'static')
      {
        tipuesearch_in = $.extend({}, tipuesearch);
      }

      var tipue_search_w = '';
      if (set.newWindow)
      {
        tipue_search_w = ' target="_blank"';
      }

      function getURLP(name)
      {
        return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20')) || null;
      }
      if (getURLP('q'))
      {
        $('#tipue_search_input').val(getURLP('q'));
        getTipueSearch(0, true);
      }

      $(this).keyup(function(event)
                    {
        if(event.keyCode == '13')
        {
          getTipueSearch(0, true);
        }
      });


      function getTipueSearch(start, replace)
      {
        $('#tipue_search_content').hide();
        $('#tipue_search_content').html('<div class="tipue_search_spinner"><div class="tipue_search_rect1"></div><div class="tipue_search_rect2"></div><div class="rect3"></div></div>');
        $('#tipue_search_content').show();

        var out = '';
        var results = '';
        var show_replace = false;
        var show_stop = false;
        var standard = true;
        var c = 0;
        found = [];

        var d = $('#tipue_search_input').val().toLowerCase();
        d = $.trim(d);

        if ((d.match("^\"") && d.match("\"$")) || (d.match("^'") && d.match("'$")))
        {
          standard = false;
        }

        if (standard)
        {
          var d_w = d.split(' ');
          d = '';
          for (var i = 0; i < d_w.length; i++)
          {
            var a_w = true;
            for (var f = 0; f < tipuesearch_stop_words.length; f++)
            {
              if (d_w[i] == tipuesearch_stop_words[f])
              {
                a_w = false;
                show_stop = true;
              }
            }
            if (a_w)
            {
              d = d + ' ' + d_w[i];
            }
          }
          d = $.trim(d);
          d_w = d.split(' ');
        }
        else
        {
          d = d.substring(1, d.length - 1);
        }

        if (d.length >= set.minimumLength)
        {
          if (standard)
          {
            if (replace)
            {
              var d_r = d;
              for (var i = 0; i < d_w.length; i++)
              {
                for (var f = 0; f < tipuesearch_replace.words.length; f++)
                {
                  if (d_w[i] == tipuesearch_replace.words[f].word)
                  {
                    d = d.replace(d_w[i], tipuesearch_replace.words[f].replace_with);
                    show_replace = true;
                  }
                }
              }
              d_w = d.split(' ');
            }

            var d_t = d;
            for (var i = 0; i < d_w.length; i++)
            {
              for (var f = 0; f < tipuesearch_stem.words.length; f++)
              {
                if (d_w[i] == tipuesearch_stem.words[f].word)
                {
                  d_t = d_t + ' ' + tipuesearch_stem.words[f].stem;
                }
              }
            }
            d_w = d_t.split(' ');

            for (var i = 0; i < tipuesearch_in.pages.length; i++)
            {
              var score = 0;
              var s_t = tipuesearch_in.pages[i].text;
              for (var f = 0; f < d_w.length; f++)
              {
                var pat = new RegExp(d_w[f], 'gi');
                if (tipuesearch_in.pages[i].title.search(pat) != -1)
                {
                  var m_c = tipuesearch_in.pages[i].title.match(pat).length;
                  score += (20 * m_c);
                }
                if (tipuesearch_in.pages[i].text.search(pat) != -1)
                {
                  var m_c = tipuesearch_in.pages[i].text.match(pat).length;
                  score += (20 * m_c);
                }

                if (set.highlightTerms)
                {
                  if (set.highlightEveryTerm)
                  {
                    var patr = new RegExp('(' + d_w[f] + ')', 'gi');
                  }
                  else
                  {
                    var patr = new RegExp('(' + d_w[f] + ')', 'i');
                  }
                  s_t = s_t.replace(patr, "<span class=\"h01\">$1</span>");
                }

                if (tipuesearch_in.pages[i].tags.search(pat) != -1)
                {
                  var m_c = tipuesearch_in.pages[i].tags.match(pat).length;
                  score += (10 * m_c);
                }
                if (tipuesearch_in.pages[i].url == undefined) {tipuesearch_in.pages[i].url = " "}
                if (tipuesearch_in.pages[i].url.search(pat) != -1)
                {
                  score += 20;
                }

                if (score != 0)
                {
                  for (var e = 0; e < tipuesearch_weight.weight.length; e++)
                  {
                    if (tipuesearch_in.pages[i].url == tipuesearch_weight.weight[e].url)
                    {
                      score += tipuesearch_weight.weight[e].score;
                    }
                  }
                }

                if (d_w[f].match('^-'))
                {
                  pat = new RegExp(d_w[f].substring(1), 'i');
                  if (tipuesearch_in.pages[i].title.search(pat) != -1 || tipuesearch_in.pages[i].text.search(pat) != -1 || tipuesearch_in.pages[i].tags.search(pat) != -1)
                  {
                    score = 0;
                  }
                }
              }

              if (score != 0)
              {
                found.push(
                  {
                    "score": score,
                    "title": tipuesearch_in.pages[i].title,
                    "desc": s_t,
                    "url": tipuesearch_in.pages[i].url
                  });
                c++;
              }
            }
          }
          else
          {
            for (var i = 0; i < tipuesearch_in.pages.length; i++)
            {
              var score = 0;
              var s_t = tipuesearch_in.pages[i].text;
              var pat = new RegExp(d, 'gi');
              if (tipuesearch_in.pages[i].title.search(pat) != -1)
              {
                var m_c = tipuesearch_in.pages[i].title.match(pat).length;
                score += (20 * m_c);
              }
              if (tipuesearch_in.pages[i].text.search(pat) != -1)
              {
                var m_c = tipuesearch_in.pages[i].text.match(pat).length;
                score += (20 * m_c);
              }

              if (set.highlightTerms)
              {
                if (set.highlightEveryTerm)
                {
                  var patr = new RegExp('(' + d + ')', 'gi');
                }
                else
                {
                  var patr = new RegExp('(' + d + ')', 'i');
                }
                s_t = s_t.replace(patr, "<span class=\"h01\">$1</span>");
              }

              if (tipuesearch_in.pages[i].tags.search(pat) != -1)
              {
                var m_c = tipuesearch_in.pages[i].tags.match(pat).length;
                score += (10 * m_c);
              }

              if (tipuesearch_in.pages[i].url.search(pat) != -1)
              {
                score += 20;
              }

              if (score != 0)
              {
                for (var e = 0; e < tipuesearch_weight.weight.length; e++)
                {
                  if (tipuesearch_in.pages[i].url == tipuesearch_weight.weight[e].url)
                  {
                    score += tipuesearch_weight.weight[e].score;
                  }
                }
              }

              if (score != 0)
              {
                found.push(
                  {
                    "score": score,
                    "title": tipuesearch_in.pages[i].title,
                    "desc": s_t,
                    "url": tipuesearch_in.pages[i].url
                  });
                c++;
              }
            }
          }

          if (c != 0)
          {
            if (set.showTitleCount && tipuesearch_t_c == 0)
            {
              var title = document.title;
              document.title = '(' + c + ') ' + title;
              tipuesearch_t_c++;
            }

            if (show_replace == 1)
            {
              out += '<div id="tipue_search_warning">' + tipuesearch_string_2 + ' ' + d + '. ' + tipuesearch_string_3 + ' <a id="tipue_search_replaced">' + d_r + '</a></div>';
            }
            if (c == 1)
            {
              out += '<div id="tipue_search_results_count">' + tipuesearch_string_4 + '</div>';
            }
            else
            {
              c_c = c.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
              out += '<div id="tipue_search_results_count">' + c_c + ' ' + tipuesearch_string_5 + '</div>';
            }

            found.sort(function(a, b) { return b.score - a.score } );

            var l_o = 0;
            for (var i = 0; i < found.length; i++)
            {
              if (l_o >= start && l_o < set.show + start)
              {
                out += '<div class="tipue_search_content_title"><a href="' + found[i].url + '"' + tipue_search_w + '>' +  found[i].title + '</a></div>';

                if (set.debug)
                {
                  out += '<div class="tipue_search_content_debug">Score: ' + found[i].score + '</div>';
                }

                if (set.showURL)
                {
                  var s_u = found[i].url.toLowerCase();
                  if(s_u.indexOf('http://') == 0)
                  {
                    s_u = s_u.slice(7);
                  }
                  out += '<div class="tipue_search_content_url"><a href="' + found[i].url + '"' + tipue_search_w + '>' + s_u + '</a></div>';
                }

                if (found[i].desc)
                {
                  var t = found[i].desc;
                  var t_d = '';
                  var t_w = t.split(' ');
                  if (t_w.length < set.descriptiveWords)
                  {
                    t_d = t;
                  }
                  else
                  {
                    for (var f = 0; f < set.descriptiveWords; f++)
                    {
                      t_d += t_w[f] + ' ';
                    }
                  }
                  t_d = $.trim(t_d);
                  if (t_d.charAt(t_d.length - 1) != '.')
                  {
                    t_d += ' ...';
                  }
                  out += '<div class="tipue_search_content_text">' + t_d + '</div>';
                }
              }
              l_o++;
            }

            if (c > set.show)
            {
              var pages = Math.ceil(c / set.show);
              var page = (start / set.show);
              out += '<div id="tipue_search_foot"><ul id="tipue_search_foot_boxes">';

              if (start > 0)
              {
                out += '<li><a class="tipue_search_foot_box" id="' + (start - set.show) + '_' + replace + '">' + tipuesearch_string_6 + '</a></li>';
              }

              if (page <= 2)
              {
                var p_b = pages;
                if (pages > 3)
                {
                  p_b = 3;
                }
                for (var f = 0; f < p_b; f++)
                {
                  if (f == page)
                  {
                    out += '<li class="current">' + (f + 1) + '</li>';
                  }
                  else
                  {
                    out += '<li><a class="tipue_search_foot_box" id="' + (f * set.show) + '_' + replace + '">' + (f + 1) + '</a></li>';
                  }
                }
              }
              else
              {
                var p_b = page + 2;
                if (p_b > pages)
                {
                  p_b = pages;
                }
                for (var f = page - 1; f < p_b; f++)
                {
                  if (f == page)
                  {
                    out += '<li class="current">' + (f + 1) + '</li>';
                  }
                  else
                  {
                    out += '<li><a class="tipue_search_foot_box" id="' + (f * set.show) + '_' + replace + '">' + (f + 1) + '</a></li>';
                  }
                }
              }

              if (page + 1 != pages)
              {
                out += '<li><a class="tipue_search_foot_box" id="' + (start + set.show) + '_' + replace + '">' + tipuesearch_string_7 + '</a></li>';
              }

              out += '</ul></div>';
            }
          }
          else
          {
            out += '<div id="tipue_search_warning">' + tipuesearch_string_8 + '</div>';
          }
        }
        else
        {
          if (show_stop)
          {
            out += '<div id="tipue_search_warning">' + tipuesearch_string_8 + '. ' + tipuesearch_string_9 + '</div>';
          }
          else
          {
            out += '<div id="tipue_search_warning">' + tipuesearch_string_10 + '</div>';
            if (set.minimumLength == 1)
            {
              out += '<div id="tipue_search_warning">' + tipuesearch_string_11 + '</div>';
            }
            else
            {
              out += '<div id="tipue_search_warning">' + tipuesearch_string_12 + ' ' + set.minimumLength + ' ' + tipuesearch_string_13 + '</div>';
            }
          }
        }

        $('#tipue_search_content').hide();
        $('#tipue_search_content').html(out);
        $('#tipue_search_content').slideDown(200);

        $('#tipue_search_replaced').click(function()
                                                                        {
          getTipueSearch(0, false);
        });

        $('.tipue_search_foot_box').click(function()
                                          {
          var id_v = $(this).attr('id');
          var id_a = id_v.split('_');

          getTipueSearch(parseInt(id_a[0]), id_a[1]);
        });
      }

    }).promise().done( function(){  } );
  };

})(jQuery);

//$("#tipue_search_input").on( "click", function() {
//if(!$(".tipue_search_loaded").length){
//Search
$(function() {
  var previewMode = getUrlVars();
  previewMode = previewMode[0];
  console.log(previewMode);
  if((previewMode.substring(0, 11) == "http://file") || (previewMode.substring(0, 16) == "http://localhost") || (previewMode.substring(0, 10) == "http://127")) {
    //Dont load
    $("#tipue_search_input").css("pointer-events","none");
    console.log("Live Search: Preview mode detected, search has been disabled.")
  } else {
    $('#tipue_search_input').tipuesearch({
      'mode': 'live',
      'liveDescription': '.nnn-content',
      'liveContent': 'body'
    });
    $('form#live-search').on('submit', function() {
      $("body").addClass("searching");
      return false;
    });
    $('#tipue_search_input, #tipue_search_content').on('click', function(e) {
      e.stopPropagation();
    });
    $(document).on('click', function (e) {
      $("body").removeClass("searching");
    });
  }
  jQuery("body").addClass("tipue_search_loaded");
});


//}
//});

//
//!function(e){e.fn.tipuesearch=function(t){var i=e.extend({show:7,newWindow:!1,showURL:!0,showTitleCount:!0,minimumLength:3,descriptiveWords:60,highlightTerms:!0,highlightEveryTerm:!1,mode:"static",liveDescription:"*",liveContent:"*",contentLocation:"tipuesearch/tipuesearch_content.json",debug:!1},t);return this.each(function(){function t(e){return decodeURIComponent((new RegExp("[?|&]"+e+"=([^&;]+?)(&|#|;|$)").exec(location.search)||[,""])[1].replace(/\+/g,"%20"))||null}function s(t,c){e("#tipue_search_content").hide(),e("#tipue_search_content").html('<div class="tipue_search_spinner"><div class="tipue_search_rect1"></div><div class="tipue_search_rect2"></div><div class="rect3"></div></div>'),e("#tipue_search_content").show();var n="",o=!1,p=!1,l=!0,u=0;found=[];var g=e("#tipue_search_input").val().toLowerCase();if(g=e.trim(g),(g.match('^"')&&g.match('"$')||g.match("^'")&&g.match("'$"))&&(l=!1),l){var _=g.split(" ");g="";for(var d=0;d<_.length;d++){for(var v=!0,f=0;f<tipuesearch_stop_words.length;f++)_[d]==tipuesearch_stop_words[f]&&(v=!1,p=!0);v&&(g=g+" "+_[d])}g=e.trim(g),_=g.split(" ")}else g=g.substring(1,g.length-1);if(g.length>=i.minimumLength){if(l){if(c){for(var w=g,d=0;d<_.length;d++)for(var f=0;f<tipuesearch_replace.words.length;f++)_[d]==tipuesearch_replace.words[f].word&&(g=g.replace(_[d],tipuesearch_replace.words[f].replace_with),o=!0);_=g.split(" ")}for(var m=g,d=0;d<_.length;d++)for(var f=0;f<tipuesearch_stem.words.length;f++)_[d]==tipuesearch_stem.words[f].word&&(m=m+" "+tipuesearch_stem.words[f].stem);_=m.split(" ");for(var d=0;d<r.pages.length;d++){for(var x=0,b=r.pages[d].text,f=0;f<_.length;f++){var L=new RegExp(_[f],"gi");if(-1!=r.pages[d].title.search(L)){var E=r.pages[d].title.match(L).length;x+=20*E}if(-1!=r.pages[d].text.search(L)){var E=r.pages[d].text.match(L).length;x+=20*E}if(i.highlightTerms){if(i.highlightEveryTerm)var R=new RegExp("("+_[f]+")","gi");else var R=new RegExp("("+_[f]+")","i");b=b.replace(R,'<span class="h01">$1</span>')}if(-1!=r.pages[d].tags.search(L)){var E=r.pages[d].tags.match(L).length;x+=10*E}if(-1!=r.pages[d].url.search(L)&&(x+=20),0!=x)for(var C=0;C<tipuesearch_weight.weight.length;C++)r.pages[d].url==tipuesearch_weight.weight[C].url&&(x+=tipuesearch_weight.weight[C].score);_[f].match("^-")&&(L=new RegExp(_[f].substring(1),"i"),(-1!=r.pages[d].title.search(L)||-1!=r.pages[d].text.search(L)||-1!=r.pages[d].tags.search(L))&&(x=0))}0!=x&&(found.push({score:x,title:r.pages[d].title,desc:b,url:r.pages[d].url}),u++)}}else for(var d=0;d<r.pages.length;d++){var x=0,b=r.pages[d].text,L=new RegExp(g,"gi");if(-1!=r.pages[d].title.search(L)){var E=r.pages[d].title.match(L).length;x+=20*E}if(-1!=r.pages[d].text.search(L)){var E=r.pages[d].text.match(L).length;x+=20*E}if(i.highlightTerms){if(i.highlightEveryTerm)var R=new RegExp("("+g+")","gi");else var R=new RegExp("("+g+")","i");b=b.replace(R,'<span class="h01">$1</span>')}if(-1!=r.pages[d].tags.search(L)){var E=r.pages[d].tags.match(L).length;x+=10*E}if(-1!=r.pages[d].url.search(L)&&(x+=20),0!=x)for(var C=0;C<tipuesearch_weight.weight.length;C++)r.pages[d].url==tipuesearch_weight.weight[C].url&&(x+=tipuesearch_weight.weight[C].score);0!=x&&(found.push({score:x,title:r.pages[d].title,desc:b,url:r.pages[d].url}),u++)}if(0!=u){if(i.showTitleCount&&0==a){var T=document.title;document.title="("+u+") "+T,a++}1==o&&(n+='<div id="tipue_search_warning">'+tipuesearch_string_2+" "+g+". "+tipuesearch_string_3+' <a id="tipue_search_replaced">'+w+"</a></div>"),1==u?n+='<div id="tipue_search_results_count">'+tipuesearch_string_4+"</div>":(c_c=u.toString().replace(/\B(?=(\d{3})+(?!\d))/g,","),n+='<div id="tipue_search_results_count">'+c_c+" "+tipuesearch_string_5+"</div>"),found.sort(function(e,t){return t.score-e.score});for(var y=0,d=0;d<found.length;d++){if(y>=t&&y<i.show+t){if(n+='<div class="tipue_search_content_title"><a href="'+found[d].url+'"'+h+">"+found[d].title+"</a></div>",i.debug&&(n+='<div class="tipue_search_content_debug">Score: '+found[d].score+"</div>"),i.showURL){var k=found[d].url.toLowerCase();0==k.indexOf("http://")&&(k=k.slice(7)),n+='<div class="tipue_search_content_url"><a href="'+found[d].url+'"'+h+">"+k+"</a></div>"}if(found[d].desc){var W=found[d].desc,$="",j=W.split(" ");if(j.length<i.descriptiveWords)$=W;else for(var f=0;f<i.descriptiveWords;f++)$+=j[f]+" ";$=e.trim($),"."!=$.charAt($.length-1)&&($+=" ..."),n+='<div class="tipue_search_content_text">'+$+"</div>"}}y++}if(u>i.show){var O=Math.ceil(u/i.show),S=t/i.show;if(n+='<div id="tipue_search_foot"><ul id="tipue_search_foot_boxes">',t>0&&(n+='<li><a class="tipue_search_foot_box" id="'+(t-i.show)+"_"+c+'">'+tipuesearch_string_6+"</a></li>"),2>=S){var D=O;O>3&&(D=3);for(var f=0;D>f;f++)n+=f==S?'<li class="current">'+(f+1)+"</li>":'<li><a class="tipue_search_foot_box" id="'+f*i.show+"_"+c+'">'+(f+1)+"</a></li>"}else{var D=S+2;D>O&&(D=O);for(var f=S-1;D>f;f++)n+=f==S?'<li class="current">'+(f+1)+"</li>":'<li><a class="tipue_search_foot_box" id="'+f*i.show+"_"+c+'">'+(f+1)+"</a></li>"}S+1!=O&&(n+='<li><a class="tipue_search_foot_box" id="'+(t+i.show)+"_"+c+'">'+tipuesearch_string_7+"</a></li>"),n+="</ul></div>"}}else n+='<div id="tipue_search_warning">'+tipuesearch_string_8+"</div>"}else p?n+='<div id="tipue_search_warning">'+tipuesearch_string_8+". "+tipuesearch_string_9+"</div>":(n+='<div id="tipue_search_warning">'+tipuesearch_string_10+"</div>",n+=1==i.minimumLength?'<div id="tipue_search_warning">'+tipuesearch_string_11+"</div>":'<div id="tipue_search_warning">'+tipuesearch_string_12+" "+i.minimumLength+" "+tipuesearch_string_13+"</div>");e("#tipue_search_content").hide(),e("#tipue_search_content").html(n),e("#tipue_search_content").slideDown(200),e("#tipue_search_replaced").click(function(){s(0,!1)}),e(".tipue_search_foot_box").click(function(){var t=e(this).attr("id"),i=t.split("_");s(parseInt(i[0]),i[1])})}var r={pages:[]};e.ajaxSetup({async:!1});var a=0;if("live"==i.mode)for(var c=0;c<tipuesearch_pages.length;c++)e.get(tipuesearch_pages[c]).done(function(t){var s=e(i.liveContent,t).text();s=s.replace(/\s+/g," ");
////var a=e(i.liveDescription,t).text();a=a.replace(/\s+/g," ");
////Modifications
//var a=e(".stacks_top", t).html();
//if(a == undefined){a=e("*", t).html();}
////if search description is defined
//if (a.indexOf("live-search-description") >= 0) {
//  //a = a.split('<div class="live-search-description"></div>').pop();
//  a = a.split('<div class="live-search-description"></div>').slice(1).join('<div class="live-search-description"></div>');
//}
//a=a.replace(/\s+/g," ");
//a=a.replace(/<ul.+?ul>/g,"");
//a=a.replace(/<style.+?style>/g,"");
//a=a.replace(/<script.+?script>/g,"");
//a=e(a).text();
//
//var h=t.toLowerCase().indexOf("<title>"),n=t.toLowerCase().indexOf("</title>",h+7);if(-1!=h&&-1!=n)var o=t.slice(h+7,n);else var o=tipuesearch_string_1;r.pages.push({title:o,text:a,tags:s,url:tipuesearch_pages[c]})});"json"==i.mode&&e.getJSON(i.contentLocation).done(function(t){r=e.extend({},t)}),"static"==i.mode&&(r=e.extend({},tipuesearch));var h="";i.newWindow&&(h=' target="_blank"'),t("q")&&(e("#tipue_search_input").val(t("q")),s(0,!0)),e(this).keyup(function(e){"13"==e.keyCode&&s(0,!0)})})}}(jQuery);
//// Read a page's GET URL variables and return them as an associative array.
function getUrlVars() {
  var vars = [], hash;
  var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
  for(var i = 0; i < hashes.length; i++)
  {
    hash = hashes[i].split('=');
    vars.push(hash[0]);
    vars[hash[0]] = hash[1];
  }
  return vars;
}


