"use strict";
/****** ANIMATION *****/
var wow = new WOW(
  {
    animateClass: 'animated',
    offset:       100,
    callback:     function(box) {
      //console.log("WOW: animating <" + box.tagName.toLowerCase() + ">")
    }
  }
);
wow.init();


/******* DOCUMENT READY START *********/
$(document).ready(function(){
  
  /****** SLIDER *****/
  $('#t-banner_slider').bxSlider({
   controls: false
  });
  /****** SLIDER *****/
  $("#our_service").tinycarousel({
	    bullets  : true,
	    axis: "y"
	});
  /****** SKILL BAR *****/
  SkillBar();
  /****** SKILL BAR *****/

  /****** Our Team Carousel *****/
  OurTeamCarousel();
  /****** Our Team Carousel *****/

  /****** Client Tesimonial Carousel *****/
  ClientTesimonial()
  /****** Client Tesimonial Carousel *****/

  /****** Client Logo Carousel *****/
  ClientLogo();
  /****** Client Logo Carousel *****/

  /****** Client Logo Carousel *****/
  TheProcess();
  /****** Client Logo Carousel *****/

  /****** Form Validation *****/
  FormValidation();
  /****** Form Validation *****/
  
  /****** HomeBlog Height *****/
  HomeBlogHight()
  /****** HomeBlog Height *****/
  
  /****** Our Work *****/	
  	$(document).on('click', "#t-our_work_cat > ul > li a", function() {
		var work_data_val = $(this).data('target');
		$(this).parents("ul").find('li.active_service').removeClass('active_service');
		$(this).parent("li").addClass('active_service');
		OurWork(work_data_val);

		if(typeof $(this).data("rel") != "undefined" ){
			var current_id = $(this).data("rel");
			$(".t-our_work_portfolio").fadeOut("slow");
			$("#"+current_id).fadeIn("slow");
			$(".t-our_work_portfolio").css("max-height",$(".t-our_work_portfolio >  div.js-masonry").height());
		}
		return false;
	});
  	
  OurWork($(document).find("#t-our_work_cat > ul > li a:first").data('target'));
  /****** Our Work *****/ 	

  ServiceHeight();

 $('#header_nav > ul > li > a').on('click',function (e) {
   $('#header_nav > ul > li > a').removeClass('t_active');
   $(this).addClass('t_active');  	  	
   e.preventDefault();
   e.stopPropagation();	
   $('html, body').stop().animate({
        'scrollTop': $($(this).attr('href')).offset().top
    }, 900, 'swing', function () {});
   return false;
 });

 $(document).on("scroll", onScroll);

 $('.t-counter').counterUp({
    delay: 100,
    time: 3000
 });

 $('#t-back_to_top').on('click', function(){
   $('html, body').animate({scrollTop : 0},800);
	   return false;
 }); 

 $('#t-header_mobile_nav').on('click', function(){
    $('#header_nav').slideToggle('slow');
    return false;
 }); 

 ColorSelector();
 
 if(window.location.hash) {
    var url = document.URL;
    var hash = url.substring(url.indexOf('#')); // '#foo'
    $('html, body').animate({
        scrollTop: $(hash).offset().top
    }, 2000);
  }
});
/******* DOCUMENT READY END *********/

$(window).resize(function() {
	ServiceHeight();

  if($(window).width() > 767){
    $("#header_nav").show();
  }
});



$(window).load(function() {
	$(".t-masonary .t-our_work_portfolio").hide("fast"); 
	$(".t-masonary #t-our_work_1").show("slow");
	$("#all").trigger('click');
	/****** Sticky Header *****/
 	 HeaderStick();	
    /****** Sticky Header *****/

    setTimeout(
    function() 
    {
      $("body").removeClass('t-overlay');
    }, 1500);
});

function ServiceHeight(){
	var service_left = $(".t-our_service_content").outerHeight();
	$(".t-our_service_image").height(service_left);
}

function SkillBar(){
	 $('.skill_1').css('width', '60%');
     $('.skill_2').css('width', '40%');
     $('.skill_3').css('width', '80%');
     $('.skill_4').css('width', '50%');
}


function OurTeamCarousel(){
	var our_team = $("#t-our_team_carousel");
	our_team.owlCarousel({
		items : 4, //10 items above 1000px browser width
		itemsDesktop : [1000,4], //5 items between 1000px and 901px
		itemsDesktopSmall : [900,3], // 3 items betweem 900px and 601px
		itemsTablet: [600,1], //2 items between 600 and 0;
		itemsMobile : false, // itemsMobile disabled - inherit from itemsTablet option
		pagination :false
	});

    $( ".t-next_team" ).on( "click", function() {
	  our_team.trigger('owl.next');
	  return false;
	});
	$( ".t-prev_team" ).on( "click", function() {
	  our_team.trigger('owl.prev');
	  return false;
	});

}

function ClientTesimonial(){
	var client_testimonial = $("#t-client_testimonial_carousel");
	client_testimonial.owlCarousel({
		items : 1, //10 items above 1000px browser width
		itemsDesktop : [1000,1], //5 items between 1000px and 901px
		itemsDesktopSmall : [900,1], // 3 items betweem 900px and 601px
		itemsTablet: [600,1], //2 items between 600 and 0;
		itemsMobile : false // itemsMobile disabled - inherit from itemsTablet option
	});
}


function ClientLogo(){
	var client_logo = $("#t-client_logo_carousel");
	client_logo.owlCarousel({
		items : 5, //10 items above 1000px browser width
		itemsDesktop : [1000,5], //5 items between 1000px and 901px
		itemsDesktopSmall : [900,4], // 3 items betweem 900px and 601px
		itemsTablet: [600,1], //2 items between 600 and 0;
		itemsMobile : false, // itemsMobile disabled - inherit from itemsTablet option
		pagination :false
	});

	$( ".t-next_logo" ).on( "click", function() {
	  client_logo.trigger('owl.next');
	  return false;
	});
	$( ".t-prev_logo" ).on( "click", function() {
	  client_logo.trigger('owl.prev');
	  return false;
	});
}

function FormValidation(){
	$("#get_in_touch").validate({
      rules: {
        name: "required",
        email: {
          required: true,
          email: true
        },
        subject: "required" 
      },
      messages: {
        name: "Please enter your name",
        email: "Please enter valid email",
        subject: "Please enter your subject" 
      }
    });
}



function OurWork(our_work){
	if(typeof our_work != "undefined"){
		
		$(our_work).owlCarousel({
			items : 5, //10 items above 1000px browser width
			itemsDesktop : [1000,5], //5 items between 1000px and 901px
			itemsDesktopSmall : [900,3], // 3 items betweem 900px and 601px
			itemsTablet: [600,2], //2 items between 600 and 0;
			itemsMobile : [479,1], // itemsMobile disabled - inherit from itemsTablet option
			pagination :false,
			lazyLoad : true
		});
		$(document).on("click", ".t-next_our_work",function() {
		  $(our_work).trigger('owl.next');
		  return false;
		});

		$(document).on( "click", ".t-prev_our_work", function() {
		  $(our_work).trigger('owl.prev');
		  return false;
		});
		$("div.t-our_work_portfolio").fadeOut();
		$(our_work).parent("div").fadeIn();
	}
}


function TheProcess(){
	var the_process = $("#t-the_process_carousel");
	the_process.owlCarousel({
		items : 1, //10 items above 1000px browser width
		itemsDesktop : [1000,1], //5 items between 1000px and 901px
		itemsDesktopSmall : [900,1], // 3 items betweem 900px and 601px
		itemsTablet: [600,1], //2 items between 600 and 0;
		itemsMobile : false, // itemsMobile disabled - inherit from itemsTablet option
		pagination :true,
		paginationNumbers : true
	});
}


function HeaderStick(){
	var distance = $('#t-who_we_are').offset().top;
	 $(window).scroll(function(){
        if($(document).scrollTop() > distance) {
        	$("#t-header").addClass('t-sticky_header');
        }else{
        	$("#t-header").removeClass('t-sticky_header');
        	$("#header_nav > ul > li:first-child > a").addClass('t_active');
        }
     });       	
}

function onScroll(event){
    var scrollPos = $(document).scrollTop();
    $('#header_nav > ul > li > a').each(function () {
        var currLink = $(this);
        var refElement = $(currLink.attr("href"));
        if (refElement.position().top <= scrollPos && refElement.position().top + refElement.height() > scrollPos) {
            $('#header_nav > ul > li > a').removeClass("active");
            currLink.addClass("t_active");
        }
        else{
            currLink.removeClass("t_active");
        }
    });
}

function HomeBlogHight(){
	var win_width =  $(window).width();
	if(win_width > 1200){
		var Img_height = $(".t-home_blog_img > div > img").height();
		$(".t-home_blog_content_inner").css({
      "max-height": Img_height,
      "height": Img_height
    });
	}
}

function ColorSelector(){
      $("#t-color_selector_list > li > span").on('click', function(event) {
        $("#t-color_selector_list > li > span i.fa-check").removeClass('fa-check');
        $(this).find('i').addClass('fa-check');  
        $( "body" ).addClass('t-overlay');
        ChkIt(this);
        return false;
    });
}

function ChkIt(color_rels){
    var Themes = {
      "red":"assets/css/theme/main_red.css",
      "mid_blue":"assets/css/theme/main_mid_blue.css",
      "nephritis":"assets/css/theme/main_nephritis.css",
      "green_sea":"assets/css/theme/main_green_sea.css",
      "orange":"assets/css/theme/main_orange.css",
      "pink":"assets/css/theme/main_pink.css",
      "yellow":"assets/css/theme/main_yellow.css",
      "saddle":"assets/css/theme/main_saddle.css",
      "main":"assets/css/main.css"
    };
    var color_rel = $(color_rels).attr("data-rel");
      if(Themes.hasOwnProperty(color_rel)){ 
        $(document).find("link#ThemeRoller").remove();
        SwitchTheme(Themes[color_rel]);
        /*$(document).find("link#ThemeRoller").attr("href",Themes[color_rel]);*/
      }
    
}

function SwitchTheme(href){
  var wjs = document.createElement('link');
  wjs.type = 'text/css';
  wjs.id = 'ThemeRoller';
  wjs.async = true;
  wjs.rel="stylesheet";
  wjs.onload = function(){
    $("body").removeClass('t-overlay');
  };
  wjs.href = href;
  (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(wjs);
} 

$(document).click(function(e) { 
	if ($("#gx-sidemenu").hasClass("opened") && (!$('#gx-sidemenu-inner-1').is(e.target)) && ($(e.target).parents('#gx-sidemenu-inner-1').length == 0))
    {
	    $("#gx-sidemenu").removeClass("opened");
	      $( "#gx-sidemenu" ).animate({
		    left: "-280px",
		  }, 500, function() {
		  });
	}
});

/****** BACK TO TOP *****/
$(window).scroll(function() {
    if ($(document).scrollTop() > 500) {
        $('#t-back_to_top').fadeIn();
    } else {
        $('#t-back_to_top').fadeOut();
    }
});