$(document).ready(function(){
		//validate required checkbox
		if ($(".required_checkbox")[0]){
			$('.required_checkbox_submit').click(function() {
	            checked = $("input.required_checkbox:checkbox:checked").length;

	            if(!checked) {
	                alert("Case à cocher obligatoire.");
	                return false;
	            }
	        });
		}

        /*-------------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]);

            });
        });

		$("#fast_login_form").submit(function(e) {
	        if($("#fast_login_ajax").val()==0)
	        {
	            e.preventDefault(); // avoid to execute the actual submit of the form.
	            var url = "/boutique/ajax_check_login.php"; // the script where you handle the form input.
	            $.ajax({
	                type: "POST",
	                url: url,
	                data: $("#fast_login_form").serialize(), // serializes the form's elements.
	                success: function(data)
	                {
	                    if(data==1)   //if(data.match(/1/g))
	                    {
	                        $("#fast_login_ajax").val("1");
	                        $("#fast_login_form" ).submit();
	                    }else
	                    {
	                        $("#fast_login_email_address").val("");
	                        $("#fast_login_password").val("");
	                        $("#msg_error_login").html("<br>Mot de passe ou identifiant invalide");
	                    }
	                }
	            });
	        }
	    });

		//sidebar account
		$('#sidebarCollapse').on('click', function () {
        	$('#sidebar').toggleClass('active');
        });
		$("#sidebar_fixe").mCustomScrollbar({
        	theme: "minimal"
        });
		if ($(window).width() < 900) {
		   $('#sidebar').addClass('active');
		}

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

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

        $('#accueil').css("font-size", fontsize+"%", "!important");
        $('#accueil p').css("font-size", fontsize+"%", "!important");
        $('#accueil a').css("font-size", fontsize+"%", "!important");
        $('#accueil h1').css("font-size", fontsize+"%", "!important");
        $('#accueil h2').css("font-size", fontsize+"%", "!important");
        $('#accueil h3').css("font-size", fontsize+"%", "!important");
        $('#accueil h4').css("font-size", fontsize+"%", "!important");
        $('#accueil h5').css("font-size", fontsize+"%", "!important");
        $('#accueil h6').css("font-size", fontsize+"%", "!important");
    });

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

        $('#accueil').css("font-size", fontsize+"%", "!important");
        $('#accueil p').css("font-size", fontsize+"%", "!important");
        $('#accueil a').css("font-size", fontsize+"%", "!important");
        $('#accueil h1').css("font-size", fontsize+"%", "!important");
        $('#accueil h2').css("font-size", fontsize+"%", "!important");
        $('#accueil h3').css("font-size", fontsize+"%", "!important");
        $('#accueil h4').css("font-size", fontsize+"%", "!important");
        $('#accueil h5').css("font-size", fontsize+"%", "!important");
        $('#accueil h6').css("font-size", fontsize+"%", "!important");
    });

	//scrolling top
	$(window).scroll(function() {
        if ($(this).scrollTop() >= 150) {
            $('#return-to-top').fadeIn(200);
        } else {
            $('#return-to-top').fadeOut(200);
        }
    });
    $('#return-to-top').click(function() {
        $('body,html').animate({
            scrollTop : 0
        }, 500);
    });

    // Formulaire de contact flottant
    $("#contactUs-tab").click(function() {
        $("#request-contactUs").toggleClass("visible");
    });

    $(".contactUs-close").click(function() {
        $("#request-contactUs").removeClass("visible");
    });

    $("a[rel^='prettyPhoto']").prettyPhoto({
        animationSpeed: 'normal',
        opacity: 0.80,
        deeplinking: false,
        allow_resize: true, /* Resize the photos bigger than viewport. true/false */
        default_width: 500,
        default_height: 344,
        showTitle: true,
        social_tools: ''
   });
    $(".photo_product_slider").owlCarousel({
        autoPlay : 5000,
        stopOnHover : true,
        navigation:false,
        pagination:true,
        paginationSpeed : 1000,
        goToFirstSpeed : 2000,
        singleItem : true,
        autoHeight : true,
        transitionStyle:"fade",
        navigationText: [
           "",
           ""
        ],
    });
        /*------------------PAGINATION----------------*/
    var show_per_page = 10;
    var number_of_items = $('#wrapper_list_cab').children('.list_cab').size();
    var number_of_pages = Math.ceil(number_of_items / show_per_page);

    $('#current_page').val(0);
    $('#show_per_page').val(show_per_page);

    var navigation_html = '<a class="prev" onclick="previous()">Précedent</a>';
    var current_link = 0;
    while (number_of_pages > current_link) {
        navigation_html += '<a class="page" onclick="go_to_page(' + current_link + ')" longdesc="' + current_link + '">' + (current_link + 1) + '</a>';
        current_link++;
    }
    navigation_html += '<a class="next" onclick="next()">Suivant</a>';

    $('.controls_pagination').html(navigation_html);
    $('.controls_pagination .page:first').addClass('active');

    $('#wrapper_list_cab').children().css('display', 'none');
    $('#wrapper_list_cab').children().slice(0, show_per_page).css('display', 'block');




    $('ul.dropdown-menu [data-toggle=dropdown]').on('click', function(event) {
		event.preventDefault();
		event.stopPropagation();
		$(this).parent().siblings().removeClass('open');
		$(this).parent().toggleClass('open');
	});
    $("#mobile_spc_menu_btn").click(function(e){
        $(this).toggleClass("Active");
        $("#menu_spc").slideToggle("fast");
        e.preventDefault();
    });

	/* ================ 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');
		});
	});


	/* ================ Back to top button. ================ */
	var winScroll = $(window).scrollTop();
	if (winScroll > 1) {
		$('#to-top').css({bottom:"10px"});
	} else {
		$('#to-top').css({bottom:"-100px"});
	}
	$(window).on("scroll",function(){
		winScroll = $(window).scrollTop();

		// PARALLAX background Animation.
		var y = parseInt($('.parallax').css('background-position-y'));
		var newY = -(winScroll * 0.05) + 'px';
		$('.parallax').css("background-position-y",newY);


		//  Show Hide back to top button.
		if (winScroll > 1) {
			$('#to-top').css({opacity:1,bottom:"10px"});
		} else {
			$('#to-top').css({opacity:0,bottom:"-100px"});
		}
	});


	$('#to-top').click(function(){
		$('html, body').animate({scrollTop: '0px'}, 800);
		return false;
	});




    	/* ================ Show Hide Search box. ================ */
        /*
        	$('.top-search a').click(function(){
        		if($(this).parent().find('.search-box').is(':visible')){
        			$('.search-box').fadeOut(300);
        			$(this).parent().removeClass('selected');
        			return false;
        		}else{
        			$('.search-box').fadeIn(300);
        			$(this).parent().addClass('selected');
        			return false;
        		}
        	});
        	$(document).mouseup(function(e){
        		if($('.search-box').is(':visible')){
        			var targ = $(".search-box");
        			if (!targ.is(e.target) && targ.has(e.target).length === 0){
        			$('.search-box').fadeOut(300);
        			$('.top-search').removeClass('selected');
        			}
        		}
        	});
        */

    /*$( function() {
        $( ".accordion" ).accordion({
          heightStyle: "content",
          collapsible: true,
          active: false
        });
      } );*/

    	/* ================ Album Photos ================ */
    $(".filter-button").click(function(){
        var value = $(this).attr('data-filter');

        if(value == "all")
        {
            //$('.filter').removeClass('hidden');
            $('.filter').show('1000');
        }
        else
        {
//            $('.filter[filter-item="'+value+'"]').removeClass('hidden');
//            $(".filter").not('.filter[filter-item="'+value+'"]').addClass('hidden');
            $(".filter").not('.'+value).hide('3000');
            $('.filter').filter('.'+value).show('3000');

        }
    });

    if ($(".filter-button").removeClass("active")) {
        $(this).removeClass("active");
    }
    $(this).addClass("active");

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


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

    // Get the navbar
    var navbar = document.getElementById("menu_principal");
    var logo = document.getElementById("logo_sticky_nav");
   // 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 >= 300) {
            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";
            } */
        }
    }

	//video embed full width
	$('.video_full_width').each(function () {
		$(this).removeAttr('style');
		$(this).wrap("<div class='fullwidth_video_container'></div>");
	});


	$('.plus_moins').click(function(){
	    if (!$(this).hasClass('moins')) {
	        $(this).attr('src', '/client_file/themes/default/interface/picto_moins.png');
	        $(this).addClass('moins')
	    } else  {
	        $(this).attr('src', '/client_file/themes/default/interface/picto_plus.png');
	        $(this).removeClass('moins')
	    }
	});

});

function isNumeric(n) {
    return !isNaN(parseFloat(n)) && isFinite(n);
}

    function go_to_page(page_num) {
        var show_per_page = parseInt($('#show_per_page').val(), 0);
        start_from = page_num * show_per_page;
        end_on = start_from + show_per_page;
        $('#wrapper_list_cab').children().css('display', 'none').slice(start_from, end_on).css('display', 'block');
        $('.page[longdesc=' + page_num + ']').addClass('active').siblings('.active').removeClass('active');
        $('#current_page').val(page_num);
    }
    function previous() {
        new_page = parseInt($('#current_page').val(), 0) - 1;
        //if there is an item before the current active link run the function
        if ($('.active').prev('.page').length == true) {
            go_to_page(new_page);
        }
    }
    function next() {
        new_page = parseInt($('#current_page').val(), 0) + 1;
        //if there is an item after the current active link run the function
        if ($('.active').next('.page').length == true) {
            go_to_page(new_page);
        }
    }


/*event cat*/
function changeSrcImage (image, id) {
	var element = document.getElementById(id);
	element.src = "/client_file/themes/default/interface/st_lin/"+image+"";
}
/*event cat*/
function changeBg (color, id) {
	var element = document.getElementById(id);
	element.style.background  = "#"+color+"";
}

/*event cat*/
function detail_cat(cat_id,link_id,aa='',mm='',jj='') {
	$('.secondary_cat_wrapper').empty();
    var data_cat = {"cat_id":cat_id,"aa":aa,"mm":mm,"jj":jj}
    var url = "/gi2-modules/custom/cust_fiq_evenement/ajax_cat.php";
    $.ajax({
        type: "POST",
        url: url,
        data : data_cat,
        success : function(result) {
            jQuery("#detail_cat_"+cat_id).html(result); // result is the HTML text
			jQuery("#detail_cat_"+cat_id).show("slow");
            //jQuery("#detail_cat").show("slow");
        },
    });
    $('.event_primary_cat').removeClass('picto_cat_active');
    $('#'+link_id).toggleClass('picto_cat_active');
}

/*maj list event*/
function maj_event(cat_id,aa,mm,jj) {
    var data_cat = {"cat_id":cat_id,"aa":aa,"mm":mm,"jj":jj}
    var url = "/gi2-modules/custom/cust_fiq_evenement/ajax_cal.php";
    $.ajax({
        type: "POST",
        url: url,
        data : data_cat,
        success : function(result) {
            jQuery("#wrapper_calendar").html(result); // result is the HTML text
            //jQuery("#wrapper_calendar").show("slow");
        },
    });
    var url = "/gi2-modules/custom/cust_fiq_evenement/ajax_event.php";
    $.ajax({
        type: "POST",
        url: url,
        data : data_cat,
        success : function(result) {
            jQuery("#wrapper_list_event").html(result); // result is the HTML text
            //jQuery("#wrapper_calendar").show("slow");
        },
    });
    jQuery(".controls_pagination").html('');

	//texte de la catégorie
	data_cat = {"cat_id":cat_id,"mod":"cat_desc"}
	$.ajax({
        type: "POST",
        url: url,
        data : data_cat,
        success : function(result) {
            jQuery("#cat_desc").html(result); // result is the HTML text
        },
    });

}

function toggle_tuile(tuile_id){
	$('.fix_tuile_height').removeClass('tuile_active');
	$('#tuile_'+tuile_id).addClass('tuile_active');
	$('.tuile_detail').hide("fade");
	$('#tuile_detail_'+tuile_id).show("fade");
}

function input_numeric_only(evt,allow_negatif) {
    var theEvent = evt || window.event;

    // Handle paste
    if (theEvent.type === 'paste') {
            key = event.clipboardData.getData('text/plain');
    } else {
    // Handle key press
            var key = theEvent.keyCode || theEvent.which;
            key = String.fromCharCode(key);
    }
    if(allow_negatif=='1'){
    	var regex = /[0-9]|\.|\-/;
    }else{
    	var regex = /[0-9]|\./;
    }
    if( !regex.test(key) ) {
        theEvent.returnValue = false;
        if(theEvent.preventDefault) theEvent.preventDefault();
    }
}

function changeBgNews(color, id) {
	var element = document.getElementById(id);
	element.style.background  = ""+color+"";
}

/*news cat*/
function detail_cat_news(cat_id,link_id) {
	//$('.secondary_cat_wrapper').empty();
    var data_cat = {"cat_id":cat_id}
    var url = "/gi2-modules/standard/news/ajax_cat.php";
    $.ajax({
        type: "POST",
        url: url,
        data : data_cat,
        success : function(result) {
            jQuery("#detail_cat_"+cat_id).html(result); // result is the HTML text
			jQuery("#detail_cat_"+cat_id).show("slow");
            //jQuery("#detail_cat").show("slow");
        },
    });
    //$('.event_primary_cat').removeClass('picto_cat_active');
    //$('#'+link_id).toggleClass('picto_cat_active');
}

/*maj list news*/
function maj_news(cat_id) {
    var data_cat = {"cat_id":cat_id}
    var url = "/gi2-modules/standard/news/ajax_news.php";
    $.ajax({
        type: "POST",
        url: url,
        data : data_cat,
        success : function(result) {
            jQuery("#news_wrapper_list").html(result); // result is the HTML text
            //jQuery("#wrapper_calendar").show("slow");
        },
    });
    jQuery(".controls_pagination").html('');

	//texte de la catégorie
	data_cat = {"cat_id":cat_id,"mod":"cat_desc"}
	$.ajax({
        type: "POST",
        url: url,
        data : data_cat,
        success : function(result) {
            jQuery("#cat_desc").html(result); // result is the HTML text
        },
    });
}

//modal img
$(function() {
	$('.image_fullsize').on('click', function() {
		$('.imagepreview').attr('src', $(this).attr('src'));
		var desc=$(this).attr('alt');
		if(!desc){
			desc=$(this).attr('title');
		}
		$('#text_img_fullsize').html(desc);
		$('#imagemodal').modal('show');
	});
});
