$(document).ready(function(){	
	
	/*$('div#navigation').corner({
		style : 'br tl 15px'
	});*/
	
	/*$('.imgBorder').corner({
		style : 'br tl 15px'
	});*/
	
	//$.fn.corner.defaults.useNative = false;
	//$('.picimg').corner("round 10px").parent().css('padding', '2px').corner("round 10px");
	//$('.imgWrap').corner("round 10px").parent().css('padding', '2px').corner("round 10px");
	
	//Carrousel page d'accueil
	/*jQuery('#mycarousel').jcarousel({
        auto: 4,
		scroll: 1,
		wrap: 'both',
		animation: 1200,
		easing : 'easeInOutCubic'
    });*/
    
    // Bind carousel
    manageCarousel.init('#carousel');
    manageCarousel.play('#carousel');
    $('#carousel .leftArrow').click(function () {
    	manageCarousel.pause('#carousel');
    	manageCarousel.previous('#carousel');
    	return false;
    });
    $('#carousel .rightArrow').click(function () {
    	manageCarousel.pause('#carousel');
    	manageCarousel.next('#carousel');
    	return false;
    });
	
	//Toggle actualites
	$('#contentFull ul li .contenu').hide();
	$('#contentFull ul li .contenu .comments').hide();
	$('#contentFull ul li h3').click(function() {
		$(".desc", $(this).parent()).toggle();
		content = $(".contenu", $(this).parent()).toggle();
		$("a.commenterActu", content).click(function() {
			idActu = $(this).attr("id");
			$("div#" + idActu).toggle();
		});
	});

	/*Menu deroulant
	$('#navigation ul li ul').each(function(){
		if ($(this).attr("class") != "sActif") 
			$(this).hide();
	});
	$('#navigation ul li').click(function() {
		if ($("ul", $(this)).attr("class") != "sActif") {
			$('#navigation ul li ul').hide().removeClass("sActif");
			$('#navigation ul li').removeClass("actif");
			$("ul", $(this)).show().addClass("sActif");
			$($(this)).addClass("actif");
		}
		else {
			$('#navigation ul li ul').slideUp(200).removeClass("sActif");
			$($(this)).removeClass("actif");
		}
	});
	*/
	
	//Toggle temoignages / references / actu
	$('.contentTemoignage div.contenu, .contentActu div.contenu, .contentReference div.contenu').hide();
	var titleTemp = '';
	$('.contentTemoignage .lireSuite, .contentActu .lireSuite, .contentReference .lireSuite').click(function() {
		var elmt = $(this);
		if(elmt.text().toLowerCase().indexOf('lire') > -1) {
			titleTemp = elmt.text();
		}
		
		if(!elmt.hasClass('showItem')) {
			elmt.addClass('showItem');
			elmt.html("réduire");
			
			$(".contenu", elmt.parent()).show();
			$(".desc", elmt.parent()).hide();
			
		} else {
			elmt.removeClass('showItem');
			elmt.html(titleTemp);
			
			$(".contenu", elmt.parent()).hide();
			$(".desc", elmt.parent()).show();
			// scroll
			$(document).scrollTop(0);
		}

		// update fullscreen background
		manageFullscreenBg.update();
		updateTools();
		
		return false;
	});
	//$('.reference .referenceBloc:first .lireSuite').click();
	
	// fullscreen bg
	manageFullscreenBg.init();
	
	// vertical center align
	vCenter.init();
	
	// hover homepage link
	$('#header h1 a').hover(function() {
		$(this).addClass('hover');
	}, function () {
		$(this).removeClass('hover');
	});
	
	updateTools();
	
	//manage print
	
	$('.print').click(function () {
		var obj = $('#wrapper');
		var topOffset = obj.css('top');
		obj.css('top', '0');
		window.print();
		obj.css('top', topOffset);
		return false;
	});
	
	// empty P cleaner
	$('p').each(function () {
		var elmt = $(this);
		var texte = String(elmt.text());
		texte = texte.replace('&nbsp;', '');
		texte = texte.replace(' ', '');
		var html  = String(elmt.html());
		html = html.replace('&nbsp;', '').replace(' ', '');
		if((texte.length == 0) && (html.length == 0)) {
			elmt.css({'display':'none'}).addClass('emptyParagraphe');
		}
	});
	
	//Options fancybox : cf. plugin spip
	$("a.newsletter_fancy").fancybox({
		'hideOnContentClick': false
	});
	
});
function updateTools () {
	$('#main #right #contentcolgauche a.haut, #main #right #contentcolgauche a.print').css('bottom', '1px').css('bottom', '0');
}
