+function toggle_section(event)
+{
+ $(this).parent().find('ul').toggle();
+}
+
+var waiting_stop = false;
+var waiting_forward = true;
+function results_waiting_stop()
+{
+ waiting_stop = true;
+ if (waiting_forward)
+ waiting_forward = false;
+}
+
+function results_waiting()
+{
+ var max = $(window).width() - 120;
+ var step = 15;
+ var hr = $('div#results hr');
+ var margin = hr.css('marginLeft').replace('px','');
+ if (margin.length)
+ margin = parseInt(margin, 10);
+ else
+ margin = 0;
+
+ if (margin == 0 && waiting_stop) {
+ waiting_stop = false;
+ } else {
+ if (margin > max)
+ waiting_forward = false;
+ else if (margin == 0)
+ waiting_forward = true;
+
+ if (waiting_forward)
+ margin += step;
+ else
+ margin -= step;
+
+ hr.css('marginLeft', margin+'px');
+ setTimeout(results_waiting,200);
+ }
+}
+setTimeout(results_waiting_stop,20000);
+
+function submit_search()
+{
+ if (!$('input#search_keyword').val().length)
+ return false;
+
+ $('div#results h1').text('Results.');
+ open_page('results');
+ $('div#results div.w3-section').hide();
+ results_waiting();
+
+ $.post('index.php',
+ 'action=search&' + $('div.w3-container#search form').serialize(),
+ function(data){
+ if (data) {
+ $('div#results h1').text(data.count+' matches.');
+ var result = $('<ul class="section">');
+
+ for (section in data.list) {
+ var dom_li = $('<li class="section">');
+ var dom_div = $('<div class="section">');
+ dom_div.append($('<strong class="w3-round">').text(section).click(toggle_section));
+
+ var dom_ul = $('<ul class="files">').hide();
+ for (var i=0; i < data.list[section].length; i++) {
+ var item = $('<li>');
+ if (i % 2 == 1)
+ item.addClass('bg');
+ item.append($('<div class="it">').html(data.list[section][i].title));
+ item.append($('<div class="ip">').html(data.list[section][i].path));
+ item.append($('<div class="in">').html(data.list[section][i].name));
+
+ dom_ul.append(item);
+ }
+ dom_div.append(dom_ul);
+
+ dom_li.append(dom_div);
+ result.append(dom_li);
+ }
+
+ $('div#results div.w3-section').empty().append(result);
+ $('div#results div.w3-section').show();
+ // $('div#results div.waiting').hide();
+ results_waiting_stop();
+ }
+ });
+
+ return false;
+}
+