function preg_replace (array_pattern, array_pattern_replace, my_string) { var new_string = String (my_string); for (i=0; i<array_pattern.length; i++) { var reg_exp= RegExp(array_pattern[i], "gi"); var val_to_replace = array_pattern_replace[i]; new_string = new_string.replace (reg_exp, val_to_replace); } return new_string; }

function removeAccents (my_string) { var new_string = ""; var pattern_accent = new Array("é", "è", "ê", "ë", "ç", "à", "â", "ä", "î", "ï", "ù", "ô", "ó", "ö"); var pattern_replace_accent = new Array("e", "e", "e", "e", "c", "a", "a", "a", "i", "i", "u", "o", "o", "o"); if (my_string && my_string!= "") { new_string = preg_replace (pattern_accent, pattern_replace_accent, my_string); } new_string = new_string.replace(/\s+/g, ''); return new_string; }

$('#container').isotope({
  itemSelector : '.definition',
  layoutMode : 'fitRows'
});

$(function()
{
	if($('#champsRecherche').val().length > 0)
	{
		var recherche = $('#champsRecherche').val().toLowerCase();
		recherche = removeAccents(recherche);
		var resultat = $("[data-mot*='" + recherche + "']").add('.row-end');
		var selector = resultat;
		
		$('#container').isotope({ 
		filter: selector 
		});
	}
	
	$(".copyButton").click(function(evt) {
            var elt = $(evt.target);
            if(elt.siblings(".zclip").length === 0) {
                elt.zclip({
	       	    path: "ZeroClipboard.swf",
	    	    copy: function(){return elt.prev().val();},
		    afterCopy: function(){elt.text('Copié !');},
                });
            }
	});
});

$('.defineTile').click(function(event){
	event.stopPropagation();
	$(this).addClass('active');
	$(this).siblings('li').removeClass('active');
	$(this).parent().nextAll('.commentSection').hide();
});

$('.commentTile').click(function(event){
	event.stopPropagation()
	$(this).addClass('active');
	$(this).siblings('li').removeClass('active');
	$(this).parent().nextAll('.commentSection').show();
	
	//xmlRequest(event);
});

$('#menuExtraContent a').click(function(event){
	event.stopPropagation();
	$(this).addClass('active');
	$(this).siblings('a').removeClass('active');
});

$('#filters input').click(function(){
	$(this).siblings().attr('checked', false);
	$(this).attr('checked', true);
	
	if($('#champsRecherche').val().length == 0)
	{
		var selector = $('div input[checked]').attr('data-filter');
	}
	else
	{
		var recherche = $('#champsRecherche').val().toLowerCase();
		recherche = removeAccents(recherche);
		var resultat = $("[data-mot*='" + recherche + "']");
		var selector = $($('div input[checked]').attr('data-filter')).filter(resultat).add('.row-end');
	}
	
	$('#container').isotope({ 
	filter: selector 
	});
});

$('#champsRecherche').keyup(function(event){
	var recherche = $('#champsRecherche').val().toLowerCase();
	recherche = removeAccents(recherche);
	var resultat = $("[data-mot*='" + recherche + "']");
	var selector = $($('div input[checked]').attr('data-filter')).filter(resultat).add('.row-end');

	
	if($('#champsRecherche').val().length == 0)
	{
		selector = $('div input[checked]').attr('data-filter');
	}
	$('#container').isotope({ 
	filter: selector 
	});

});

$('.element').click(function(){
	if(!$(this).hasClass("folder")){
		$(this).toggleClass("large");
		if(!$(this).prevAll('.folder').first().hasClass('height2')){
			$(this).prevAll('.folder').first().toggleClass('height2');
		}
		else if($(this).prevAll('.folder').first().hasClass('height2') && $(this).siblings('.large').length == 0 && !$(this).hasClass('large')){
			$(this).prevAll('.folder').first().toggleClass('height2');
		}
		$('#container').isotope(
			'reLayout');
	}
});
