$(document).ready(function() {

	/** minimum Menu compatibility for IE 7 - very ugly but IE 7 sucks */
	if ($.browser.msie && parseInt($.browser.version, 10) === 7) {
		$("li.menu").css("margin", "0");
		$("li.menu").css("padding", "0");
		$("li.sub_menu").css("position", "relative");
	}

	$(".quickbox").hover(function() {
		$(".quickbox").children("ul").slideDown();
		$('#qbbg h1 i').removeClass('icon-angle-down').addClass('icon-angle-up');
	}, function() {
		$(".quickbox").children("ul").slideUp();
		$('#qbbg h1 i').removeClass('icon-angle-up').addClass('icon-angle-down');
	});

	if ($(window).width() < 1200) { $("#l21_logo").hide(); };
	
	$( window ).resize(function() {
		if ($(window).width() < 1200) {
			$("#l21_logo").hide();
		} else {
			$("#l21_logo").show();
		}
	});

	$("a.out").attr("target", "_blank");
	$("div#aide").css('display', 'none');

	$("a.aide-ancre").click(function() {
		$("div#aide").slideToggle("slow");
		return false;
	});
	
	$(".toggle_title a").click(function() {
		
		if($(this).parent().next().css('display')=='none') {
			$(this).addClass("open");
			$(this).parent().next().slideDown();
		} else {
			$(this).removeClass("open");
			$(this).parent().next().slideUp();
		}
		
		return false;
	});
	
	
	$('#menu_home').prepend('<i class="icon-desktop"><\/i><br />');
	$('#menu_com').prepend('<i class="icon-globe"><\/i><br />');
	$('#menu_gestion').prepend('<i class="icon-graduation-cap"><\/i><br />');
	$('#menu_config').prepend('<i class="icon-cog-alt"><\/i><br />');
	$('#menu_public_interface').prepend('<i class="icon-home"><\/i><br />');
	
	$('#menu_news, #chemin_news').prepend('<i class="icon-calendar"><\/i>');
	$('#menu_publication, #chemin_publication, #menu_contents, #chemin_contents').prepend('<i class="icon-book"><\/i>');
	$('#menu_newsletter, #chemin_newsletter').prepend('<i class="icon-paper-plane"><\/i>');
	$('#menu_comment, #chemin_comment').prepend('<i class=" icon-chat-empty"><\/i>');
	$('#menu_library, #chemin_library').prepend('<i class=" icon-folder-open"><\/i>');
	$('#menu_page, #chemin_page').prepend('<i class="icon-doc"><\/i>');
	$('#menu_workshop, #chemin_workshop, #chemin_workshoprep, #workshop-subtitle').prepend('<i class="icon-users"><\/i>');
	$('#menu_project, #chemin_project').prepend('<i class="icon-briefcase"><\/i>');
	$('#menu_sdi, #chemin_sdi, #indicator-subtitle').prepend('<i class="icon-attach"><\/i>');
	$('#menu_dashboard, #chemin_dashboard').prepend('<i class="icon-chart-bar"><\/i>');
	$('#menu_yellowpages, #chemin_yellowpages').prepend('<i class="icon-list-alt"><\/i>');
	$('#menu_user, #chemin_user').prepend('<i class="icon-user"><\/i>');
	$('#menu_level, #chemin_level').prepend('<i class="icon-inbox"><\/i>');
	$('#menu_scale, #chemin_scale').prepend('<i class="icon-bookmark"><\/i>');
	$('#menu_tag, #chemin_tag').prepend('<i class="icon-tag-1"><\/i>');
	$('#menu_system, #chemin_system').prepend('<i class=" icon-wrench"><\/i>');
	$('#menu_plugins, #chemin_plugins').prepend('<i class="icon-puzzle"><\/i>');
	
	$('#qbbg h1').prepend('<i class="icon-angle-down"><\/i> ');
	
	$('#containersearch').hide();
	
	$('#searchDiv').mouseover(function() {
		if($( "#containersearch" ).is( ":visible" )) {
			$('#containersearch').fadeOut();
		} else {		
			$('#containersearch').fadeIn();
		}
	});
	
	// clone buttons on Validation pages 'dl.summary'
	if($('dl.summary + form').length) {		// if element exists

		var formId = $('dl.summary + form').attr('id');
		
		$('<form id="' + formId + '-clone"></form>').insertBefore( "#content > dl.summary:eq(0)" );
		
		$('dl.summary + form').find('input').each(function() {
			$el = $(this).clone(false, false).prop({ id: $(this).attr('id') + '-clone'});
			$el.appendTo('#' + formId + '-clone');
	    });
		
		$('#' + formId + '-clone').submit(function(evt) {
		    evt.preventDefault();
		    
		    // when submit form with jQuery the submit button is not passed
		    // so we recreate it on the fly
		    $('<input>').attr({ type: 'hidden', id: $('#' + formId + ' :submit').attr('id'), name: $('#' + formId + ' :submit').attr('name') }).appendTo('#' + formId);
		    $('#' + formId).submit();
		    return false;
		});
	}
	
});

function number_f(nb) {
	nb = nb.toString().replace('.', ',');
	nb = nb.replace(/\B(?=(\d{3})+(?!\d))/g, " ");
	return nb;
}

function getRandomInt(min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
}