<commit_before>/*
 * YouMax Youtube gallery Jquery Library.
 *
 * https://github.com/codehandling/youmax
 * @license MIT
 */
var youmax_global_options = {};

(function ($) {

    "use strict";

    var secondsToTime = function (duration) {
        if (null === duration || duration === "" || duration === "undefined") {
            return "?";
        }
        var minutes = Math.floor(duration / 60), seconds = duration % 60;

        if (seconds < 10) {
            seconds = "0" + seconds;
        }
        return minutes + ":" + seconds;
    },

        // utility function to display time
        convertDuration = function (videoDuration) {
            var duration, returnDuration;
            videoDuration = videoDuration.replace('PT', '').replace('S', '').replace('M', ':').replace('H', ':');

            // TODO: fix some duration settings
            // console.log('videoDuration-'+videoDuration);

            var videoDurationSplit = videoDuration.split(':');
            returnDuration = videoDurationSplit[0];

            for (var i = 1; i < videoDurationSplit.length; i++) {
                duration = videoDurationSplit[i];
                //console.log('duration-'+duration);
                if (duration === "") {
                  returnDuration += ":00";
                } else {
                  duration = parseInt(duration, 10);
                  //console.log('duration else -'+duration)
                  if (duration < 10) {
                    returnDuration += ":0" + duration;
                  } else {
                    returnDuration += ":" + duration;
                  }
                }
            }
          if (videoDurationSplit.length == 1) {
            returnDuration = "0:" + returnDuration;
          }
          return returnDuration;

        },


    getDateDiff = function (timestamp) {
        if (null === timestamp || timestamp === "" || timestamp === "undefined") {
            return "?";
        }

      //alert(timestamp);
      var splitDate = ((timestamp.toString().split('T'))[0]).split('-');
      var d1 = new Date();

      var d1Y = d1.getFullYear();
      var d2Y = parseInt(splitDate[0], 10);
      var d1M = d1.getMonth();
      var d2M = parseInt(splitDate[1], 10);

      var diffInMonths = (d1M + 12 * d1Y) - (d2M + 12 * d2Y);
      /*alert(d1Y);
        alert(d2Y);
        alert(d1M);
        alert(d2M);
        alert(diffInMonths);
        */
      if (diffInMonths <= 1)
        return "1 month";
      else if (diffInMonths < 12)
        return diffInMonths + " months";

      var diffInYears = Math.floor(diffInMonths / 12);

      if (diffInYears <= 1)
        return "1 year";
      else if (diffInYears < 12)
        return diffInYears + " years";

    },

    getReadableNumber = function (number) {
      if (null === number || number === "" || number === "undefined")
        return "?";

      number = number.toString();
      var readableNumber = '';
      var count = 0;
      for (var k = number.length; k >= 0; k--) {
        readableNumber += number.charAt(k);
        if (count == 3 && k > 0) {
          count = 1;
          readableNumber += ',';
        } else {
          count++;
        }
      }
      return readableNumber.split("").reverse().join("");
    },


    loadYoumax = function () {

      youmaxWidgetWidth = $('#youmax').width();

      $('#youmax').append('<div id="youmax-header"><div id="youmax-stat-holder"></div></div>');

      //$('#youmax').append('<div id="youmax-tabs"></div>');

      $('#youmax').append('<div id="youmax-tabs"><span id="featured_" class="youmax-tab">Featured</span><span id="uploads_" class="youmax-tab">Uploads</span><span id="playlists_" class="youmax-tab">Playlists</span></div>');

      $('#youmax').append('<div id="youmax-encloser"><iframe id="youmax-video" width="' + (youmaxWidgetWidth - 2) + '" height="' + (youmaxWidgetWidth / youmax_global_options.youtubeVideoAspectRatio) + '" src="" frameborder="0" allowfullscreen></iframe><div id="youmax-video-list-div"></div><div id="youmax-load-more-div">LOAD MORE</div></div>');

      $('#youmax-video').hide();

      $('#youmax').append('<div id="youmax-lightbox"><div style="width:100%; position:absolute; top:20%;"><iframe id="youmax-video-lightbox" width="640" height="360" src="" frameborder="0" allowfullscreen></iframe></div></div>');

      $('#youmax-lightbox').hide();
    },

    //get channel Id if channel URL is of the form ....../user/Adele
    getChannelId = function (apiUrl) {
      //console.log('inside getChannelId');
      //console.log('apiUrl-'+apiUrl);
      //showLoader();

      $.ajax({
        url: apiUrl,
        type: "GET",
        async: true,
        cache: true,
        dataType: 'jsonp',
        success: function (response) {
          youmaxChannelId = response.items[0].id;
          getChannelDetails(youmaxChannelId);
        },
        error: function (html) {
          alert(html);
        },
        beforeSend: setHeader
      });
    },


    getChannelDetails = function (channelId) {
      // var apiProfileURL = "http://gdata.youtube.com/feeds/api/users/"+youmaxUser+"?v=2&alt=json";
      var apiProfileURL = "https://www.googleapis.com/youtube/v3/channels?part=brandingSettings%2Csnippet%2Cstatistics%2CcontentDetails&id=" + channelId + "&key=" + youmax_global_options.apiKey;

      $.ajax({
        url: apiProfileURL,
        type: "GET",
        async: true,
        cache: true,
        dataType: 'jsonp',
        success: function (response) {
          showInfo(response);
        },
        error: function (html) {
          alert(html);
        },
        beforeSend: setHeader
      });
    },

    setHeader = function (xhr) {
      if (xhr && xhr.overrideMimeType) {
        xhr.overrideMimeType("application/j-son;charset=UTF-8");
      }
    },

    showLoader = function () {
      youmax_global_options.youmaxItemCount = 0;
      $('#youmax-video-list-div').empty();
      $('#youmax-video').hide();
      $('#youmax-video').attr('src', '');
      $('#youmax-video-list-div').append('<div style="text-align:center; height:200px; font:14px Calibri;"><br><br><br><br><br><br>loading...</div>');
    },

    initFeaturedVideos = function () {
      youTubePlaylistURL = youmax_global_options.youTubePlaylistURL;
      // console.log('inside init featured - ' + youTubePlaylistURL);
      if (null !== youTubePlaylistURL && youTubePlaylistURL.indexOf("youtube.com/playlist?list=") != -1) {
        youmaxFeaturedPlaylistId = youTubePlaylistURL.substring(youTubePlaylistURL.indexOf("?list=") + 6);
        youmax_global_options.youmaxFeaturedPlaylistId = youmaxFeaturedPlaylistId;
      }
    },

    showInfo = function (response) {
      // console.log('showInfo');
      // console.log(response);

      var channelData = response.items[0];
      var channelId = channelData.id;
      var channelName = channelData.snippet.title;
      var channelPic = channelData.snippet.thumbnails.default.url;
      var channelSubscribers = channelData.statistics.subscriberCount;
      var channelViews = channelData.statistics.viewCount;
      var channelDesc = "";
      var channelUploadsPlaylistId = channelData.contentDetails.relatedPlaylists.uploads;

      $('#youmax-header').append('<img id="youmax-header-logo" src="' + channelPic + '"/>' + channelName);

      $('#youmax-header').append('&nbsp;&nbsp;&nbsp;&nbsp;<div class="youmax-subscribe"><div class="g-ytsubscribe" data-channelid="' + channelId + '" data-layout="default" data-count="default"></div></div>');

      //$('#youmax-stat-holder').append('<div class="youmax-stat">'+channelSubscribers+'<br/> subscribers </div><div class="youmax-stat">'+channelViews+'<br/>video views</div>');

      //$('#youmax-stat-holder').append('<div class="youmax-stat"><span class="youmax-stat-count">'+getReadableNumber(channelViews)+'</span><br/> video views </div><div class="youmax-stat"><span class="youmax-stat-count">'+getReadableNumber(channelSubscribers)+'</span><br/>subscribers</div>');

      //$('#youmax-channel-desc').append('About '+channelName+'<br/>'+channelDesc);

      renderSubscribeButton();

      $('#youmax-tabs').find('span[id^=uploads_]').attr('id', 'uploads_' + channelUploadsPlaylistId);

      youmaxDefaultTab = youmax_global_options.youmaxDefaultTab;

      if (typeof youmaxDefaultTab === 'undefined' || null === youmaxDefaultTab || youmaxDefaultTab === "" || youmaxDefaultTab == "undefined") {
        $("#youmax-tabs span[id^=featured_]").click();
      } else if (youmaxDefaultTab.toUpperCase() == 'UPLOADS' || youmaxDefaultTab.toUpperCase() == 'UPLOAD') {
        $("#youmax-tabs span[id^=uploads_]").click();
      } else if (youmaxDefaultTab.toUpperCase() == 'PLAYLISTS' || youmaxDefaultTab.toUpperCase() == 'PLAYLIST') {
        $("#youmax-tabs span[id^=playlists_]").click();
      } else if (youmaxDefaultTab.toUpperCase() == 'FEATURED' || youmaxDefaultTab.toUpperCase() == 'FEATURED') {
        $("#youmax-tabs span[id^=featured_]").click();
      }
    },

    renderSubscribeButton = function () {
      $.ajaxSetup({
        cache: true
      });

      $.getScript("https://apis.google.com/js/platform.js")
        .done(function (script, textStatus) {
          //alert( textStatus );
        })
        .fail(function (jqxhr, settings, exception) {
          //alert( "Triggered ajaxError handler." );
        });
    },

    showPlaylists = function (response, loadMoreFlag) {
      // console.log(response);

      if (!loadMoreFlag) {
        $('#youmax-video-list-div').empty();
      }

      var nextPageToken = response.nextPageToken;
      var $youmaxLoadMoreDiv = $('#youmax-load-more-div');
      //console.log('nextPageToken-'+nextPageToken);

      if (null != nextPageToken && nextPageToken != "undefined" && nextPageToken !== "") {
        $youmaxLoadMoreDiv.data('nextpagetoken', nextPageToken);
      } else {
        $youmaxLoadMoreDiv.data('nextpagetoken', '');
      }

      youmaxColumns = youmax_global_options.youmaxColumns;

      var playlistArray = response.items;
      var playlistIdArray = [];
      var zeroPlaylistCompensation = 0;
      for (var i = 0; i < playlistArray.length; i++) {
        playListId = playlistArray[i].id;
        playlistSize = playlistArray[i].contentDetails.itemCount;
        if (playlistSize <= 0) {
          zeroPlaylistCompensation++;
          continue;
        }
        playlistIdArray.push(playListId);
        playlistTitle = playlistArray[i].snippet.title;
        playlistUploaded = playlistArray[i].snippet.publishedAt;
        playlistThumbnail = playlistArray[i].snippet.thumbnails.medium.url;
        //playlistThumbnail = playlistThumbnail.replace("hqdefault","mqdefault");
        if ((i + youmax_global_options.youmaxItemCount - zeroPlaylistCompensation) % youmaxColumns !== 0)
          $('#youmax-video-list-div').append('<div class="youmax-video-tnail-box" style="width:' + ((100 / youmaxColumns) - 4) + '%;" id="' + playListId + '"><div class="youmax-video-tnail" style="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader( src=\'' + playlistThumbnail + '\', sizingMethod=\'scale\'); background-image:url(\'' + playlistThumbnail + '\')"><div class="youmax-playlist-sidebar" id="youmax-playlist-sidebar-' + playListId + '"><span class="youmax-playlist-video-count"><b>' + playlistSize + '</b><br/>VIDEOS</span></div></div><span class="youmax-video-list-title">' + playlistTitle + '</span><br/><span class="youmax-video-list-views">' + getDateDiff(playlistUploaded) + ' ago</span></div>');
        else
          $('#youmax-video-list-div').append('<div class="youmax-video-tnail-box" style="width:' + ((100 / youmaxColumns) - 4) + '%; clear:both;" id="' + playListId + '"><div class="youmax-video-tnail" style="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader( src=\'' + playlistThumbnail + '\', sizingMethod=\'scale\'); background-image:url(\'' + playlistThumbnail + '\')"><div class="youmax-playlist-sidebar" id="youmax-playlist-sidebar-' + playListId + '"><span class="youmax-playlist-video-count"><b>' + playlistSize + '</b><br/>VIDEOS</span></div></div><span class="youmax-video-list-title">' + playlistTitle + '</span><br/><span class="youmax-video-list-views">' + getDateDiff(playlistUploaded) + ' ago</span></div>');

      }

      youmax_global_options.youmaxItemCount += playlistArray.length - zeroPlaylistCompensation;
      //console.log(playlistIdArray);

      $('.youmax-video-tnail-box').click(function () {
        //alert(this.id);
        showLoader();
        playlistTitle = $(this).find(".youmax-video-list-title").text();
        getUploads("play_" + this.id, playlistTitle);
        //getPlaylistVideos(this.id);
      });

      /*
        if(youmaxTnailHeight<130) {
            maxTopVideos = 3;
            $('html > head').append('<style>.youmax-playlist-video-count{margin: 10%;margin-top: 15%;}.youmax-playlist-sidebar-video{margin: 8% auto;}</style>');
            //$('div.youmax-playlist-video-count').css({'margin':'10%','margin-top':'15%'});
            //$('div.youmax-playlist-sidebar-video').css({'margin':'8% auto'});
        } else {
            maxTopVideos = 4;
        }*/

      resetLoadMoreButton();

      //console.log(youmaxTnailWidth);
      //console.log(youmaxTnailHeight);

      //getTopVideosFromPlaylist(playlistIdArray,maxTopVideos);
    },

    showUploads = function (response, playlistTitle, loadMoreFlag) {
      // console.log(response);

      if (!loadMoreFlag) {
        $('#youmax-video-list-div').empty();

        if (playlistTitle) {
          $('.youmax-tab-hover').removeClass('youmax-tab-hover');
          $('#youmax-video-list-div').append('<span class="youmax-showing-title youmax-tab-hover" id="uploads_' + response.items[0].snippet.playlistId + '" style="max-width:100%;"><span class="youmax-showing">&nbsp;&nbsp;Showing playlist: </span>' + playlistTitle + '</span><br/>');
        }
      }

      var nextPageToken = response.nextPageToken;
      var $youmaxLoadMoreDiv = $('#youmax-load-more-div');
      //console.log('nextPageToken-'+nextPageToken);

      youmaxColumns = youmax_global_options.youmaxColumns;

      if (null != nextPageToken && nextPageToken != "undefined" && nextPageToken !== "") {
        $youmaxLoadMoreDiv.data('nextpagetoken', nextPageToken);
      } else {
        $youmaxLoadMoreDiv.data('nextpagetoken', '');
      }

      var uploadsArray = response.items;
      var videoIdArray = [];

      for (var i = 0; i < uploadsArray.length; i++) {
        videoId = uploadsArray[i].snippet.resourceId.videoId;
        videoTitle = uploadsArray[i].snippet.title;
        //videoViewCount = uploadsArray[i].snippet.viewCount;
        //videoDuration = uploadsArray[i].snippet.duration;
        videoUploaded = uploadsArray[i].snippet.publishedAt;
        videoThumbnail = uploadsArray[i].snippet.thumbnails.medium.url;
        //videoThumbnail = videoThumbnail.replace("hqdefault","mqdefault");

        videoIdArray.push(videoId);

        //$('#youmax-video-list-div').append('<div class="youmax-video-tnail-box" style="width:'+((100/youmaxColumns)-4)+'%;" id="'+videoId+'"><div class="youmax-video-tnail" style="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader( src=\''+videoThumbnail+'\', sizingMethod=\'scale\'); background-image:url(\''+videoThumbnail+'\')"><div class="youmax-duration">'+secondsToTime(videoDuration)+'</div></div><span class="youmax-video-list-title">'+videoTitle+'</span><br/><span class="youmax-video-list-views">'+getReadableNumber(videoViewCount)+' views | '+getDateDiff(videoUploaded)+' ago</span></div>');


        if ((i + youmax_global_options.youmaxItemCount) % youmaxColumns !== 0)
          $('#youmax-video-list-div').append('<div class="youmax-video-tnail-box" style="width:' + ((100 / youmaxColumns) - 4) + '%;" id="' + videoId + '"><div class="youmax-video-tnail" style="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader( src=\'' + videoThumbnail + '\', sizingMethod=\'scale\'); background-image:url(\'' + videoThumbnail + '\')"><div class="youmax-duration"></div></div><span class="youmax-video-list-title">' + videoTitle + '</span><br/><span class="youmax-video-list-views">' + getDateDiff(videoUploaded) + ' ago</span></div>');
        else
          $('#youmax-video-list-div').append('<div class="youmax-video-tnail-box" style="width:' + ((100 / youmaxColumns) - 4) + '%; clear:both;" id="' + videoId + '"><div class="youmax-video-tnail" style="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader( src=\'' + videoThumbnail + '\', sizingMethod=\'scale\'); background-image:url(\'' + videoThumbnail + '\')"><div class="youmax-duration"></div></div><span class="youmax-video-list-title">' + videoTitle + '</span><br/><span class="youmax-video-list-views">' + getDateDiff(videoUploaded) + ' ago</span></div>');

      }

      youmax_global_options.youmaxItemCount += uploadsArray.length;

      $('.youmax-video-tnail-box').click(function () {
        //alert(this.id);
        //alert(showVideoInLightbox);
        if (youmax_global_options.showVideoInLightbox) {
          showVideoLightbox(this.id);
        } else {
          $('#youmax-video').attr('src', 'http://www.youtube.com/embed/' + this.id);
          $('#youmax-video').show();
          $('html,body').animate({
            scrollTop: $("#youmax-header").offset().top
          }, 'slow');
        }
      });

      // not sure why this is needed
      /*var youmaxTnailWidth = $('.youmax-video-tnail').css('width');
        youmaxTnailWidth=youmaxTnailWidth.substring(0,youmaxTnailWidth.indexOf("px"));
        var youmaxTnailHeight = youmaxTnailWidth/youmax_global_options.youtubeMqdefaultAspectRatio;
        //$('html > head').append('<style>.youmax-video-tnail{height:'+youmaxTnailHeight+'px;}</style>');
        $('div.youmax-video-tnail').css({'height':youmaxTnailHeight+'px'});*/


      getVideoStats(videoIdArray);
      resetLoadMoreButton();
<commit_msg>[WIP] Made file apply to JS Hint<commit_after>/*
 * YouMax Youtube gallery Jquery Library.
 *
 * https://github.com/codehandling/youmax
 * @license MIT
 */
var youmax_global_options = {};

(function ($) {

    "use strict";

    var secondsToTime = function (duration) {
        if (null === duration || duration === "" || duration === "undefined") {
            return "?";
        }
        var minutes = Math.floor(duration / 60), seconds = duration % 60;

        if (seconds < 10) {
            seconds = "0" + seconds;
        }
        return minutes + ":" + seconds;
    },

        // utility function to display time
        convertDuration = function (videoDuration) {
            var duration, returnDuration;
            videoDuration = videoDuration.replace('PT', '').replace('S', '').replace('M', ':').replace('H', ':');

            // TODO: fix some duration settings
            // console.log('videoDuration-'+videoDuration);

            var videoDurationSplit = videoDuration.split(':');
            returnDuration = videoDurationSplit[0];

            for (var i = 1; i < videoDurationSplit.length; i++) {
                duration = videoDurationSplit[i];
                //console.log('duration-'+duration);
                if (duration === "") {
                  returnDuration += ":00";
                } else {
                  duration = parseInt(duration, 10);
                  //console.log('duration else -'+duration)
                  if (duration < 10) {
                    returnDuration += ":0" + duration;
                  } else {
                    returnDuration += ":" + duration;
                  }
                }
            }
          if (videoDurationSplit.length == 1) {
            returnDuration = "0:" + returnDuration;
          }
          return returnDuration;

        },


    getDateDiff = function (timestamp) {
        if (null === timestamp || timestamp === "" || timestamp === "undefined") {
            return "?";
        }

      //alert(timestamp);
      var splitDate = ((timestamp.toString().split('T'))[0]).split('-');
      var d1 = new Date();

      var d1Y = d1.getFullYear();
      var d2Y = parseInt(splitDate[0], 10);
      var d1M = d1.getMonth();
      var d2M = parseInt(splitDate[1], 10);

      var diffInMonths = (d1M + 12 * d1Y) - (d2M + 12 * d2Y);
      /*alert(d1Y);
        alert(d2Y);
        alert(d1M);
        alert(d2M);
        alert(diffInMonths);
        */
      if (diffInMonths <= 1) {
        return "1 month";
      }
      else if (diffInMonths < 12) {
        return diffInMonths + " months";
      }

      var diffInYears = Math.floor(diffInMonths / 12);

      if (diffInYears <= 1) {
        return "1 year";
      }
      else if (diffInYears < 12) {
        return diffInYears + " years";
      }
    },

    getReadableNumber = function (number) {
      if (null === number || number === "" || number === "undefined") {
        return "?";
      }

      number = number.toString();
      var readableNumber = '';
      var count = 0;
      for (var k = number.length; k >= 0; k--) {
        readableNumber += number.charAt(k);
        if (count == 3 && k > 0) {
          count = 1;
          readableNumber += ',';
        } else {
          count++;
        }
      }
      return readableNumber.split("").reverse().join("");
    },


    loadYoumax = function () {

      youmaxWidgetWidth = $('#youmax').width();

      $('#youmax').append('<div id="youmax-header"><div id="youmax-stat-holder"></div></div>');

      //$('#youmax').append('<div id="youmax-tabs"></div>');

      $('#youmax').append('<div id="youmax-tabs"><span id="featured_" class="youmax-tab">Featured</span><span id="uploads_" class="youmax-tab">Uploads</span><span id="playlists_" class="youmax-tab">Playlists</span></div>');

      $('#youmax').append('<div id="youmax-encloser"><iframe id="youmax-video" width="' + (youmaxWidgetWidth - 2) + '" height="' + (youmaxWidgetWidth / youmax_global_options.youtubeVideoAspectRatio) + '" src="" frameborder="0" allowfullscreen></iframe><div id="youmax-video-list-div"></div><div id="youmax-load-more-div">LOAD MORE</div></div>');

      $('#youmax-video').hide();

      $('#youmax').append('<div id="youmax-lightbox"><div style="width:100%; position:absolute; top:20%;"><iframe id="youmax-video-lightbox" width="640" height="360" src="" frameborder="0" allowfullscreen></iframe></div></div>');

      $('#youmax-lightbox').hide();
    },

    //get channel Id if channel URL is of the form ....../user/Adele
    getChannelId = function (apiUrl) {
      //console.log('inside getChannelId');
      //console.log('apiUrl-'+apiUrl);
      //showLoader();

      $.ajax({
        url: apiUrl,
        type: "GET",
        async: true,
        cache: true,
        dataType: 'jsonp',
        success: function (response) {
          youmaxChannelId = response.items[0].id;
          getChannelDetails(youmaxChannelId);
        },
        error: function (html) {
          alert(html);
        },
        beforeSend: setHeader
      });
    },


    getChannelDetails = function (channelId) {
      // var apiProfileURL = "http://gdata.youtube.com/feeds/api/users/"+youmaxUser+"?v=2&alt=json";
      var apiProfileURL = "https://www.googleapis.com/youtube/v3/channels?part=brandingSettings%2Csnippet%2Cstatistics%2CcontentDetails&id=" + channelId + "&key=" + youmax_global_options.apiKey;

      $.ajax({
        url: apiProfileURL,
        type: "GET",
        async: true,
        cache: true,
        dataType: 'jsonp',
        success: function (response) {
          showInfo(response);
        },
        error: function (html) {
          alert(html);
        },
        beforeSend: setHeader
      });
    },

    setHeader = function (xhr) {
      if (xhr && xhr.overrideMimeType) {
        xhr.overrideMimeType("application/j-son;charset=UTF-8");
      }
    },

    showLoader = function () {
      youmax_global_options.youmaxItemCount = 0;
      $('#youmax-video-list-div').empty();
      $('#youmax-video').hide();
      $('#youmax-video').attr('src', '');
      $('#youmax-video-list-div').append('<div style="text-align:center; height:200px; font:14px Calibri;"><br><br><br><br><br><br>loading...</div>');
    },

    initFeaturedVideos = function () {
      youTubePlaylistURL = youmax_global_options.youTubePlaylistURL;
      // console.log('inside init featured - ' + youTubePlaylistURL);
      if (null !== youTubePlaylistURL && youTubePlaylistURL.indexOf("youtube.com/playlist?list=") != -1) {
        youmaxFeaturedPlaylistId = youTubePlaylistURL.substring(youTubePlaylistURL.indexOf("?list=") + 6);
        youmax_global_options.youmaxFeaturedPlaylistId = youmaxFeaturedPlaylistId;
      }
    },

    showInfo = function (response) {
      // console.log('showInfo');
      // console.log(response);

      var channelData = response.items[0];
      var channelId = channelData.id;
      var channelName = channelData.snippet.title;
      var channelPic = channelData.snippet.thumbnails.default.url;
      var channelSubscribers = channelData.statistics.subscriberCount;
      var channelViews = channelData.statistics.viewCount;
      var channelDesc = "";
      var channelUploadsPlaylistId = channelData.contentDetails.relatedPlaylists.uploads;

      $('#youmax-header').append('<img id="youmax-header-logo" src="' + channelPic + '"/>' + channelName);

      $('#youmax-header').append('&nbsp;&nbsp;&nbsp;&nbsp;<div class="youmax-subscribe"><div class="g-ytsubscribe" data-channelid="' + channelId + '" data-layout="default" data-count="default"></div></div>');

      //$('#youmax-stat-holder').append('<div class="youmax-stat">'+channelSubscribers+'<br/> subscribers </div><div class="youmax-stat">'+channelViews+'<br/>video views</div>');

      //$('#youmax-stat-holder').append('<div class="youmax-stat"><span class="youmax-stat-count">'+getReadableNumber(channelViews)+'</span><br/> video views </div><div class="youmax-stat"><span class="youmax-stat-count">'+getReadableNumber(channelSubscribers)+'</span><br/>subscribers</div>');

      //$('#youmax-channel-desc').append('About '+channelName+'<br/>'+channelDesc);

      renderSubscribeButton();

      $('#youmax-tabs').find('span[id^=uploads_]').attr('id', 'uploads_' + channelUploadsPlaylistId);

      youmaxDefaultTab = youmax_global_options.youmaxDefaultTab;

      if (typeof youmaxDefaultTab === 'undefined' || null === youmaxDefaultTab || youmaxDefaultTab === "" || youmaxDefaultTab == "undefined") {
        $("#youmax-tabs span[id^=featured_]").click();
      } else if (youmaxDefaultTab.toUpperCase() == 'UPLOADS' || youmaxDefaultTab.toUpperCase() == 'UPLOAD') {
        $("#youmax-tabs span[id^=uploads_]").click();
      } else if (youmaxDefaultTab.toUpperCase() == 'PLAYLISTS' || youmaxDefaultTab.toUpperCase() == 'PLAYLIST') {
        $("#youmax-tabs span[id^=playlists_]").click();
      } else if (youmaxDefaultTab.toUpperCase() == 'FEATURED' || youmaxDefaultTab.toUpperCase() == 'FEATURED') {
        $("#youmax-tabs span[id^=featured_]").click();
      }
    },

    renderSubscribeButton = function () {
      $.ajaxSetup({
        cache: true
      });

      $.getScript("https://apis.google.com/js/platform.js")
        .done(function (script, textStatus) {
          //alert( textStatus );
        })
        .fail(function (jqxhr, settings, exception) {
          //alert( "Triggered ajaxError handler." );
        });
    },

    showPlaylists = function (response, loadMoreFlag) {
      // console.log(response);

      if (!loadMoreFlag) {
        $('#youmax-video-list-div').empty();
      }

      var nextPageToken = response.nextPageToken;
      var $youmaxLoadMoreDiv = $('#youmax-load-more-div');
      //console.log('nextPageToken-'+nextPageToken);

      if (null != nextPageToken && nextPageToken != "undefined" && nextPageToken !== "") {
        $youmaxLoadMoreDiv.data('nextpagetoken', nextPageToken);
      } else {
        $youmaxLoadMoreDiv.data('nextpagetoken', '');
      }

      youmaxColumns = youmax_global_options.youmaxColumns;

      var playlistArray = response.items;
      var playlistIdArray = [];
      var zeroPlaylistCompensation = 0;
      for (var i = 0; i < playlistArray.length; i++) {
        playListId = playlistArray[i].id;
        playlistSize = playlistArray[i].contentDetails.itemCount;
        if (playlistSize <= 0) {
          zeroPlaylistCompensation++;
          continue;
        }
        playlistIdArray.push(playListId);
        playlistTitle = playlistArray[i].snippet.title;
        playlistUploaded = playlistArray[i].snippet.publishedAt;
        playlistThumbnail = playlistArray[i].snippet.thumbnails.medium.url;
        //playlistThumbnail = playlistThumbnail.replace("hqdefault","mqdefault");
        if ((i + youmax_global_options.youmaxItemCount - zeroPlaylistCompensation) % youmaxColumns !== 0) {
          $('#youmax-video-list-div').append('<div class="youmax-video-tnail-box" style="width:' + ((100 / youmaxColumns) - 4) + '%;" id="' + playListId + '"><div class="youmax-video-tnail" style="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader( src=\'' + playlistThumbnail + '\', sizingMethod=\'scale\'); background-image:url(\'' + playlistThumbnail + '\')"><div class="youmax-playlist-sidebar" id="youmax-playlist-sidebar-' + playListId + '"><span class="youmax-playlist-video-count"><b>' + playlistSize + '</b><br/>VIDEOS</span></div></div><span class="youmax-video-list-title">' + playlistTitle + '</span><br/><span class="youmax-video-list-views">' + getDateDiff(playlistUploaded) + ' ago</span></div>');
        }
        else {
          $('#youmax-video-list-div').append('<div class="youmax-video-tnail-box" style="width:' + ((100 / youmaxColumns) - 4) + '%; clear:both;" id="' + playListId + '"><div class="youmax-video-tnail" style="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader( src=\'' + playlistThumbnail + '\', sizingMethod=\'scale\'); background-image:url(\'' + playlistThumbnail + '\')"><div class="youmax-playlist-sidebar" id="youmax-playlist-sidebar-' + playListId + '"><span class="youmax-playlist-video-count"><b>' + playlistSize + '</b><br/>VIDEOS</span></div></div><span class="youmax-video-list-title">' + playlistTitle + '</span><br/><span class="youmax-video-list-views">' + getDateDiff(playlistUploaded) + ' ago</span></div>');
        }

      }

      youmax_global_options.youmaxItemCount += playlistArray.length - zeroPlaylistCompensation;
      //console.log(playlistIdArray);

      $('.youmax-video-tnail-box').click(function () {
        //alert(this.id);
        showLoader();
        playlistTitle = $(this).find(".youmax-video-list-title").text();
        getUploads("play_" + this.id, playlistTitle);
        //getPlaylistVideos(this.id);
      });

      /*
        if(youmaxTnailHeight<130) {
            maxTopVideos = 3;
            $('html > head').append('<style>.youmax-playlist-video-count{margin: 10%;margin-top: 15%;}.youmax-playlist-sidebar-video{margin: 8% auto;}</style>');
            //$('div.youmax-playlist-video-count').css({'margin':'10%','margin-top':'15%'});
            //$('div.youmax-playlist-sidebar-video').css({'margin':'8% auto'});
        } else {
            maxTopVideos = 4;
        }*/

      resetLoadMoreButton();

      //console.log(youmaxTnailWidth);
      //console.log(youmaxTnailHeight);

      //getTopVideosFromPlaylist(playlistIdArray,maxTopVideos);
    },

    showUploads = function (response, playlistTitle, loadMoreFlag) {
      // console.log(response);

      if (!loadMoreFlag) {
        $('#youmax-video-list-div').empty();

        if (playlistTitle) {
          $('.youmax-tab-hover').removeClass('youmax-tab-hover');
          $('#youmax-video-list-div').append('<span class="youmax-showing-title youmax-tab-hover" id="uploads_' + response.items[0].snippet.playlistId + '" style="max-width:100%;"><span class="youmax-showing">&nbsp;&nbsp;Showing playlist: </span>' + playlistTitle + '</span><br/>');
        }
      }

      var nextPageToken = response.nextPageToken;
      var $youmaxLoadMoreDiv = $('#youmax-load-more-div');
      //console.log('nextPageToken-'+nextPageToken);

      youmaxColumns = youmax_global_options.youmaxColumns;

      if (null != nextPageToken && nextPageToken != "undefined" && nextPageToken !== "") {
        $youmaxLoadMoreDiv.data('nextpagetoken', nextPageToken);
      } else {
        $youmaxLoadMoreDiv.data('nextpagetoken', '');
      }

      var uploadsArray = response.items;
      var videoIdArray = [];

      for (var i = 0; i < uploadsArray.length; i++) {
        videoId = uploadsArray[i].snippet.resourceId.videoId;
        videoTitle = uploadsArray[i].snippet.title;
        //videoViewCount = uploadsArray[i].snippet.viewCount;
        //videoDuration = uploadsArray[i].snippet.duration;
        videoUploaded = uploadsArray[i].snippet.publishedAt;
        videoThumbnail = uploadsArray[i].snippet.thumbnails.medium.url;
        //videoThumbnail = videoThumbnail.replace("hqdefault","mqdefault");

        videoIdArray.push(videoId);

        //$('#youmax-video-list-div').append('<div class="youmax-video-tnail-box" style="width:'+((100/youmaxColumns)-4)+'%;" id="'+videoId+'"><div class="youmax-video-tnail" style="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader( src=\''+videoThumbnail+'\', sizingMethod=\'scale\'); background-image:url(\''+videoThumbnail+'\')"><div class="youmax-duration">'+secondsToTime(videoDuration)+'</div></div><span class="youmax-video-list-title">'+videoTitle+'</span><br/><span class="youmax-video-list-views">'+getReadableNumber(videoViewCount)+' views | '+getDateDiff(videoUploaded)+' ago</span></div>');


        if ((i + youmax_global_options.youmaxItemCount) % youmaxColumns !== 0) {
          $('#youmax-video-list-div').append('<div class="youmax-video-tnail-box" style="width:' + ((100 / youmaxColumns) - 4) + '%;" id="' + videoId + '"><div class="youmax-video-tnail" style="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader( src=\'' + videoThumbnail + '\', sizingMethod=\'scale\'); background-image:url(\'' + videoThumbnail + '\')"><div class="youmax-duration"></div></div><span class="youmax-video-list-title">' + videoTitle + '</span><br/><span class="youmax-video-list-views">' + getDateDiff(videoUploaded) + ' ago</span></div>');
        }
        else {
          $('#youmax-video-list-div').append('<div class="youmax-video-tnail-box" style="width:' + ((100 / youmaxColumns) - 4) + '%; clear:both;" id="' + videoId + '"><div class="youmax-video-tnail" style="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader( src=\'' + videoThumbnail + '\', sizingMethod=\'scale\'); background-image:url(\'' + videoThumbnail + '\')"><div class="youmax-duration"></div></div><span class="youmax-video-list-title">' + videoTitle + '</span><br/><span class="youmax-video-list-views">' + getDateDiff(videoUploaded) + ' ago</span></div>');
        }
      }

      youmax_global_options.youmaxItemCount += uploadsArray.length;

      $('.youmax-video-tnail-box').click(function () {
        //alert(this.id);
        //alert(showVideoInLightbox);
        if (youmax_global_options.showVideoInLightbox) {
          showVideoLightbox(this.id);
        } else {
          $('#youmax-video').attr('src', 'http://www.youtube.com/embed/' + this.id);
          $('#youmax-video').show();
          $('html,body').animate({
            scrollTop: $("#youmax-header").offset().top
          }, 'slow');
        }
      });

      // not sure why this is needed
      /*var youmaxTnailWidth = $('.youmax-video-tnail').css('width');
        youmaxTnailWidth=youmaxTnailWidth.substring(0,youmaxTnailWidth.indexOf("px"));
        var youmaxTnailHeight = youmaxTnailWidth/youmax_global_options.youtubeMqdefaultAspectRatio;
        //$('html > head').append('<style>.youmax-video-tnail{height:'+youmaxTnailHeight+'px;}</style>');
        $('div.youmax-video-tnail').css({'height':youmaxTnailHeight+'px'});*/


      getVideoStats(videoIdArray);
      resetLoadMoreButton();

{'fraction_non_alphanumeric': 0.183507613790808, 'fraction_numerical': 0.007488974565223421, 'mean_word_length': 3.0469188461106747, 'pattern_counts': {'":': 8, '<': 289, '<?xml version=': 0, '>': 275, 'https://': 6, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2790721', 'n_tokens_mistral': 11423, 'n_tokens_neox': 11035, 'n_words': 1666}