 /*
  _____      						 _______ 	     
 |  __ \  							|_ _ _ _| _  	 	    
 | |__) | 					     _	   | |	 | |	        
 |  ___/    ___    __ _    __ _  | |    | |	 | |__     ___ 	 _ __  _ __    ___ 
 | |\ \    / _ \  / _` |  / _` | | |    | |	 | '_ \   / _ \ | '_ \| '_ \  / _ \
 | | \ \  |  __/ | (_| | | (_| | | |    | |	 | | | | |  __/ | |  ||  | | |  __/
 |_|  \ \  \___|  \__, |  \__,_| |_|    |_|   |_| |_|  \___| |_|  ||  |_|  \___|
                   __/ |              
                  |___/  		     
 ================================================================================ */
 (function($) {
     "use strict";

     /*
     MOBILE MENU
     ================================== */
     //  Main menu
     var MainLiDrop = $('.mainmenu li.dropdown,.mainmenu li.sub-dropdown');
     MainLiDrop.append('<div class="dropdown-btn"></div>');
     //Dropdown Button
     var MainLiDDbtn = $('.mainmenu li.dropdown .dropdown-btn');
     MainLiDDbtn.on('click', function() {
         $(this).toggleClass('submenu-icon');
         $(this).prev('ul').slideToggle(400);
     });

     /*
     STICKY
     ================================== */
     var AcSticky = $('.active-sticky');
     var WinD = $(window);
     WinD.on('scroll', function() {
         var scroll = $(window).scrollTop();
         var AESticky = AcSticky;
         if (scroll < 245) {
             AESticky.removeClass("is-sticky");
         } else {
             AESticky.addClass("is-sticky");
         }
     });

     /*
     PROGRESS WITH WAYPOINT ACTIVE
     ================================== */

     var ProWey = $('.skill-progress');
     if (ProWey.length > 0) {
         ProWey.waypoint(function() {
             // element 
             jQuery('.skill-bar').each(function() {
                 jQuery(this).find('.progress-content').animate({
                     width: jQuery(this).attr('data-percentage')
                 }, 2000);

                 jQuery(this).find('.progress-mark').animate({
                     left: jQuery(this).attr('data-percentage')
                 }, {
                     duration: 2150,
                     step: function(now, fx) {
                         var data = Math.round(now);
                         jQuery(this).find('.percent').html(data + '%');
                     }
                 });

             });
         }, {
             offset: '90%'
         });
     }

     /*
     ISOTOPE ACTIVE
     ================================ */

     // isotope menu
     var ProjMli = $('.portfolio-menu li');
     var ProjGrid = $('.portfolio-grid');
     ProjMli.on('click', function() {
         ProjMli.removeClass("active");
         $(this).addClass("active");
         var selector = $(this).attr('data-filter');
         ProjGrid.isotope({
             filter: selector,
             animationOptions: {
                 duration: 750,
                 easing: 'linear',
                 queue: false,
             }
         });
     });

     /*
     FANCYBOX POPUP
     ================================ */
     var FanBox = $('.fancybox');
     FanBox.fancybox({
         openEffect: 'fade',
         closeEffect: 'fade',
         padding: 0,
         closeBtn: true,
         helpers: {
             title: {
                 type: 'inside'
             },
             buttons: {}
         },
         helpers: {
             overlay: {
                 locked: false
             }
         }
     });
     /* YOUTUBE VIDEO POPUP
     --------------------*/
     $(".various").fancybox({
         'padding': 0,
         maxWidth: 800,
         maxHeight: 600,
         fitToView: false,
         width: '70%',
         height: '70%',
         autoSize: false,
         closeClick: false,
         openEffect: 'fade',
         closeEffect: 'fade'
     });

     /*
     SLICK CAROUSEL AS NAV
     ===================================*/
     var OneITem = $('.one-item');
     var TesITem = $('.testimonial-item');
     var SliThr = $('.slider-three');
     OneITem.slick({
         dots: true,
         arrows: true,
         prevArrow: '<i class="prev zmdi zmdi-chevron-left"></i>',
         nextArrow: '<i class="next zmdi zmdi-chevron-right"></i>'
     });
     TesITem.slick({
         dots: false,
         arrows: false,
         autoplay: true,
         autoplaySpeed: 4000
     });
     SliThr.slick({
         dots: true,
         arrows: false,
         prevArrow: '<i class="prev zmdi zmdi-chevron-left"></i>',
         nextArrow: '<i class="next zmdi zmdi-chevron-right"></i>'
     });

     /*
     CONTACT FORM VALIDATIONS SETTINGS
     ========================================*/
     var CTForm = $('#contact_form');
     CTForm.validate({
         onfocusout: false,
         onkeyup: false,
         rules: {
             name: "required",
             email: {
                 required: true,
                 email: true
             }
         },
         errorPlacement: function(error, element) {
             error.insertBefore(element);
         },
         messages: {
             name: "What's your name?",
             email: {
                 required: "What's your email?",
                 email: "Please, enter a valid email"
             }
         },
         highlight: function(element) {
             $(element)
                 .text('').addClass('error')
         },
         success: function(element) {
             element
                 .text('').addClass('valid')
         }
     });

     /*
     CONTACT FORM SCRIPT
     ========================================*/
     var CTSubmit = $('#contact_submit');
     CTForm.submit(function() {
         // submit the form
         if ($(this).valid()) {
             CTSubmit.button('loading');
             var action = $(this).attr('action');
             $.ajax({
                 url: action,
                 type: 'POST',
                 data: {
                     contactname: $('#contact_name').val(),
                     contactemail: $('#contact_email').val(),
                     contactmessage: $('#contact_message').val()
                 },
                 success: function() {
                     CTSubmit.button('reset');
                     CTSubmit.button('complete');
                 },
                 error: function() {
                     CTSubmit.button('reset');
                     CTSubmit.button('error');
                 }
             });
             // return false to prevent normal browser submit and page navigation 
         } else {
             CTSubmit.button('reset')
         }
         return false;
     });

     /*
     SCROLLUP
     ================================ */
     $.scrollUp({
         scrollText: '<i class="zmdi zmdi-arrow-left"></i> <p>Top<p/>',
         easingType: 'linear',
         scrollSpeed: 500,
         animation: 'slide'
     });

     jQuery(window).on('load', function() {
         // Preloader
         var preeLoad = $('#loading-wrap');
         preeLoad.fadeOut(1000);

         // isotope fitRows grid
         var IsoGriddoload = $('.fitRows-grid');
         IsoGriddoload.isotope({
             itemSelector: '.grid-item',
             // layout mode options
             layoutMode: 'fitRows'
         });
         // isotope masonry grid
         var IsoGriddoload = $('.masonry-grid');
         IsoGriddoload.isotope({
             itemSelector: '.grid-item',
             // layout mode options
             masonryHorizontal: {
                 rowHeight: 100
             }
         });

         /*
         COUNT UP ACTIVE JQUERY
         ================================== */
         var CoUNT = $('.counter');
         CoUNT.counterUp({
             delay: 50,
             time: 3000
         });
     });

 })(jQuery);