
//run podcast with genre selected
function runPodcast(){

  //reset the dropdown selected index to default
  // var s = document.getElementById('genreselect');
  // s.selectedIndex = 0;
  // if(s.selectedIndex == 0) {//}


  //disable button to let animation play
  $('.goBtn').attr("disabled", true);


  $('.podcast_result').addClass('hidden');
  var e = document.getElementById("genreselect");
  var selectedElement = e.options[e.selectedIndex];
  var podcastCategory = e.options[e.selectedIndex].value;
  var selectedCategory = $(selectedElement).attr('data-categoryid');
  // console.log(podcastCategory);
  // console.log(selectedCategory);
  var resultList = Array();
  if (selectedCategory != -1) {
    resultList = $('.podcast_result[data-categoryid="'+selectedCategory+'"]');
  } else {
    resultList = $('.podcast_result');
  }
  // console.log($(resultList).length);
  var randomIndex = Math.floor(Math.random()*$(resultList).length);

  $(resultList[randomIndex]).removeClass('hidden');
  $(resultList[randomIndex]).attr('id','podcast_share_title');

  //display sharing options for podcast result
  $('.podcast-result-footer').removeClass('hidden');

    var showWhichPodcast = document.getElementById('podcast_share_title');
    // console.log(showWhichPodcast.innerHTML);


  $('.confetti').addClass('confetti_surprise');
  $('.ring').addClass('ring_surprise');
  $('.waveform').addClass('waveform_surprise');

  setTimeout(function(){ 
    $('.confetti').removeClass('confetti_surprise');
    $('.ring').removeClass('ring_surprise');
    
   }, 750);

     //enable button after animation
    setTimeout(function(){
      $('.goBtn').attr("disabled", false);
      $(resultList[randomIndex]).attr('id','');
  }, 1100);



}

// console.log(showWhichPodcast.toString());

// FB.ui({
//   method: 'share',
//   href: 'https://www.cbc.ca/mynextpodcast'
// }, function(response){});

// $('.fb-share-button').attr('data-description', showWhichPodcast);

// $('.fb-share-button').click(function() {
//   console.log("SHARE ON FACEBOOK");

//   var quoteStr = document.getElementById('podcast_share_title').innerHTML;
//   var urlStr = $('meta[property="og:url"]').attr('content');
//   console.log(quoteStr);
//   console.log(urlStr);
//   FB.ui({
//     method: 'share',
//     href: urlStr,
//     quote: quoteStr
//   }, function(response){});
// });

  

// var showWhichPodcast = document.getElementById('podcast_share_title');
// console.log(showWhichPodcast.innerHTML);


  //find the ID for the podcast title
  // var podcastShareTitle = $('#podcast_share_title');
  // var podcastShareTitle = document.getElementById('podcast_share_title')
  // console.log(podcastShareTitle.innerHTML);



// facebook share button
  //   FB.ui({
  //     app_id: '2726945710658354',
  //     method: 'share',
  //     href: 'https://www.cbc.ca/mynextpodcast/',
  //     quote: showWhichPodcast.innerHTML
  // }, function(response){});


    // var CBC.APP.SC.DTM.DATA = {
    //     authors: "lindsay michael,senior producer","rebecca viegas,senior web developer","ben shannon,art director", "philip leung,associate producer" // send a list of authors if you attribute them
    //     contentarea: "radio", // "news", "sports", "radio", "music", "arts", "lifestyle", "comedy", "tv", "listen"
    //     contentid: "", // if your CMS produces a unique ID that represents the app state/view then send it along
    //     contenttier: "free", // possible values are "free", "authenticated", "premium" (use if you have a tiered content catalog)
    //     contenttype: "index", // "index", "story", "blogentry", "recipe"
    //     keywords: "podcast generator, podcast oracle, podcast playlists", //provide us tags that describe the content so that we can see how popular certain topics/stories are
    //     originaltitle: "CBC's My Next Podcast", //provide us the original title of the content if you've changed the title
    //     preventDefault: true, //required
    //     publishedTime: "Saturday September 29 2019", //provide us the epoch timestamp when the editorial content was first published
    //     subsection1: "podcast", //subsections are a descriptors of where this page lives inside of the CBC organization tree
    //     subsection2: "mynextpodcast", //or you can think of subsections as telling us what department in CBC owns the content in this page,
    //     partner:{
    //         id: "", //the id is here in case the partner name changes
    //         name: ""
    //     },
    //     pillar: "", //"feed", "watch", "listen", "legacyee"
    //     sponsor:{
    //         id:"", // the id is here in case the sponsor name is changes
    //         name:""
    //     },
    //     spa: true, //required
    //     title: "CBC My Next Podcast", //required: the value you are going to set in the title html tag (no formatting)
    //     url: "https://www.cbc.ca/mynextpodcast", //required: the value you are going to set in the canonical link html tag
    //     updatedTime: "",
    //     usertier: "" //possible values are "free", "authenticated", "premium" (use if you have a premium monthly subscription service)
    // }

