$(document).ready(function(){
	Cufon.replace("#navbar a span.lk", {fontFamily: 'HelveticaNeue LT 55 Roman', hover: true, textShadow: '#730000 1px 1px'});
	Cufon.replace("h2", {fontFamily: 'HelveticaNeue LT 55 Roman'});
	Cufon.replace("h1, .slideTitle", {fontFamily: 'HelveticaNeue LT 45 Light'});

	$('.navLeft, .navRight').hide();
	
	$('#navbar a').prepend('<span class="navLeft"></span>').append('<span class="navRight"></span>').mouseenter(function() {
		if($(this).parent('li').attr('class').indexOf('current_page_item')==-1 && !ismobile) {
			var curIndex = $(this).parent('li').index();

			if($(this).parents('ul').find('li:eq('+(curIndex*1-1)+')').length == 1)
				var previtem_active = $(this).parents('ul').find('li:eq('+(curIndex*1-1)+')').attr('class').indexOf('current_page_item');
			else var previtem_active = -1;
			if($(this).parents('ul').find('li:eq('+(curIndex*1+1)+')').length == 1)
				var nextitem_active = $(this).parents('ul').find('li:eq('+(curIndex*1+1)+')').attr('class').indexOf('current_page_item');
			else var nextitem_active = -1;
			
			if(previtem_active==-1) {
				$(this).find('.navLeft').stop().fadeTo(350,1, function() { $(this).show(); });
			}

			if(nextitem_active==-1) {
				$(this).find('.navRight').stop().fadeTo(350,1, function() { $(this).show(); });
			}
	
		
		}
	})
	.mouseleave(function(){
		if($(this).parent('li').attr('class').indexOf('current_page_item')==-1 && !ismobile) {
			$(this).find('.navLeft, .navRight').stop().fadeTo(350,0, function() { $(this).hide(); });
		}
	})
	.each(function() {
		$(this).width($(this).find('.lk').width()+56);
	});
	
	// Transitions d'images

    $('#navbar li').each(function(){
  	      $(this).removeClass('highlight')
	        .find('a')
	        .prepend('<span class="hover"/>').each(function () {
					var addWidth = $(this).find('.lk').css('padding-left').substr(0,2)*1 + $(this).find('.lk').css('padding-right').substr(0,2)*1;
					$(this).find('span.hover').width($(this).find('.lk').width()+addWidth);
	                var $span = $('> span.hover', this).css('opacity', 0);
						if($(this).parents('li').attr('class').indexOf('current_page_item')==-1 && !ismobile) {
		                $(this).hover(function () {
		                    // on hover
		                    $span.stop().fadeTo(300, 1);
		                }, function () {
		                    // off hover
		                    $span.stop().fadeTo(300, 0);
		                });
					}
					else {
						if($(this).parents('li').attr('class').indexOf('current_page_item')!=-1) {
							$span.stop().fadeTo(0, 1);
							$(this).find('.navLeft, .navRight').stop().fadeTo(0,1);
						}
					}
	          });
	});
	
	// accueil
	$('#cx li').each(function(){
	      $(this).removeClass('highlight')
	        .find('a')
	        .prepend('<span class="hover"/>').each(function () {
	                var $span = $('> span.hover', this).css('opacity', 0);
						if($(this).parents('li').attr('class').indexOf('current_page_item')==-1 && !ismobile) {
		                $(this).hover(function () {
		                    // on hover
		                    $span.stop().fadeTo(300, 1);
		                }, function () {
		                    // off hover
		                    $span.stop().fadeTo(300, 0);
		                });
					}
					else {
						if($(this).parents('li').attr('class').indexOf('current_page_item')!=-1) {
							$span.stop().fadeTo(0, 1);
						}
					}
	          });
	});
	
	//  Footer (positionnement JS)
	posf($(window).height());
	$(window).resize(function() { posf($(this).height()) });
	
	$(document).pngFix();
	
	//$('#tabs .selected').parent('li').css({backgroundColor:'#000', 'paddingLeft':20});
	
	$('img.size-thumbnail').each(function(){
		$(this).parents('a').attr('class','fb');
	});
	
	$("a.fb").fancybox({
			padding:20,
			scrolling:'no',
			overlayOpacity:0.8,
			titleShow:false,
			overlayColor:'#000'
		});
});

function posf(h) {
	if($('#wrapInner').length>0) {
		var num = 390;	
	}
	else {
		var num = 323;
	}
	if($.browser.msie && parseFloat($.browser.version) <= 7)
	$('#ctn').css({'height':h*1-num+'px'});
	else
	$('#ctn').css({'min-height':h*1-num+'px'});
}
