// Utf-8 é
$(document).ready(function() {

    /*-------------TABLE RESPONSIVE ---------*/
    // Setup responsive table
    var header = Array();
    //first get the data from the headings
    $(".responsive_style_table thead th").each(function(i, v) {
            header[i] = $(this).text();
        });
        //now loop through table rows and apply headings to the td in each row
    $(".responsive_style_table tbody tr").each(function(i, v) {
        var myRow = $(this);

        myRow.find('td').each(function(j) {
            $(this).attr('data-thead', header[j]);

        });
    });


    $(window).scroll(function(event){
       var st = $(this).scrollTop();
       if (st > 300 ){
           // downscroll code
           $('.addthis_inline_share_toolbox').addClass("fix-social");
       }
       if (st < 150 ){
            $('.addthis_inline_share_toolbox').removeClass("fix-social");
       }
    });


	/* ================ Show Login box. ================ */
	$('.login-btn').prepend('<b class="tri hidden"></b>');
	$('.login-btn').click(function(e){
		e.preventDefault();
        $(this).toggleClass('active_hd');
		$('.login-box').slideToggle();
		$('.login-btn').find('.tri').toggleClass('visible');
		$('.close-login').click(function(e){
			e.preventDefault();
            $('.login-btn').toggleClass('active_hd');
			$('.login-box').slideUp();
			$('.login-btn').find('.tri').removeClass('visible');
		});
	});

    $("#main_slider").owlCarousel({
        autoPlay : 6000,
        stopOnHover : true,
        navigation:true,
        pagination:false,
        paginationSpeed : 3000,
        goToFirstSpeed : 2000,
        singleItem : true,
        autoHeight : true,
        navigationText: [
           "<i class='fa fa-chevron-left'></i>",
           "<i class='fa fa-chevron-right'></i>"
        ],
        transitionStyle:"fade"
    });
     
    /*
	$("#secondary_slider").owlCarousel({
        autoPlay : 6000,
        stopOnHover : true,
        navigation:true,
        pagination:false,
        paginationSpeed : 1000,
        goToFirstSpeed : 2000,
        singleItem : false,
		items:4,
        autoHeight : true,
        navigationText: [
           "<i class='fa fa-chevron-left'></i>",
           "<i class='fa fa-chevron-right'></i>"
        ],
        transitionStyle:"fade"
    });
    */
    // Initialize to unread notifications
    // TODO: add badge for unread notifications

    // Show/Hide Notifications Drawer
    $('.drawer-pf-trigger').click(function() {
      var $drawer = $('.drawer-pf');

      $(this).toggleClass('open');
      if ($drawer.hasClass('hide')) {
        $drawer.removeClass('hide');
        setTimeout(function () {
          if (window.dispatchEvent) {
            window.dispatchEvent(new Event('resize'));
          }
          // Special case for IE
          if ($(document).fireEvent) {
            $(document).fireEvent('onresize');
          }
        }, 100);
      } else {
        $drawer.addClass('hide');
      }
      // Special case, close navigation menu in mobile mode
     if ($('.container-pf-nav-pf-vertical').hasClass('hidden-nav')) {
       $('.nav-pf-vertical').removeClass('show-mobile-nav');
     }
    });
    $('.drawer-pf-close').click(function() {
      var $drawer = $('.drawer-pf');

      $('.drawer-pf-trigger').removeClass('open');
      $drawer.addClass('hide');
    });
    $('.drawer-pf-toggle-expand').click(function() {
      var $drawer = $('.drawer-pf');
      var $drawerNotifications = $drawer.find('.drawer-pf-notification');

      if ($drawer.hasClass('drawer-pf-expanded')) {
        $drawer.removeClass('drawer-pf-expanded');
        $drawerNotifications.removeClass('expanded-notification');
      } else {
        $drawer.addClass('drawer-pf-expanded');
        $drawerNotifications.addClass('expanded-notification');
      }
    });

    // Mark All Read / Clear All
    $('.panel-collapse').each(function (index, panel) {
      var $panel = $(panel);
      var unreadCount = $panel.find('.drawer-pf-notification.unread').length;
      $(panel.parentElement).find('.panel-counter').text(unreadCount + ' New Event' + (unreadCount !== 1 ? 's' : ''));

      if ($('.drawer-pf .panel-collapse .unread').length === 0) {
        // TODO: remove badge for unread indicator
      }

      $panel.on('click', '.drawer-pf-action [data-toggle="mark-all-read"] .btn', function() {
        $panel.find('.unread').removeClass('unread');
        $panel.find('.drawer-pf-action [data-toggle="mark-all-read"]').remove();
        $(panel.parentElement).find('.panel-counter').text('0 New Events');
        if ($('.drawer-pf .panel-collapse .unread').length === 0) {
          $('.drawer-pf-trigger').removeClass('unread');
        }
      });
      $panel.on('click', '.drawer-pf-action [data-toggle="clear-all"] .btn', function() {
        $panel.find('.panel-body .drawer-pf-notification').remove();
        $panel.find('.drawer-pf-action').remove();
        $panel.find('.blank-slate-pf').removeClass('hidden');
        $panel.find('.drawer-pf-loading').addClass('hidden');
        $(panel.parentElement).find('.panel-counter').text('0 New Events');
        if ($('.drawer-pf .panel-collapse .unread').length === 0) {
          // TODO: remove badge for unread indicator
        }
      });

      $panel.find('.drawer-pf-notification').each(function (index, notification) {
        var $notification = $(notification);
        $notification.on('click', '.drawer-pf-notification-content', function() {
          $notification.removeClass('unread');
          var unreadCount = $panel.find('.drawer-pf-notification.unread').length;
          $(panel.parentElement).find('.panel-counter').text(unreadCount + ' New Event' + (unreadCount !== 1 ? 's' : ''));
          if (unreadCount === 0) {
            $panel.find('.drawer-pf-action [data-toggle="mark-all-read"]').remove();
            if ($('.drawer-pf .panel-collapse .unread').length === 0) {
              // TODO: remove badge for unread indicator
            }
          }
        });
      });
    });

    $('#notification-drawer-accordion').initCollapseHeights('.panel-body');

    $(".row-cards-pf > [class*='col'] > .card-pf .card-pf-title").matchHeight();
    $(".row-cards-pf > [class*='col'] > .card-pf > .card-pf-body").matchHeight();
    $(".row-cards-pf > [class*='col'] > .card-pf > .card-pf-footer").matchHeight();
    $(".row-cards-pf > [class*='col'] > .card-pf").matchHeight();

    // Initialize the vertical navigation
    $().setupVerticalNavigation(true);

    //----- Third lv menu
    $('.spc_toggle_trigger').click(function() {
        $('.spc_toggle_menu').removeClass("active_submenu");
        $('.spc_toggle_trigger').removeClass("active");
        $(this).next('.spc_toggle_menu').toggleClass('active_submenu');
        $(this).toggleClass('active');
        return false;
    });

    /*animation load*/
    new WOW().init();

    /*image zoom*/
    $('.img_zoom').hover(function() {
        $(this).addClass('transition');

    }, function() {
        $(this).removeClass('transition');
    });

    //lightbox reBox
    $('.gallery_lightbox').rebox({ selector: 'a' });

    $("#page_top").hide();
	$(function toTop() {
		$(window).scroll(function () {
			if ($(this).scrollTop() > 100) {
				$('#page_top').fadeIn();
			} else {
				$('#page_top').fadeOut();
			}
		});

		$('#page_top').click(function () {
			$('body,html').animate({
				scrollTop: 0
			}, 500);
			return false;
		});
	});

    //Augmenter/diminuer la taille du texte                          accueil
    var fontsize = 100;

    $("#TextTransform #BigText").click(function(){
        fontsize = fontsize+15;
        $('p').css("font-size", fontsize+"%", "!important");
        $('a').css("font-size", fontsize+"%", "!important");
        $('h1').css("font-size", fontsize+"%", "!important");
        $('h2').css("font-size", fontsize+"%", "!important");
        $('h3').css("font-size", fontsize+"%", "!important");
        $('h4').css("font-size", fontsize+"%", "!important");
        $('h5').css("font-size", fontsize+"%", "!important");
        $('h6').css("font-size", fontsize+"%", "!important");
    });

    $("#TextTransform #SmallText").click(function(){
        fontsize = fontsize-15;
        $('p').css("font-size", fontsize+"%", "!important");
        $('a').css("font-size", fontsize+"%", "!important");
        $('h1').css("font-size", fontsize+"%", "!important");
        $('h2').css("font-size", fontsize+"%", "!important");
        $('h3').css("font-size", fontsize+"%", "!important");
        $('h4').css("font-size", fontsize+"%", "!important");
        $('h5').css("font-size", fontsize+"%", "!important");
        $('h6').css("font-size", fontsize+"%", "!important");
    });



    //Sticky Nav
    // When the user scrolls the page, execute stickyNav
    window.onscroll = function() {stickyNav()};

    // Get the navbar
    var navbar = document.getElementById("main_menu_wrapper");
    var logo = document.getElementById("wrapper_logo_site");
   // var change_lang = document.getElementById("changeLang_sticky_nav");
    // Get the offset position of the navbar
    var sticky = navbar.offsetTop;

    // Add the sticky class to the navbar when you reach its scroll position.
    // Remove "sticky" when you leave the scroll position
    function stickyNav() {
        if (window.pageYOffset >= sticky) {
            navbar.classList.add("sticky");
            logo.classList.add("sticky_nav_logo");

            if (logo.style.display === "none"){
                logo.style.display = "table-cell";
            }

            /*if (change_lang.style.display === "none"){
                change_lang.style.display = "table-cell";
            } */
        } else {
            navbar.classList.remove("sticky");
            logo.classList.remove("sticky_nav_logo");

            if (logo.style.display === "table-cell"){
                logo.style.display = "none";
            }

           /* if (change_lang.style.display === "table-cell"){
                change_lang.style.display = "none";
            } */
        }
    }

});



/*menuprincipal over*/
function changeBgImage (image, id) {
	var element = document.getElementById(id);
	element.style.backgroundImage = "url(/client_file/themes/default/interface/site/"+image+")";
}

/*bootstrap_lightbox*/
$(document).on('click', '[data-toggle="lightbox"]', function(event) {
    event.preventDefault();
    $(this).ekkoLightbox();
});
