(function($) { 
    new WOW().init();
	$('[data-toggle="offcanvas"]').on('click', function () {
		$('.navbar-collapse').toggleClass('show');
    });
	$(document).ready(function() {
		$('.pgwSlider').pgwSlider({
			transitionEffect:"sliding",	
			displayControls:true,
			touchControls:true,
			verticalCentering:true,
			adaptiveHeight:true,
			maxHeight:410,
			intervalDuration:16000
		});
	});

/* ================ Revolution Slider. ================ */
  if($('.tp-banner').length > 0){
    $('.tp-banner').show().revolution({
      delay:6000,
          startheight: 380,
          startwidth: 1170,
          hideThumbs: 1000,
          navigationType: 'none',
          touchenabled: 'on',
          onHoverStop: 'on',
          navOffsetHorizontal: 0,
          navOffsetVertical: 0,
          dottedOverlay: 'none',
          fullWidth: 'on'
    });
  }
  if($('.tp-banner-full').length > 0){
    $('.tp-banner-full').show().revolution({
      delay:6000,
          hideThumbs: 1000,
          navigationType: 'none',
          touchenabled: 'on',
          onHoverStop: 'on',
          navOffsetHorizontal: 0,
          navOffsetVertical: 0,
          dottedOverlay: 'none',
          fullScreen: 'on'
    });
  } 
  


    /*==== Nav ====*/
    $('.navbar-collapse a').on('click',function(){
        $(".navbar-collapse").collapse('hide');
    });

/* ================ Nav ================ */
    $('.fa-caret-down').on("click", function(e) {
        e.preventDefault();
        $(this).next().slideToggle('');
    });
    

/* ================ Nice Select ================ */
    $(document).ready(function() {
  $('select').niceSelect();
});



  // The slider being synced must be initialized first
  $('#carousel').flexslider({
    animation: "slide",
    controlNav: false,
    animationLoop: false,
    slideshow: false,
    itemWidth: 210,
    itemMargin: 5,
    asNavFor: '#slider'
  });
 
  $('#slider').flexslider({
    animation: "slide",
    controlNav: false,
    animationLoop: false,
    slideshow: false,
    sync: "#carousel"
  });


})(jQuery);

if ($('.strnix-carousel').length) {
		$(".strnix-carousel").each(function (index) {
		var $owlAttr = {navText: [ '<span class="icon fa fa-angle-left"></span>', '<span class="icon fa fa-angle-right"></span>' ]},
		$extraAttr = $(this).data("options");
		$.extend($owlAttr, $extraAttr);
		$(this).owlCarousel($owlAttr);
	});
}
$(function() {
    $('.scrollto').on('click', function() {
        var target = $(this.hash);
        target = target.length ? target : $('[name=' + this.hash.substr(1) +']');
        if (target.length) {
            $('html,body').animate({
                scrollTop: target.offset().top
            }, 2000);
            return false;
        }
    });
});

var $owlnn = $('.home-history-carousel').owlCarousel();
$owlnn.on("initialized.owl.carousel changed.owl.carousel", function(e) {
if (!e.namespace) {return;}
var current_sl = e.relatedTarget.relative(e.item.index) + 1;

//alert(current_sl);

if(current_sl == 1){
	$(".testimonial-section").removeClass("promoting-plantation ");
	$(".testimonial-section").removeClass("low-carbon");
	$(".testimonial-section").removeClass("e-waste");
	$(".testimonial-section").addClass("renewal-energy");
} else if (current_sl == 2){
	$(".testimonial-section").removeClass("renewal-energy");
	$(".testimonial-section").removeClass("low-carbon");
	$(".testimonial-section").removeClass("promoting-plantation");
	$(".testimonial-section").addClass("e-waste");
} else if (current_sl == 3){
	$(".testimonial-section").removeClass("e-waste");
	$(".testimonial-section").removeClass("promoting-plantation");
	$(".testimonial-section").removeClass("renewal-energy");
	$(".testimonial-section").addClass("low-carbon");
	
} else if (current_sl == 4){
	$(".testimonial-section").removeClass("low-carbon");
	$(".testimonial-section").removeClass("renewal-energy");
	$(".testimonial-section").removeClass("e-waste");
	$(".testimonial-section").addClass("promoting-plantation");		
} 

//$(".num").text(e.relatedTarget.relative(e.item.index) + 1 + "/" + e.item.count);


});

$(".campaign-photo-slider").slick({
  dots: false,
  infinite: true,
  slidesToShow: 15,
  slidesToScroll: 1,
  accessibility:true,
  autoplay:true,
  pauseOnHover:true,
  pauseOnFocus:false,
  responsive: [{
	breakpoint: 1024,
	settings: {
	  slidesToShow: 12,
	  infinite: true
	}
  }, {
	breakpoint: 600,
	settings: {
	  slidesToShow: 8,
	  dots: true
	}
  }, {
	breakpoint: 300,
	settings: "unslick" // destroys slick
  }],
  speed: 1000,
  swipe:true,
  touchMove:true,
});

(function() {

	var width = 260; // We will scale the photo width to this
	var height = ''; // This will be computed based on the input stream

	var streaming = false;

	var video = null;
	var canvas = null;
	var photo = null;
	var startbutton = null;

	function startup() {
		video = document.getElementById('video');
		canvas = document.getElementById('canvas');
		photo = document.getElementById('photo');
		startbutton = document.getElementById('startbutton');

		navigator.mediaDevices.getUserMedia({
				video: true,
				audio: false
			})
			.then(function(stream) {
				video.srcObject = stream;
				video.play();
			})
			.catch(function(err) {
				console.log("An error occurred: " + err);
			});

		video.addEventListener('canplay', function(ev) {
			if (!streaming) {
				height = video.videoHeight / (video.videoWidth / width);

				if (isNaN(height)) {
					height = width / (4 / 3);
				}

				video.setAttribute('width', width);
				video.setAttribute('height', height);
				canvas.setAttribute('width', width);
				canvas.setAttribute('height', height);
				streaming = true;
			}
		}, false);

		startbutton.addEventListener('click', function(ev) {
			takepicture();
			ev.preventDefault();
		}, false);

		clearphoto();
	}


	function clearphoto() {
		var context = canvas.getContext('2d');
		context.fillStyle = "#AAA";
		context.fillRect(0, 0, canvas.width, canvas.height);

		var data = canvas.toDataURL('image/png');
		//photo.setAttribute('src', data);
		//photo.attr("value",data);
		
	}
	

	function takepicture() {
		var context = canvas.getContext('2d');
		if (width && height) {
			canvas.width = width;
			canvas.height = height;
			context.drawImage(video, 0, 0, width, height);

			var data = canvas.toDataURL('image/png');
		   // photo.setAttribute('src', data);
			$('#taken-photo').attr("value",data);
			$('#selected-img').attr("value", 'Image Captured');
			
		} else {
			clearphoto();
		}
	}
	$('#startcam').click(function(){
		startup();
		$(this).hide();
	});
	//window.addEventListener('load', startup, false);
})();

$(document).ready(function() {
	$('.popup-gallery').magnificPopup({
		delegate: 'a',
		type: 'image',
		
		gallery: {
			enabled: true,
		}
	});
});
$('.ts-image-popup').magnificPopup({
  type: 'inline',
  closeOnContentClick: false,
  midClick: true,
  callbacks: {
	 beforeOpen: function () {
		this.st.mainClass = this.st.el.attr('data-effect');
	 }
  },
  zoom: {
	 enabled: true,
	 duration: 500, // don't foget to change the duration also in CSS
  },
  mainClass: 'mfp-fade',
});
$('.popup-youtube').magnificPopup({
	disableOn: 700,
	type: 'iframe',
	mainClass: 'mfp-fade',
	removalDelay: 160,
	preloader: false,

	fixedContentPos: true
});

if ($('#schedule-tab .schedule-tab-title').length) {
	var tabWrap = $('#schedule-tab .schedule-tab-content');
	var tabClicker = $('#schedule-tab .schedule-tab-title tr td');
	
	tabWrap.children('div').hide();
	tabWrap.children('div').eq(0).show();
	tabClicker.on('click', function() {
		var tabName = $(this).data('tab-name');
		tabClicker.removeClass('active');
		$(this).addClass('active');
		var id = '#'+ tabName;
		tabWrap.children('div').not(id).hide();
		tabWrap.children('div'+id).fadeIn('500');
		return false;
	});        
}


const coverflowSlider = new Swiper('.coverflow-slider', {
  effect: 'coverflow',
  grabCursor: true,
  centeredSlides: true,
  slidesPerView: 1,
  loop: false,
  initialSlide: 1,
  spaceBetween: 0,
  coverflowEffect: {
	rotate: 20,
	stretch: 0,
	depth: 200,
	modifier: 1,
	slideShadows: true
  },
  breakpoints: {
	991: {
	  slidesPerView: 'auto'
	},
	575: {
	  slidesPerView: 2
	}
  }
});
$(".andro_music-player-backward").on('click', function(e) {
  e.preventDefault();
  coverflowSlider.slidePrev();
});
$(".andro_music-player-forward").on('click', function(e) {
  e.preventDefault();
  coverflowSlider.slideNext();
});

$('.panel-collapse').collapse({
  toggle: false
});