$(function() {
	// On cache les sous menu si le tag current n'est pas dedans
	var c = $('#menu div.categories');
	$('>ul>li ul',c).hide();
	
	if ($('li.category-current',c).length > 0) {
		// On cherche un eventuel category-current dans la liste
		$('li.category-current>ul:hidden',c).show();
		$('ul:hidden:has(li.category-current)',c).show();
		$('li:has(li.category-current)').children('a').addClass('active');
		$('li.category-current>a').addClass('active');
	} else {
		// Sinon, on va chercher par rapport a l'URL
		$('#menu li>a').each(function() {
			if (this.href == document.location.href) {
				$(this).addClass('active');
				return false;
			}
		});
	}
	
	// On cache les menu de niveau 3 ou plus
	//$('>ul>li>ul>li>ul>li>ul>li:visible',c).hide();
	
	// Formulaire Flash Info
	$('#flash-form input[name=email]').focus(function() {
		if ($(this).val().toLowerCase() == 'abonnez vous') {
			$(this).val('');
		}
	}).blur(function() {
		if ($.trim($(this).val()) == '') {
			$(this).val('ABONNEZ VOUS');
		}
	});
});

// Affichage des images dans les articles
$(function() {
	if ($('body.dc-post').length == 0) {
		return;
	}
	
	var imgs = $('#content').find(
		'a[href$=.jpg]:has(>img),a[href$=.jpeg]:has(>img),'+
		'a[href$=.png]:has(>img),a[href$=.gif]:has(>img),'+
		'a[href$=.JPG]:has(>img),a[href$=.JPEG]:has(>img),'+
		'a[href$=.PNG]:has(>img),a[href$=.GIF]:has(>img)'
	);
	
	if (imgs.length == 0) {
		return;
	}
	
	$('#content').addClass('with-images');
	
	var C = $('<div class="images"></div>');
	var view = $(document.createElement('p')).addClass('images-view');
	C.append(view);
	$('#content #article-content').before(C);
	view.append(imgs);
	$('a:gt(0)',view).hide();
	
	if (imgs.length > 1) {
		var nav = $(document.createElement('p')).addClass('images-nav');
		nav.append('vues : ');
		C.append(nav)
		imgs.each(function(i) {
			var link = $(document.createElement('a')).text(i+1);
			link.attr('href','#');
			nav.append(link);
			link.click(function() {
				var index = $(this).text() - 1;
				
				$('a',view).hide();
				$('a:eq('+index+')',view).show();
				
				$('a',nav).removeClass('current-img');
				$('a:eq('+index+')',nav).addClass('current-img');
				
				return false;
			});
			if (i == 0) {
				link.addClass('current-img');
			}
			if (i+1 < imgs.length) {
				nav.append(' | ');
			}
		});
	}
	
	$('a',view).modalImages(modal_settings);
});
