$(function() {
   $("#search_term_or_url").autocomplete({
    minLength: 3,
    source: "/search_suggestions",
    // select: function (event, ui) {
    //   $('#search_term_or_url').val(ui.item.title);
    //   $('#song_uid').val(ui.item.id);
    //   return false;
    // }
      select: function(event, ui) {
      $('#search_term_or_url').val(ui.item.value);
    }
   });

  // $( "#add-song" ).on( "click", function(event) {
  //   event.preventDefault();
  //   // event.stopPropagation();
  //   var newSong = $( "#song_url" ).val();
  //   newSong = newSong.replace("https://youtu.be/", "");
  //   videoIDs.push(newSong);
  //   $(".request.rowBox").last().append("<div>New song added, refresh to view</div>") // append song here....... 
  //   // $.post("/playlists/1/songs", {"song" : {"url" : $("#song_url").val()}}, function(data) {
  //   //   // Implement Rails flash
  //   // })
  // });

  $( "#skip-song" ).on( "click", function(event) {
    event.preventDefault();
    event.stopPropagation();
    if (player.getPlayerState() == 0) {
      player.loadVideoById(videoIDs[currentVideoId]);
    }
    if (player.getPlayerState() == 1) {
      currentVideoId++;
      player.loadVideoById(videoIDs[currentVideoId]);
    }
  });

  $(".upvote").click(function(event) {
    var requestId = $(this).attr("id")
    requestId = requestId.replace("upvote-", "")
    $.post("/requests/upvote", {"request_id": requestId}, function(data) {  
      });
  });

  $(".downvote").click(function(event) {
    var requestId = $(this).attr("id")
    requestId = requestId.replace("downvote-", "")
    $.post("/requests/downvote", {"request_id": requestId}, function(data) {  
      });
  });

  $(".delete").click(function(event) {
    var requestId = $(this).attr("id")
    requestId = requestId.replace("delete-", "")
    $.post("/requests/destroy", {"request_id": requestId}, {_method:'delete'}, null, "script");
  });

  $(":submit").click(function(event) {
    if ($(this).attr('id') == "intelligent-add-song") {
      event.preventDefault();
      $.post(location.href + "/songs", $("form").serialize(), function(data) {
        videoIDs.push(data.uid)  
      })
      $(".request.rowBox").last().append("<div>New song added, refresh to view</div>") // append song here....... 
    } else if ($(this).attr('id') == "chat_send") {
      event.preventDefault();
      // $.post("/playlist//chat_messages", $("form").serialize(), function(data) { 
      $.post(location.href + "/chat_messages", $("form").serialize(), function(data) {  
      })
      $("#new_chat_message")[0].reset();
    }
  });
});

// to write own autocomplete
// event listener on that input
// type = keydown or keyup
// send a get request to youtube api
// when that get request returns, function (data) {
//   $("some element").append("<div> jsondata </div>")

// }
// ul -> li

// add event listener the ul
// $("ul").click(function() {
//   add the clicked element into the input box, set the data id of that element to be the videoid
//   run whatever 
// })
@@ -107,19 +107,16 @@
 ns%22,%0A   
- //
  select:
@@ -124,17 +124,16 @@
 function
- 
 (event, 
@@ -139,21 +139,16 @@
  ui) %7B%0A 
-   //
    $('#s
@@ -183,713 +183,24 @@
 tem.
-title);%0A    //   $('#song_uid').val(ui.item.id);%0A    //   return false;%0A    // %7D%0A      select: function(event, ui) %7B%0A      $('#search_term_or_url').val(ui.item.value);%0A    %7D%0A   %7D);%0A%0A  // $( %22#add-song%22 ).on( %22click%22, function(event) %7B%0A  //   event.preventDefault();%0A  //   // event.stopPropagation();%0A  //   var newSong = $( %22#song_url%22 ).val();%0A  //   newSong = newSong.replace(%22https://youtu.be/%22, %22%22);%0A  //   videoIDs.push(newSong);%0A  //   $(%22.request.rowBox%22).last().append(%22%3Cdiv%3ENew song added, refresh to view%3C/div%3E%22) // append song here....... %0A  //   // $.post(%22/playlists/1/songs%22, %7B%22song%22 : %7B%22url%22 : $(%22#song_url%22).val()%7D%7D, function(data) %7B%0A  //   //   // Implement Rails flash%0A  //   // %7D)%0A  //
+value);%0A    %7D%0A  
  %7D);
@@ -680,23 +680,20 @@
 .post(%22/
-request
+vote
 s/upvote
@@ -902,23 +902,20 @@
 .post(%22/
-request
+vote
 s/downvo
@@ -1221,15 +1221,29 @@
  $(%22
-:submit
+#intelligent-add-song
 %22).c
@@ -1269,64 +1269,8 @@
 ) %7B%0A
-    if ($(this).attr('id') == %22intelligent-add-song%22) %7B%0A
     
@@ -1405,16 +1405,17 @@
 ata.uid)
+;
   %0A     
@@ -1409,32 +1409,33 @@
 uid);  %0A      %7D)
+;
 %0A      $(%22.reque
@@ -1540,54 +1540,51 @@
  %0A  
-  %7D else if ($(this).attr('id') == %22chat_send%22
+%7D);%0A%0A  $(%22#chat_send%22).click(function(event
 ) %7B%0A
@@ -1795,16 +1795,17 @@
       %7D)
+;
 %0A      $
@@ -1838,28 +1838,23 @@
 eset();%0A
-    %7D%0A
   %7D);%0A
+%0A
 %7D);%0A%0A// 

Clean up javascript