// Given an href of the form "...#vid1234_..." return 1234.
function video_id_from_href(href) {
  var str = href.substring(href.indexOf('#vid') + 4); return str.substring(0, str.indexOf('_'));
}

// Called by form submit. Does a simple case-insensitive match. Does not split
// search terms, use AND or OR, or anything nice like that.
function video_search() {

  var terms = $('#searchInp').val();

  // proceed only if the status bar is not empty
  if(terms == ''){
      return;
  }
  
  var matched_ids = new Array();
  var nonmatch_ids = new Array();
  $('.allVideoDescription').each(function(i, link) {
       var desc = link.innerHTML;
       var video_id = video_id_from_href(link.href);
       if (desc.toLowerCase().indexOf(terms) != -1) {
           matched_ids.push(video_id);
       }else{
           nonmatch_ids.push(video_id);
       }
     });
  allVideoIndexes_obj.setToSearch(matched_ids,nonmatch_ids);
}

// asign the search button action
function setupSearch(){
    document.getElementById('srchBtn').onclick = function(){
        video_search();
        return false;
    };
}
