// fix-menu

jQuery(function($) {
  function fixDiv() {
    var windowsize = $(window).width();
    var home_header = $(".header");

    
    if ($(window).scrollTop() >60  && windowsize>=768){
        home_header.addClass( "scroll" );
    }else{
		home_header.removeClass("scroll");
	}

}

  $(window).scroll(fixDiv);
fixDiv();
}); 

//
/* Animate Nael*/



$(function() {
    $('.bottom-banner').each(function(index, el) {
        var img = $(el).children('img');
        $(el).css('background', 'url(' + img.attr('src') + ') 50% 50% / contain fixed');
        img.remove();
    });
});


var scrollCb = function () {
    var tiles = $(".text-banner div:not(.animated)");
    var $window = $(window);
    var b = $window.scrollTop() + $window.height();

    tiles.each(function (i) {
        var $this = $(this);
        var a = $this.offset().top + $this.height();

        if (a < b) {
            $this.children().addClass(" animated fadeInUp delay1 duration2   eds-on-scroll");
        }
      else {
        $this.children().removeClass(" animated fadeInUp delay1 duration2 eds-on-scroll");
      }
    });
};

$(scrollCb);

$(window).scroll(scrollCb);


/* End */
$(function(){
    $('ul#brands-terms-list > li, .sub-menu > li').hover(
        function(){
            var submenu = $(this).find('ul.sub-menu');
            $(this).children('a:first').addClass('active');
            if (submenu.hasClass('sub-menu')){
                submenu.removeClass('hide');
            }
        },
        function(){
            var submenu = $(this).find('ul.sub-menu');
            $(this).children('a:first').removeClass('active');
            if (submenu.hasClass('sub-menu')){
                submenu.addClass('hide');
            }
    });
}); 


var ptts = 0;

var total = $("ul#text-cycler-text-list li").size() + 1;
var count = 1;
var total2 = $("ul#text-cycler-index-list li").size() + 1;
var count2 = 1;


function text_cycle() {
            $("ul#text-cycler-text-list li").stop().hide();
            count++;
            if (count == total) {
              count = 1;
            }
            $("ul#text-cycler-text-list li:nth-child("+count+")").stop().delay(100).fadeIn(500);

            
            
            $("ul#text-cycler-index-list li").removeClass('active');
            count2++;
            if (count2 == total2) {
              count2 = 1;
            }
            $("ul#text-cycler-index-list li:nth-child("+count2+")").addClass('active');


}




$(document).ready(function (){
    $('.loader').fadeOut(3000);
    
    $(".fancybox").fancybox();
    
    
    
    $('.sub-menu').addClass('hide');                                          
    
    
    $("[placeholder]").focus(function () {
        var e = $(this);
        if (e.val() == e.attr("placeholder")) {
            e.val("");
            e.removeClass("placeholder")
        }
    }).blur(function () {
        var e = $(this);
        if (e.val() == "" || e.val() == e.attr("placeholder")) {
            e.addClass("placeholder");
            e.val(e.attr("placeholder"))
        }
    }).blur().parents("form").submit(function () {
        $(this).find("[placeholder]").each(function () {
            var e = $(this);
            if (e.val() == e.attr("placeholder")) {
                e.val("")
            }
        })
    });
    $("[placeholder]").parents("form").submit(function () {
        $(this).find("[placeholder]").each(function () {
            var e = $(this);
            if (e.val() == e.attr("placeholder")) {
                e.val("")
            }
        })
    });
    
    
    

    
    
    
    
    $('#home-slider-prev').click(function() {
        if (!$('#home-images-slider-list').find('li:visible').is(':first-child')) {
            var dlip =  $('#home-images-slider-list').find('li:visible').prev();
            $('#home-images-slider-list').find('li').hide();
            dlip.fadeIn(500).css("display","block");
        }
    });
    
    $('#home-slider-next').click(function() {
        if (!$('#home-images-slider-list').find('li:visible').is(':last-child')) {
            var dlin =  $('#home-images-slider-list').find('li:visible').next();
            $('#home-images-slider-list').find('li').hide();
            dlin.fadeIn(500).css("display","block");
        }
    });
    
    
    
    
    
    $('#home-who-we-are').click(function(event){
    	event.preventDefault();
	    $('html,body').unbind().animate({scrollTop: $('#home-who-we-are-cont').offset().top-100},'1000');
    });
    

    
    
    
    
    $('.cycle-list-buttons').click(function() {
        var dir = $(this).attr("data-id");
        var list = $(this).attr("data-list");
        
        if (dir == 'prev') {
            cycle_list('prev', list);
        } else if (dir == 'next') {
            cycle_list('next', list);
        }
        
    });
    
    


    var sub_menu_counter = $('.sub-menu-cont ul > li').size();
    if (sub_menu_counter == 2) {
        $('.sub-menu-cont ul > li').css({'width':'50%', 'text-align': 'center'});
    } else if (sub_menu_counter == 3) {
        $('.sub-menu-cont ul > li').css({'width':'33%', 'text-align': 'center'});
    } else if (sub_menu_counter == 4) {
        $('.sub-menu-cont ul > li').css({'width':'25%', 'text-align': 'center'});
    } else if (sub_menu_counter == 5) {
        $('.sub-menu-cont ul > li').css({'width':'20%', 'text-align': 'center'});
    } else if (sub_menu_counter == 6) {
        $('.sub-menu-cont ul > li').css({'width':'16%', 'text-align': 'center'});
    }
    

    
});


jQuery('a:not(.home-slider-arrows)').each( function() {
    var ja = $(this);
    if (!ja.parent().hasClass('arrow')) {

    var $this = jQuery(this), 
        target = this.hash;
    jQuery(this).click(function (e) { 
        //e.preventDefault();
        if( $this.length > 0 ) {
            if($this.attr('href') == '#' ) {
                // Do nothing   
            } else {
               jQuery('html, body').stop().animate({ 
                    scrollTop: (jQuery(target).offset().top - ptts) 
                }, 1000);
            }  
        }
    });
    
    }
});  




function cycle_list(dir, list) {
    
    if (dir == 'prev') {
        
        if (!$('#'+list).find('li:visible').is(':first-child')) {
            var dlip =  $('#'+list).find('li:visible').prev();
            $('#'+list).find('li').hide();
            dlip.fadeIn(500);
        }
        
    } else if (dir == 'next') {
        
        if (!$('#'+list).find('li:visible').is(':last-child')) {
            var dlin =  $('#'+list).find('li:visible').next();
            $('#'+list).find('li').hide();
            dlin.fadeIn(500);
        }
        
    }
}



$(window).load(function () {
    ptts = $('.sub-menu-cont').height();
    
    window.setInterval(function(){
            text_cycle();
        }, 5000);
    
    window.setInterval(function(){
    
	    	var dlip =  $('#home-images-slider-list').find('li:visible').next();
	    	
	    	if (!$('#home-images-slider-list').find('li:visible').is(':last-child')) {
	    		$('#home-images-slider-list').find('li').hide();
	            dlip.fadeIn(500).css("display","block");
	    	} else {
	    		$('#home-images-slider-list').find('li').hide();
	    		$('#home-images-slider-list').find('li:first').fadeIn(500).css("display","block");
	    	}
    	

	}, 5000);   
});















$(window).scroll(function(){
    
    
    
      if ($(this).scrollTop() > 100) {
          $('.sub-menu-cont').addClass('fixedsm');
          $('.wrapper').css('padding-top', ptts+'px');
      } else {
          $('.sub-menu-cont').removeClass('fixedsm');
          $('.wrapper').css('padding-top', '0');
      }
  });


/***********************
Button Submit
***********************/

document.querySelector('.button-submit').onmousemove = function (e) {

	var x = e.pageX - e.target.offsetLeft;
	var y = e.pageY - e.target.offsetTop;

	e.target.style.setProperty('--x', x + 'px');
	e.target.style.setProperty('--y', y + 'px');
};

/******************************
label submit
******************************/

var $input = $('.form-fieldset > input');

$input.blur(function (e) {
  $(this).toggleClass('filled', !!$(this).val());
});

var $textarea = $('.form-fieldset > textarea');

$textarea.blur(function (e) {
  $(this).toggleClass('filled', !!$(this).val());
});

/* Calender JS*/
var $days = $('.round-list.days');
var $months = $('.round-list.months');
var $years = $('.round-list.years');
var $events = $('.events-container');
var $dots = $('.dots');

populateCalendar();
positionDigits();
showEvent(0);

$dots.on('click', 'li', function () {
    showEvent($(this).index());
});

function showEvent(index) {
    var $event = $events.children().eq(index);
    $events.children().removeClass('current move-left');
    $event.addClass('current').prevAll().addClass('move-left');
    $dots.children().removeClass('current').eq(index).addClass('current');

    var date = new Date($event.data('date'));
    rotateListToDigit($days, date.getDate());
    rotateListToDigit($months, date.getMonth());
    rotateListToDigit($years, date.getFullYear());
}

function rotateListToDigit(list, digit) {
    var current = list.children('[data-value="' + digit + '"]').addClass('current');
    var angleDelta = 360 / list.children().length;
    var rotation = -angleDelta * current.index();
    current.siblings().removeClass('current');
    list.css('transform', 'rotate(' + rotation + 'deg)');
}

function populateCalendar() {
    // populate days
    for (var i = 1; i <= 31; i++) {
        $days.append('<li data-value="' + i + '">' + i + '</li>');
    }
    // populate months
    'Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec'.split(' ').forEach(function (month, i) {
        return $months.append('<li data-value="' + i + '">' + month + '</li>');
    });
    // populate years
    var year = new Date().getFullYear();
    for (var _i = 0; _i < 18; _i++) {
        $years.append('<li data-value="' + (year + _i) + '">' + (year + _i) + '</li>');
    }
}

function positionDigits() {
    // position days digits
    positionDigitsOf($days);
    positionDigitsOf($months);
    positionDigitsOf($years);
}

function positionDigitsOf(list) {
    var angleDelta = 360 / list.children().length;
    list.children().each(function (i) {
        var angle = 180 - angleDelta * i;
        var position = getPointAtAngle(angle, list.width() / 2);
        positionDigitAt($(this), position, angle);
    });
}

function positionDigitAt(digit, position, angle) {
    var transform = ['translate(' + position.x + 'px, ' + position.y + 'px)', 'rotate(' + (180 - angle) + 'deg)'];
    digit.css('transform', transform.join(' '));
}

function getPointAtAngle(angle, distance) {
    angle = deg2rad(angle);
    return { x: Math.sin(angle) * distance, y: Math.cos(angle) * distance };
}

function deg2rad(angle) {
    return angle * (Math.PI / 180);
}

function rad2deg(angle) {
    return angle * (180 / Math.PI);
}