//JSHint Validated Custom JS Code by Designova

/*global $:false */
/*global window: false */
jQuery(document).ready(function($) {
(function(){
  "use strict";


$(function ($) {
// $("html").niceScroll();
    $(".rb-overlay").niceScroll({cursorwidth:"1px"});
  $(".masonary-blog-video").fitVids();
     //Detecting viewpot dimension and calculating the adjustments of components
     var vW = $(window).width();
     var vH = $(window).height();
     var vHperc25 = vH*25/100;
     var vHperc15 = vH*15/100;
     var vHperc20 = vH*20/100;
     if(vW > 1400)
     {
       $('.splash-home').css('min-height', vH);
       $('.splash-home').css('padding-top', vHperc20);
     }

    $('.splash-home').css('min-height', vH);
    $('#thesplashrotate').css('margin-top', vHperc15);
     //Counting number of nav-items and adjusting the height accordingly
    var navCount = $('#sidebar-nav ul li').size();
    var navHeight = vH/navCount;
    $('#sidebar-nav ul li').css('height',navHeight);



    $('.carousel').carousel({
      interval: 2000
    });



    //Nav highlight
    $('#mast-nav li > a').click(function(){
        $('#mast-nav li > a').removeClass('active');
        $(this).addClass('active');
    });

    $('.page-section').mouseenter(function(){
        var sectionId = $(this).attr('id');
        $('#mast-nav li > a').removeClass('active');
        $('#'+sectionId+'-linker').addClass('active');
    });

    //Parallax Init
    $(window).stellar({
        responsive: false,
        horizontalScrolling: false,
        parallaxBackgrounds: true,
        parallaxElements: true,
        hideDistantElements: true
    });




    //WAYPOINTS - INTERACTION
    //======================

    $('.skill-wrap').waypoint(function (event, direction) {
        if (direction === 'down') {
            //Pie-Chart Invokes
      $(function()
      {
         $(".theskill").each(function()
          {
              $(this).css('visibility','visible');
              var skillId  = $(this).attr('id');
              var color    = $(this).attr("data-color");
              if(skillId !='')
              {
                  $('#' + skillId).easyPieChart({
                      barColor: color ,
                      trackColor: '#ccc',
                      scaleColor: false,
                      lineCap: 'butt',
                      lineWidth: 15,
                      size: 140,
                      animate: 2000,
                  });
              }

          });
        });
    }},{ offset: 300 });


//Slidebar Menu - State Changes
$('.sq-side-menu ul li a').click(function(){
  $('.sq-side-menu ul li a').removeClass(' sq-active');
  $(this).addClass(' sq-active');
});

//Page nav activation
var page_stack = $.makeArray();
    var stack_top = 0;
    $('.page-section').waypoint(function (event, direction) {
        if (direction === 'down')
        {
            $('.sq-side-menu ul li a').removeClass('sq-active');
            $('#mast-nav li > a').removeClass('active');
            $('.sq-side-menu ul li a[href="#'+$(this).attr('id')+'"]').addClass('sq-active');
            $('#mast-nav li > a[href="#'+$(this).attr('id')+'"]').addClass('active');
            stack_top = stack_top+1;
            page_stack[stack_top] = $(this).attr('id');

        }
        else
        {
            stack_top = stack_top-1;
            $('.sq-side-menu ul li a').removeClass('sq-active');
            $('#mast-nav li > a').removeClass('active');
            $('.sq-side-menu ul li a[href="#'+page_stack[stack_top]+'"]').addClass('sq-active');
            $('#mast-nav li > a[href="#'+$(this).attr('id')+'"]').addClass('active'); 

        }
    },{ offset: 100 });







//Metro Panel - Rotating Tiles
  $('#metro-panel .thumb').on('rotate',function(){
    var thisOne = $(this);
    thisOne.addClass('active');
    var time =getRandomInt(3,10)*1000;
    setTimeout(function(){
      thisOne.removeClass('active');
    },time);
  });
  setInterval(function(){
    var thumbs = $('#metro-panel .thumb:not(.active)');
    $(thumbs[getRandomInt(0,thumbs.length)]).trigger('rotate');
  },3000);



//Custom functions

/**
 * Returns a random integer between min and max
 * Using Math.round() will give you a non-uniform distribution!
 */
function getRandomInt (min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
}


 $('#post-comment').addClass('btn btn-next-alt add-top add-bottom');
 $('.btn-saga-dark').addClass('btn btn-next-alt');

});


})();



});
