function getMobileOperatingSystem() {
  var userAgent = navigator.userAgent || navigator.vendor || window.opera;

    // Windows Phone must come first because its UA also contains "Android"
    if (/windows phone/i.test(userAgent)) {
        $("html").addClass("win_phone");
    }

    if (/android/i.test(userAgent)) {
        $("html").addClass("android");
    }

    // iOS detection from: http://stackoverflow.com/a/9039885/177710
    if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
        $("html").addClass("ios");
    }
}

var isOpera = !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0; 
    // Opera 8.0+ (UA detection to detect Blink/v8-powered Opera)
var isFirefox = typeof InstallTrigger !== 'undefined';   // Firefox 1.0+
var isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0;
    // At least Safari 3+: "[object HTMLElementConstructor]"
var isChrome = !!window.chrome && !isOpera;              // Chrome 1+
var isIE = /*@cc_on!@*/false || !!document.documentMode; // At least IE6

function is_touch_device() {
   return (('ontouchstart' in window)
    || (navigator.MaxTouchPoints > 0)
    || (navigator.msMaxTouchPoints > 0));
}

var rtime = new Date(1, 1, 2000, 12,00,00);
var timeout = false;
var delta = 200;

$(window).on("resize",function() {
    rtime = new Date();
    if (timeout === false) {
        timeout = true;
        setTimeout(resizeend, delta);
    }
});

function resizeend() {
    if (new Date() - rtime < delta) {
        setTimeout(resizeend, delta);
    } else {
        timeout = false;  
        all_process();
    }
}

$( window ).on( "orientationchange", function(e) {
    if(is_touch_device())
    { 
      if (window.RT) clearTimeout(window.RT);
      window.RT = setTimeout(function()
      {
        all_process();
      }, 100);
    }
});

$(window).bind("load", function() {
  getMobileOperatingSystem();
    all_process();
    setTimeout(
      function() 
      {   

	  
            if(!$.fn.isotope) return false;
            $(".portfolio_links a").click(function(){
                $(".portfolio_links a").removeClass("active");
                $(this).addClass("active");
            });

            $('.grid').isotope({isOriginLeft: false});

            $('.portfolio_links a').click(function(){
                var selector = $(this).attr('data-filter');
                $('.grid').isotope({ filter: selector, isOriginLeft: false });
                return false;
            });

      }, 50);
});

function all_process(){
  if($(".inner_page").length > 0){
    $("#header").addClass("active");
    $(".header").addClass("active");
    $(".grid li .overload").css("width",$(".grid li img").width())
    $(".grid li .overload").css("height",$(".grid li img").height())
  }

  $("#section4 .content #our_clients .owl-stage-outer").css("height",$("#section4 .content #our_clients.owl-carousel .owl-stage-outer .owl-item").outerHeight()+20);
  $("#section8 .content #our_media .owl-stage-outer").css("height",$("#section8 .content #our_media.owl-carousel .owl-stage-outer .owl-item").outerHeight()+20);
  $("#section12 .content #our_clients2 .owl-stage-outer").css("height",$("#section12 .content #our_clients2.owl-carousel .owl-stage-outer .owl-item").outerHeight()+100);
  var ft1 = $("#twitter").outerHeight();
  var ft2 = $("#blog").outerHeight();
  var ft3 = $("#testimonial").outerHeight();
  var ft_max = 0;
  if(ft1 >= ft2 && ft1>= ft3){
    ft_max = ft1;
  }
  if(ft2 >= ft3 && ft2>= ft1){
    ft_max = ft2;
  }
  if(ft3 >= ft1 && ft3>= ft2){
    ft_max = ft3;
  }    
  $("#twitter").css("min-height",ft_max);
  $("#blog").css("min-height",ft_max);
  $("#testimonial").css("min-height",ft_max);

  $("#between").css("min-height",$(window).outerHeight()-($("#header").outerHeight()+$("#footer").outerHeight()+5)); 
}

$(document).ready(function() {
    if(!$.fn.uniform) return false; 
    $(".footer_tab_contact ul li select").uniform();    
});

$(document).ready(function() {
  if(!$.fn.jPushMenu) return false;
  $('.toggle-menu').jPushMenu();
});

$(document).ready(function() {
  if(!$.fn.mCustomScrollbar) return false;
  $("#section5 .content.by_csb").mCustomScrollbar({
      axis:"x"
  });
  $("#twitter .content").mCustomScrollbar({
      axis:"y"
  });

});

$(document).ready(function(){
    $('[data-toggles="tooltip"]').tooltip();

    if(!$(".inner_page").length > 0){
      var s = $("#section1"), o = s.outerHeight();
      $(document).scroll(function() {
          var e = (o - window.scrollY) / o;
          if(e >= 0.2){ 
            s.css("opacity", e + .2)
            $("#header").removeClass("active");
            $(".header").removeClass("active");
          }else {
            $("#header").addClass("active");
            $(".header").addClass("active");
          }
         
      }); 
    } 

    $("#section5 .content ul li").each(function(){
        $(this).hover(function(){
            $("#section5 .content ul li .item").removeClass("active");
            $(this).find(".item").addClass("active");
        });
    }); 

    $(".inner_page_tools .share > a").click(function(){
      $(this).toggleClass("active");
      $(this).next().fadeToggle();
      return false;
    });    
});

$(document).ready(function() {
    $(".six6w svg path , .six6w svg text").click(function(){
    $(".six6w svg path , .six6w svg text").removeAttr("data-class");
    $(".six6w_description ul li").hide();
    var my_class=$(this).attr("class");
    $('.six6w_description ul li.'+my_class).fadeIn();
    $('.six6w svg path.'+my_class).attr("data-class","active");
    $('.six6w svg text.'+$(this).attr('class')+'').attr("data-class","active");
  });


  var angle = 0;
  var inta;
  rotateImage();

  function rotateImage() {
      inta = setInterval(function() {
          angle += 3;
          $(".six6w svg").rotate({
            angle: angle,
            duration:2500,
          });
      }, 125);
  }

  $(".six6w svg").mouseover(function(){
    clearInterval(inta)
  }).mouseout(function(){
      rotateImage();
  });

  //Affix Page Option
  $('.inner_page_tools > ul').affix({
      offset: {
          top: $('.header').outerHeight(true) - 100
      }
  });
});

$(document).scroll(function(){
  if($(this).scrollTop()>($("#section1").outerHeight()+($("#section2").outerHeight()/2))){
    $("#section3 .six6w_big").css("top","65%");
  }
  else{
    $("#section3 .six6w_big").css("top","5px");
  }
});

$(function() {  
  $('#da-thumbs > .item').each( function() { $(this).hoverdir(); } );
});