// JavaScript Document
jQuery(document).ready(function($) {
 	"use strict"; 

/* Youtube Player */
jQuery(".player").mb_YTPlayer();

/* Video Fit Div */
 $(".fitvideo").fitVids();


/* parallax
================================================== */
   
   	if( !/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
	
	$('.parallax-background').each(function(){
	   $(this).parallax("50%",.1);
	});
	
	}


	

/* nicescroll
================================================== */		
var $smoothActive = $('body').attr('data-smooth-scrolling'); 
if( $smoothActive == 1){ niceScrollInit(); }
  function niceScrollInit() { 
   $("html").niceScroll({
			scrollspeed: 60,
			mousescrollstep: 40,
			cursorwidth: 6,
			cursorborder: 0,
			cursorcolor: '#555',
			cursorborderradius: 2,
			autohidemode: false,
			horizrailenabled: false
		});
  }


  /* Add Class 
================================================== 		
var $transparentActive = $('body').attr('data-transparent-mode'); 
if( $transparentActive == 1){ $('body').addClass('transparent-nav'); }
*/

  
	
/* Site Menus
================================================== */  				
var $navMode = $('body').attr('data-nav-mode'); 
if( $navMode == "side" ){ tendinaNavInit();}
else if( $navMode == "push" ){ tendinaNavInit(); pushNavInit();}  
else if( $navMode == "default" ){ menuzordNavInit(); } 

	/* menuzord Menu
================================================== */  
function menuzordNavInit() { 
jQuery("#menuzord").menuzord({
					align: "right",
					indicatorFirstLevel: "<i class='fa fa-angle-down'></i>",
					indicatorSecondLevel: "<i class='fa fa-angle-right'></i>"
				});
} 

	/* tendina Menu
================================================== */  
  function tendinaNavInit() { 
   $('.sidebar-nav').tendina({
        // This is a setup made only
        // to show which options you can use,
        // it doesn't actually make sense!
        animate: true,
        speed: 500,
        onHover: true,
        hoverDelay: 200,
		activeMenu: null,
        openCallback: function(clickedEl) {
          clickedEl.addClass('opened');
        },
        closeCallback: function(clickedEl) {
           clickedEl.addClass('closed');
        }
      })
	
	 
	// Here you bind the mouseout event on the tendina helper class
	$(document).on('mouseout', '.tendina', function() {
	  setTimeout(function() {
		if (!$('.tendina').is(':hover')) {
		  $('.tendina').find('> li > ul').slideUp().parent().removeClass('selected');
		}
	  }, 500);
	});
 
  }	

	/* push Menu
================================================== */    
function pushNavInit() { 
var body = document.body,
		mask = document.createElement("div"),
		togglePushRight = document.querySelector( ".toggle-push-right" ),
		pushMenuRight = document.querySelector( ".push-menu-right" ),

		activeNav
	;
	mask.className = "mask";

	/* push menu right */
	togglePushRight.addEventListener( "click", function(){
		classie.add( body, "pmr-open" );
		document.body.appendChild(mask);
		activeNav = "pmr-open";
	} );

	

	/* hide active menu if mask is clicked */
	mask.addEventListener( "click", function(){
		classie.remove( body, activeNav );
		activeNav = "";
		document.body.removeChild(mask);
	} );

	/* hide active menu if close menu button is clicked */
	[].slice.call(document.querySelectorAll(".close-menu")).forEach(function(el,i){
		el.addEventListener( "click", function(){
			classie.remove( body, activeNav );
			activeNav = "";
			document.body.removeChild(mask);
		} );
	});
	
	}



/* scrollIt
================================================== */	
$(function(){
$.scrollIt({
upKey: 38, // key code to navigate to the next section
downKey: 40, // key code to navigate to the previous section
easing: 'linear', // the easing function for animation
scrollTime: 800, // how long (in ms) the animation takes
activeClass: 'active', // class given to the active nav element
onPageChange: null, // function(pageIndex) that is called when page is changed
topOffset: -40 // offste (in px) for fixed top navigation
});
});	
	
	/* animated
================================================== */
	
	 $('*[data-animated]').addClass('animated');
            function animated_contents() {
                $(".animated:appeared").each(function (i) {
                    var $this    = $(this),
                        animated = $(this).data('animated');

                    setTimeout(function () {
                        $this.addClass(animated);
                    }, 50 * i);

                });
            }

            animated_contents();
            $(window).scroll(function () {
                animated_contents();
            });
			
			
/* chart
================================================== */ 
 function initPieCharts() {
        var chart = $('.chart');
        chart.appear();
        chart.each(function() {
        $(this).on('appear', function() {
                var $this = $(this),
				chartBarColor = ($this.data('barcolor')) ? $this.data('barcolor') : "#3498db";
                if( !$this.hasClass('pie-chart-loaded') ) {
                    $this.easyPieChart({
                    animate: 2000,
					barColor: chartBarColor,
					trackColor: '#CCCCCC',
					scaleColor: '',
					scaleLength: 5,
					lineCap: 'square',
					lineWidth: 10,
					size: 140,
					rotate: 10,
					
					onStep: function(from, to, percent) {
					$(this.el).find('.percent').text(Math.round(percent));
					}
					
                    }).addClass('pie-chart-loaded');

                }
            });
        });
    }
  initPieCharts();

  
 /* //count to
================================================== */   
  		 
		 // custom formatting example
		  $('.count').data('countToOptions', {
			formatter: function (value, options) {
			  return value.toFixed(options.decimals).replace(/\B(?=(?:\d{3})+(?!\d))/g, ',');
			}
		  });
		  
		// start a timer when on appear
		var counter = $('.count');
        counter.appear();
		counter.each(function() {
		$(this).on('appear', function() {
		var $this = $(this);
				if( !$this.hasClass('counter-loaded') ) {
					$('.timer').each(count);
					$this.addClass('counter-loaded');
                }
        
      });
	  });

		  
		  function count(options) {
			var $this = $(this);
			options = $.extend({}, options || {}, $this.data('countToOptions') || {});
			$this.countTo(options);
		  }
		  
 
  /* Comming Soon Count Down
================================================== */  		
var $comeSoonActive = $('.comesoon-timer').attr('data-comesoon-active'); 
if( $comeSoonActive == 1){ comeSoonActiveInit(); }
  function comeSoonActiveInit() { 
 
		// Create a countdown instance. Change the launchDay according to your needs.
		// The month ranges from 0 to 11. I specify the month from 1 to 12 and manually subtract the 1.
		// Thus the launchDay below denotes 7 May, 2014.
		var countDownYear = parseInt($('#timer').attr('data-count-year'));
		var countDownMonth = parseInt($('#timer').attr('data-count-month'));
		var countDownDay = parseInt($('#timer').attr('data-count-day'));
		
		if( isNaN(countDownYear) || isNaN(countDownMonth) || isNaN(countDownDay) ) { 
		var newYear = new Date(); 
		var newYear = new Date(newYear.getFullYear() + 1, 1 - 1, 1); 
		$('#timer').countdown({
			until: newYear
		});
	
		}else{
		var launchDay = new Date(countDownYear, countDownMonth-1, countDownDay);
		$('#timer').countdown({
			until: launchDay
		});
		}
		
	} 
			
			
	
		
  
/* //Skill Bar Filling
================================================== */   
	function scrollBarFiller(){
		var scrollTop = $(window).scrollTop();
		var bars = $('.not-loaded');
		bars.each(function(){
			var offsetTop = $(this).offset().top;
			var evenThem = offsetTop - scrollTop - $(window).height() + $(this).height();
			if(evenThem <= 0){
				$(this).removeClass('not-loaded');
				$(this).css('width', $(this).data('width')+'%');
			}

		});
	}
	
	$(window).scroll(function(){
		var scrolling;
		scrolling = setInterval(function(){
			scrollBarFiller();
			clearInterval(scrolling);
		},100);
	});
	  

	  
	  
 /* Owl Carsouel
================================================== */  		  
// Testimonial		
		var testimonial = $(".clients-carousel");
		testimonial.each(function () {
			var $that = $(this);

			$that.owlCarousel({
			slideSpeed : 200,
			pagination : false,
			paginationSpeed : 400,
			autoPlay : true,
			lazyLoad : true,
			stopOnHover :true,
			singleItem:true
		}); 					
	});
	
// Team		
		var team = $(".team-carousel");
		team.each(function () {
			var $that = $(this);

			$that.owlCarousel({
			 items : 4,
			lazyLoad : true,
			navigation : true,
			pagination:false,
			autoPlay : 6000,
			stopOnHover :true,
			navigationText : ['<i class="fa fa-angle-left"></i>','<i class="fa fa-angle-right"></i>']
		}); 
							
	});	
	
	
// Logos		
		var logos = $(".logos-carousel");
		logos.each(function () {
			var $that = $(this);

			$that.owlCarousel({
			slideSpeed : 200,
			pagination : false,
			paginationSpeed : 400,
			autoPlay : true,
			stopOnHover :true,
			lazyLoad : true,
			items :4,
		}); 
	
								
	});
		

// Portfolio Carousel		
		var portfolio = $(".portfolio-carousel");
		portfolio.each(function () {
			var $that = $(this);

			$that.owlCarousel({
			 items : 3,
			lazyLoad : true,
			navigation : false,
			pagination:false,
			autoPlay : 6000,
			stopOnHover :true,
			navigationText : ['<i class="fa fa-angle-left"></i>','<i class="fa fa-angle-right"></i>']
		}); 
							
	});			

// Portfolio single	
		var folio = $(".folio");
		folio.each(function () {
			var $that = $(this);

			$that.owlCarousel({
			slideSpeed : 200,
			paginationSpeed : 400,
			pagination : false,
			navigationText : ['<i class="fa fa-angle-left"></i>','<i class="fa fa-angle-right"></i>'],
			navigation : true,
			autoPlay : true,
			stopOnHover :true,
			lazyLoad : true,
			singleItem:true
		}); 
	
								
	});
						
// Banner Text Slider
	$(".text-slider").owlCarousel({
      navigation : false, // Show next and prev buttons
      slideSpeed : 400,
      paginationSpeed : 500,
      singleItem:true,
	  pagination:false,
	  autoPlay : 9000,
	  stopOnHover :true,
	  transitionStyle : "fade"
  }); 


 // Banner juicyslider
var $juicyActive = $('#home').attr('data-slider-type'); 
if( $juicyActive == 'jucslider'){ jucsliderActiveInit(); }
function jucsliderActiveInit() {
    $('#jucslider').juicyslider({
	  mask: 'square',
      autoplay: 9000,
      show: {effect: 'puff', duration: 2000},
      hide: {effect: 'puff', duration: 2000},
      width: '100%',
      height: null,
       });
	  }

	  


 
 /* Portfolio Grid
================================================== */  		
var $gridActive = $('.grid-wrap').attr('data-gride-element'); 
if( $gridActive == 1){ gridElementInit(); }
  function gridElementInit() { 
  new GridScrollFx( document.getElementById( 'grid' ), {
				viewportFactor : 0.4
			} );

		
		// init Isotope
		//isotope Grid	
			var $isotopeContainer = $('#grid');
			$isotopeContainer.isotope();
			$('#filters a').click(function(){
			$('#filters a.active').removeClass('active');
			var selector = $(this).attr('data-filter');
			$isotopeContainer.isotope({
					filter: selector,
					itemSelector: '.item',
					animationOptions:{
					duration: 750,
					easing: 'linear',
					queue: false,
				}
			});
			$(this).addClass('active');
		  return false;
		});
		
}// end portfolio init





// blog Masonory
var $blogMasActive = $('#blog-main').attr('data-mas-enable'); 
if( $blogMasActive == '1'){ blogMasActiveInit(); }
function blogMasActiveInit() { 

var $container = jQuery('#blog-main').masonry();
// layout Masonry again after all images have loaded
$container.imagesLoaded( function() {
  $container.masonry({
  itemSelector: '.post-item',
});

});
}

	  // post Gallery	
		var postGal = $(".post-gallery");
		postGal.each(function () {
		var $that = $(this);

		$that.owlCarousel({
			slideSpeed : 200,
			paginationSpeed : 400,
			pagination : false,
			navigationText : ['<i class="fa fa-angle-left"></i>','<i class="fa fa-angle-right"></i>'],
			 navigation : true,
			autoPlay : true,
			lazyLoad : true,
			singleItem:true
		}); 
	
								
	});


//}

 /* Screw slider
================================================== */ 
var $homeSkewActive = $('#homeslider').attr('data-slider-type'); 
if( $homeSkewActive == 'homeskew'){ homeSkewActiveInit(); }
function homeSkewActiveInit() { 
// Home slider	 
            $('#homeslider').skewSlider({
                 speed: 1300,
                 centered: true,
                 slidePercent: 90,
                // ratio: 40/11,
				 ratio: false,
				 height: 600,
                 itemPadding: true,
                 breakpoints: {
                    tablet: {
                        maxWidth : 1024,
                        slidePercent : 95,
                        ratio : 40/20,
                        moveOnHover: 3,
                        skew: -20,
                        itemPadding: false
                    },
                    phone: {
                        maxWidth : 600,
                        slidePercent : 100,
                        ratio : 40/28,
                        skew: -15
                    }
                }
             });

}//Home skew init
			 
			 
// Gallery slider	
var $galSkewActive = $('#galleryslider').attr('data-slider-type'); 
if( $galSkewActive == 'galskew'){ galSkewActiveInit(); }
function galSkewActiveInit() { 	  
            $('#galleryslider').skewSlider({
                 speed: 1300,
                 centered: true,
                 slidePercent: 70,
                 ratio: 40/12,
                 itemPadding: true,
                 breakpoints: {
                    tablet: {
                        maxWidth : 1024,
                        slidePercent : 95,
                        ratio : 40/20,
                        moveOnHover: 3,
                        skew: -20,
                        itemPadding: false
                    },
                    phone: {
                        maxWidth : 600,
                        slidePercent : 100,
                        ratio : 40/28,
                        skew: -15
                    }
                }
             });	
}//Gallery slider init			 
			 
// Team Slider	
var $teamSkewActive = $('#teamslider').attr('data-slider-type'); 
if( $teamSkewActive == 'teamskew'){ teamSkewActiveInit(); }
function teamSkewActiveInit() { 	 
			 
 			 $('#teamslider').skewSlider({
				 speed: 850,
                 easing: 'ease',
                 skew: 0,
                 delay: 300,
                 speedDiference: 150,
                 slidePercent: 32,
                 height: 320,
                 centered: true,
                 preloadCount: 4,
                 setCurrent: 0,
                 moveFx: false,
                 navDots: true,
                 infiniteSlide: true,
                 itemPadding: false,
                 clickOnSiblings: true,
                 moveOnHover: 4,
                 ratio: 40/10,
                 slideshow: false,
                 showCaption: true,
                 breakpoints: {
                    tablet: {
                        maxWidth : 1024,
                        slidePercent : 45,
                        ratio : 40/15,
                        moveOnHover: 3,
                        moveFx: false,
                        showCaption: false,
                        skew: 0,
                    },
                    phone: {
                        maxWidth : 600,
                        ratio : 40/15,
                        slidePercent : 40,
                        skew: 0
                    }
                }
             });
			 
 
//====================== Team Slider EXAMPLE OF CUSTOM BEHAVIOR USING THE API ===================== // 

           // slide container
           var $parent = $('.cont'),
               $team = $('#teamslider');

         
                   // on each slide mouseenter event
                   $parent.find('.skw-list li').on('mouseenter', function(){
                        var $this = $(this),
                            // index of the active slide, if infiniteslide is true, we have to deduct the preloadCount val 
                            index = $this.index()-4;

                        // making sure we only trigger the update once
                        if ( !$parent.hasClass('opened') ) {
                            
                            // triguering css animations
                            $parent.addClass('opened'); 

                            // apply the update method using the api
                            $team.skewSlider('update', 
                            {
                                slidePercent: 100,
                                setCurrent: index,
                                speed: 1200,
                                breakpoints: {
                                    tablet: {
                                        maxWidth : 1024,
                                        slidePercent : 95,
                                        ratio: 40/20
                                    },
                                    phone: {
                                        maxWidth : 600,
                                        slidePercent : 95,
                                        ratio: 40/20
                                    }
                                }

                            }, function(success){
                                 if(!success){
                                    $parent.removeClass('opened');
                                }   
                            }, 600, true);
                         } 
                    });

                    $parent.on('mouseleave', function(){
                        var $this = $(this);

                        $parent.removeClass('opened');

                        // calling update method without options (or null) will restore the original options    
                        $team.skewSlider('update', null, 
                         function(success){
                            if(!success){
                                $parent.addClass('opened');
                            }
                        }, 600, true);
                    });
					
		  }//team slider init
		  
		  
		  
		//Social share
		var completed = 0;
		var windowLocation = window.location.href.replace(window.location.hash, '');
		
		////facebook share
		//load share count on load  
		$.getJSON("http://graph.facebook.com/?id="+ windowLocation +'&callback=?', function(data) {
			if((data.shares != 0) && (data.shares != undefined) && (data.shares != null)) { 
				$('.facebook-share a span.count, a.facebook-share span.count').html( data.shares );	
			}
			else {
				$('.facebook-share a span.count, a.facebook-share span.count').html( 0 );	
			}
			completed++;
			socialFade();
		});
	 
		function facebookShare(){
			window.open( 'https://www.facebook.com/sharer/sharer.php?u='+windowLocation, "facebookWindow", "height=380,width=660,resizable=0,toolbar=0,menubar=0,status=0,location=0,scrollbars=0" ) 
			return false;
		}
		
		$('.facebook-share').click(facebookShare);		


		////twitter
		
		//load tweet count on load 
		$.getJSON('http://urls.api.twitter.com/1/urls/count.json?url='+windowLocation+'&callback=?', function(data) {
			if((data.count != 0) && (data.count != undefined) && (data.count != null)) { 
				$('.twitter-share a span.count, a.twitter-share span.count').html( data.count );
			}
			else {
				$('.twitter-share a span.count, a.twitter-share span.count').html( 0 );
			}
			completed++;
			socialFade();
		});
		
		function twitterShare(){
			if($(".section-title h1").length > 0) {
				var $pageTitle = encodeURIComponent($(".section-title h1").text());
			} else {
				var $pageTitle = encodeURIComponent($(document).find("title").text());
			}
			window.open( 'http://twitter.com/intent/tweet?text='+$pageTitle +' '+windowLocation, "twitterWindow", "height=380,width=660,resizable=0,toolbar=0,menubar=0,status=0,location=0,scrollbars=0" ) 
			return false;
		}

		$('.twitter-share').click(twitterShare);

		
		
			////pinterest
		
		//load pin count on load 
		$.getJSON('http://api.pinterest.com/v1/urls/count.json?url='+windowLocation+'&callback=?', function(data) {
			if((data.count != 0) && (data.count != undefined) && (data.count != null)) { 
				$('.pinterest-share a span.count, a.pinterest-share span.count').html( data.count );
			}
			else {
				$('.pinterest-share a span.count, a.pinterest-share span.count').html( 0 );
			}
			completed++;
			socialFade();
		});
		
		function pinterestShare(){
			var $sharingImg = ($('.single-portfolio').length > 0 && $('div[data-featured-img]').attr('data-featured-img') != 'empty' ) ? $('div[data-featured-img]').attr('data-featured-img') : $('.main-content img').first().attr('src'); 
			
			if($(".section-title h1").length > 0) {
				var $pageTitle = encodeURIComponent($(".section-title h1").text());
			} else {
				var $pageTitle = encodeURIComponent($(document).find("title").text());
			}
			
			window.open( 'http://pinterest.com/pin/create/button/?url='+windowLocation+'&media='+$sharingImg+'&description='+$pageTitle, "pinterestWindow", "height=640,width=660,resizable=0,toolbar=0,menubar=0,status=0,location=0,scrollbars=0" ) 
			return false;
		}
		

		$('.pinterest-share').click(pinterestShare);


});
//End Document.ready   




/* preloader
================================================== */ 
jQuery(window).load(function() { // makes sure the whole site is loaded
	'use strict';   
	jQuery('#status').fadeOut(); // will first fade out the loading animation
	jQuery('#preloader').delay(350).fadeOut('slow'); // will fade out the white DIV that covers the website.
	jQuery('body').delay(350).css({'overflow':'visible'});
})

