/** *************Init JS*********************
	
    TABLE OF CONTENTS
	---------------------------
	1.Ready function
	2.Load function
	3.Full height function
	4.Full height function
	5.Resize function
	6.kenny function
	7.Photoswipe init
 ** ***************************************/
 
 "use strict"; 

/*****Ready function start*****/
$(document).ready(function(){
  kenny();
  $('.la-anim-1').addClass('la-animate');
});
/*****Ready function end*****/

/*****Load function start*****/
$(window).load(function(){
	$(".preloader-it").delay(500).fadeOut("slow");
});
/*****Load function* end*****/

/***** Full height function start *****/
var setHeight = function () {
	var height = $(window).height();
	$('.full-height').css('height', (height));
	$('.page-wrapper').css('min-height', (height));
	
	/*Vertical Tab Height Cal Start*/
	var verticalTab = $(".vertical-tab");
	if( verticalTab.length > 0 ){ 
		for(var i = 0; i < verticalTab.length; i++){
			var $this =$(verticalTab[i]);
			$this.find('ul.nav').css(
			  'min-height', ''
			);
			$this.find('.tab-content').css(
			  'min-height', ''
			);
			height = $this.find('ul.ver-nav-tab').height();
			$this.find('ul.nav').css(
			  'min-height', height + 40
			);
			$this.find('.tab-content').css(
			  'min-height', height + 40
			);
		}
	}
	/*Vertical Tab Height Cal End*/
};
/***** Full height function end *****/

/***** Resize function start *****/
$(window).on("resize", function () {
	setHeight();
}).resize();
/***** Resize function end *****/

/***** Kenny function start *****/
var kenny = function(){
	
	/*Counter Animation*/
	var counterAnim = $('.counter-anim');
	if( counterAnim.length > 0 ){
		counterAnim.counterUp({ delay: 10,
        time: 100});
	}
	
	/*Tooltip*/
	if( $('[data-toggle="tooltip"]').length > 0 )
		$('[data-toggle="tooltip"]').tooltip();
	
	/*Popover*/
	if( $('[data-toggle="popover"]').length > 0 )
		$('[data-toggle="popover"]').popover()
	
	/*Progress Bar Animation*/
	var progressAnim = $('.progress-anim');
	if( progressAnim.length > 0 ){
		for(var i = 0; i < progressAnim.length; i++){
			var $this = $(progressAnim[i]);
			$this.waypoint(function() {
			var progressBar = $(".progress-anim .progress-bar");
			for(var i = 0; i < progressBar.length; i++){
				$this = $(progressBar[i]);
				$this.css("width", $this.attr("aria-valuenow") + "%");
			}
			}, {
			  triggerOnce: true,
			  offset: 'bottom-in-view'
			});
		}
	}	
	
	/*Panel Remove*/
	$('.clickable').on('click',function(e){
		e.preventDefault();
		var effect = $(this).data('effect');
			$(this).closest('.panel')[effect]();
		return false;	
	});
	
	/*Accordion js*/
	$('.panel-collapse').on('show.bs.collapse', function () {
		$(this).siblings('.panel-heading').addClass('activestate');
	});
	$('.panel-collapse').on('hide.bs.collapse', function () {
		$(this).siblings('.panel-heading').removeClass('activestate');
	});
	
	/*Sidebar Navigation*/
	$( "#toggle_nav_btn" ).on( "click", function() {
		$(".wrapper").toggleClass('slide-nav-toggle');
		return false;
	});
	$( "#open_right_sidebar" ).on( "click", function() {
		$(".wrapper").toggleClass('open-right-sidebar');
		return false;
	});
	
	/*Todo*/
	var random = Math.random();
	$(document).on("click","#add_todo",function (e) {
		if (!$('.new-todo input').val().length == 0) {
				$('<li class="todo-item"><div class="checkbox checkbox-success"><input type="checkbox" id="checkbox'+random+'"/><label for="checkbox'+random+'">' + $('.new-todo input').val() + '</label></div></li>').insertAfter(".todo-list .todo-item:last-child");
				$('.new-todo input').val('');
		} else{
				alert('Please enter task!');
		}
		return false;
	});
	
	/*Chat*/
	$("#input_msg_send").keypress(function (e) {
		if ((e.which == 13)&&(!$(this).val().length == 0)) {
			$('<li class="self"><div class="self-msg-wrap"><div class="msg block pull-right">' + $(this).val() + '<div class="msg-per-detail mt-5"><span class="msg-time txt-grey">4:30pm</span></div></div></div><div class="clearfix"></div></li>').insertAfter(".chat-content > ul li:last-child");
			$(this).val('');
		} else if(e.which == 13) {
			alert('Please type somthing!');
		}
	});
	$(document).on("click",".chat-cmplt-wrap .chat-data",function (e) {
		$(".recent-chat-box-wrap").fadeIn("fast");
		$(".chat-cmplt-wrap").addClass('chat-box-slide');
		setTimeout(function(){
			$(".chat-box-wrap").fadeOut("slow");
		},300);
		
		return false;
	});
	$(document).on("click",".chat-cmplt-wrap .goto-chat-list",function (e) {
		e.preventDefault();
		$(".chat-box-wrap").fadeIn("slow");
		setTimeout(function(){
			$(".chat-cmplt-wrap").removeClass('chat-box-slide');
			$(".recent-chat-box-wrap").fadeOut("slow");
		},300);
		
		return false;
	});
	/*Slimscroll*/
	$('.nicescroll-bar').slimscroll({height:'100%',color: '#3cb878'});
	$('.message-nicescroll-bar').slimscroll({height:'320px',color: '#3cb878'});
};
/***** Kenny function end *****/
