// interne
$(document).ready(function () {
	
	//manage print links
	$('.printTopTools .print a').click(function (e) {
		window.print();
		e.preventDefault();
	});
	
	// manage mouse over "valider" button
	$('.form_1 .spip_bouton input, .form_2 .spip_bouton input').hover(function () {
		//enter
		var elmt = $(this);
		elmt.attr('src', elmt.attr('src').replace('-off.gif', '-on.gif'));
	}, function () {
		//leave
		var elmt = $(this);
		elmt.attr('src', elmt.attr('src').replace('-on.gif', '-off.gif'));
	});
	
	// Manage "Questions que tu te poses" mouse actions
	$('.fullText #main dl dt').click(function () {
		var elmt = $(this);
		var definitionText = elmt.next();
		var wrapper = elmt.parent();
		
		var duration = 250;
		var durationClose = 200;
		if (!wrapper.hasClass('move')){
			wrapper.addClass('move');
			
			var oldElmt = $('.fullText #main dl dt.show');
			oldElmt.removeClass('show').next().slideUp(durationClose, function () {
				$(this).removeClass('show');
			});
			
			if(!definitionText.hasClass('show')) {
				elmt.addClass('show');
				definitionText.slideDown(duration, function () {
					definitionText.addClass('show').removeAttr('style');
					wrapper.removeClass('move');
				});
			} else {
				elmt.removeClass('show');
				definitionText.slideUp(duration, function () {
					definitionText.removeClass('show').removeAttr('style');
					wrapper.removeClass('move');
				});
			}
		}
		return false;
	});
	
	// Manage Carousel
	var totalWidth = 0;
	$('.carousel > .wrapper > ul > li').each(function () {
		var elmt = $(this);
		totalWidth = totalWidth + parseInt(elmt.width());
		totalWidth = totalWidth + parseInt(elmt.css('margin-left').replace('px', '')) + parseInt(elmt.css('padding-left').replace('px', ''));
	});
	$('.carousel > .wrapper > ul').css('width', totalWidth+'px');
	
	$('.js .carousel .rightArrow, .js .carousel .leftArrow').click(function () {
		var elmt = $(this);
		
		var direction = "left";
		var sign = '-';
		var distance = 579;
		if(elmt.hasClass('rightArrow')) {
			direction = "right";
			sign = '+';
		}
		
		if(direction == 'right') {
			
		} else {
			
		}
		$('#main .carousel > .wrapper').scrollTo( sign+'='+distance+'px', 500 );
		
		return false;
	});
	
	//$('.carousel li:not(.firstItemSelected)').fadeTo(0, .4);
	$('.carousel li').hover(function () {
		// enter
		var elmt = $(this);
		enterCarouselItem(elmt);
		
	}, function () {
		// leave
	});
	$('.carousel li').hover(function () {
		//enter
	}, function () {
		//leave
		leaveCarouselItem();
		
	});
	
});
// Manage mouse over carousel's item
var enterCarouselItem = function (obj) {
	var elmt = $(obj);
	
	var bottomArrow = $('.carousel li div.select:first');
	$('.carousel li div.select').remove();
	
	//var visible = 1;
	//var faded = .4;
	$('.carousel li').removeClass('select')/*.stop({'clearQueue':true,'gotoEnd':true}).fadeTo(0, faded)*/;
	elmt.addClass('select')/*.stop({'clearQueue':true,'gotoEnd':true}).fadeTo(0, visible)*/;
	elmt.append(bottomArrow);
	
	/*var titleItem = $('p.title img', elmt);
	if(isIE) {
		
		if(titleItem.css('filter')) {
			var srcTitleItem = titleItem.css('filter');
			srcTitleItem = srcTitleItem.replace('off', 'on');
			$('.carousel li p.title img').each(function () {
				$(this).css({'filter': $(this).css('filter').replace('on', 'off')});
			});
			titleItem.css({'filter': srcTitleItem});
		}
		
	} else {
		
		if(titleItem.attr('src')) {
			var srcTitleItem = titleItem.attr('src');
			srcTitleItem = srcTitleItem.replace('off', 'on');
			$('.carousel li p.title img').each(function () {
				$(this).attr('src', $(this).attr('src').replace('on', 'off'));
			});
			titleItem.attr('src', srcTitleItem);
		}
		
	}*/
};
var leaveCarouselItem = function () {
	/*var visible = 1;
	var faded = .4;*/
	$('.carousel li').removeClass('select')/*.stop({'clearQueue':true,'gotoEnd':true}).fadeTo(0, faded)*/;
	$('.carousel li.firstItemSelected').addClass('select')/*.stop({'clearQueue':true,'gotoEnd':true}).fadeTo(0, visible)*/;
	
	var bottomArrow = $('.carousel li div.select:first');
	$('.carousel li div.select').remove();
	$('.carousel li.firstItemSelected').append(bottomArrow);
	
	/*var titleItem = $('.carousel .firstItemSelected p.title img');
	if(isIE) {
		var srcTitleItem = titleItem.css('filter');
		srcTitleItem = srcTitleItem.replace('off', 'on');
		$('.carousel li p.title img').each(function () {
			$(this).css({'filter' : $(this).css('filter').replace('on', 'off')});
		});
		titleItem.css({'filter': srcTitleItem});
	} else {
		var srcTitleItem = titleItem.attr('src');
		srcTitleItem = srcTitleItem.replace('off', 'on');
		$('.carousel li p.title img').each(function () {
			$(this).attr('src', $(this).attr('src').replace('on', 'off'));
		});
		titleItem.attr('src', srcTitleItem);
	}*/
};