
/* Cufon.replace('#nav li a', {
	fontFamily: 'MyriadPro-SemiboldCond',
	hover: true
}); */




var isIE6 = $.browser.msie && parseFloat($.browser.version) < 7;

$(document).ready(function(){

	Cufon.replace('#nav:has(ul) > li a, h1, h2', {
		hover: true
	});









	/*.............................................................*/
	/*'''''''''''''''''''' Début des JS "logo" ''''''''''''''''''''*/

	jQuery.event.add(window, "load", resizeFrame);
	jQuery.event.add(window, "resize", resizeFrame);

	function resizeFrame(){
		var windowWidth = $(window).width();
		var logoWidth = (windowWidth > 940) ? Math.round((windowWidth - 940) / 2 + 300) : 300;
		$("#logo").css({ width: logoWidth + "px" });
	}









	/*............................................................*/
	/*'''''''''''''''''''' Début des JS "nav" ''''''''''''''''''''*/

	$("a#show-panel").click(function(){
		if (isIE6) {
			var windowHeight = $(window).height();
			$("#lightbox").css({ height: windowHeight });
		}
		$("#lightbox, #lightbox-panel").fadeIn(300);
	});
	$("#close-panel").click(function(){
		$("#lightbox, #lightbox-panel").fadeOut(300);
	});
	$("#lightbox").click(function(){
		$("#lightbox, #lightbox-panel").fadeOut(300);
	});









	/*............................................................*/
	/*'''''''''''''''''''' Début des JS "nav" ''''''''''''''''''''*/

	if (!isIE6) {
		$("#nav > li").not(".langue").each(function() {
			// var current = "nav current-" + ($(this).attr("class"));
			// var parentClass = $(".nav").attr("class");
			// if (parentClass != current) {
				$(this).children("a").css({
					background: "none",
					backgroundImage: 'url(images/idx_on.gif)',
	
					paddingTop: '2px',
					paddingBottom: '14px'
				});
				$(this).children("div").css({ opacity: 0 });
			// }
		});




		$("#nav > li").not(".langue").hover(function() {
			$(this).children("a")
				.stop().animate({
					backgroundPosition: '0 -80px',
		
					paddingTop: '7px',
					paddingBottom: '9px'
				}, 300)
				.css({ color: "#FFF" });
				Cufon.refresh();
	
			$(this).children("div:not(.subNavBack)")
				.css({ visibility: "visible" })
				.stop().animate({ opacity: 1 }, 300);
	
			$(this).children(".subNavBack")
				.css({ visibility: "visible" })
				.stop().animate({ opacity: 0.75 }, 300);




		}, function() {
			$(this).children("div").stop().animate({ opacity: 0 }, 300, function() {
				$(this).css({ visibility: "hidden" });
			});
	
			$(this).children("a:first-child")
				.stop().animate({
					backgroundPosition: '0 0',
		
					paddingTop: '2px',
					paddingBottom: '14px'
				}, 300)
				.css({ color: "#666" });
				Cufon.refresh();
		});
	}









	/*..............................................................*/
	/*'''''''''''''''''''' Début des JS "infos" ''''''''''''''''''''*/

	if ($("#infos #button").css("display") != "none") {

		$("#bottom").css({
			position: "fixed",
			left: 0,
			bottom: 0
		});
		$("#infos").css({
			position: "fixed",
			left: 0,
			bottom: "-100px"
		});
		$("#infos #content #button").css({
			visibility: "visible"
		});
		$("#infos #content #button #contact").css({
			visibility: "visible",
			opacity: 0
		});




		var contact = false;

		$("#infos #content #button").click(function() {
			if (contact) {
				$("#infos").stop().animate({ bottom: "-100px" }, function() {
					$("#content #button #contact").stop().animate({ opacity: 0 }, 100)
					contact = false;
				});
			}
			else {
				contact = true;
				$("#infos").stop().animate({
					bottom: "24px"
				});
			}
		});




		$("#infos #content #button").hover(function() {
			if (!contact) {
				$(this).children("#contact").stop().animate({ opacity: 1 }, 100)
			}
		}, function() {
			if (!contact) {
				$(this).children("#contact").stop().animate({ opacity: 0 }, 100)
			}
		});
	}









	/*..................................................................*/
	/*'''''''''''''''''''' Début des JS "slideShow" ''''''''''''''''''''*/

	$("#prev").click(function() {
		slidePause("prev");
	});
	$("#next").click(function() {
		slidePause("next");
	});




	$("#show #play").click(function() {
		slidePlay("play");
	});


	$("#show #pause").click(function() {
		slidePause("pause");
	});




	$("#show").bind("mouseenter mouseleave", toggleControl);

	slideAuto();


});









var timer;
var target = "pause";
var auto = true;




function slidePause(trigger) {
	if (auto) {
		clearInterval(timer);
		auto = false;

		$("#show #pause").fadeOut();
		target = "play";
		toggleControl();
		if (trigger == "prev" || trigger == "next") {
			$("#show #play").delay(400).fadeOut();
		}
	}
	if (trigger != "pause") slideSwitch(trigger);
}

function slidePlay(trigger) {
	$("#show #play").fadeOut();
	target = "pause";
	toggleControl();

	if (!auto) {
		auto = true;
	}
	slideSwitch(trigger);
}

function slideAuto() {
	timer = setInterval( "slideSwitch()", 4000 );
}




function slideSwitch(trigger) {
	var $active = $('#show img.active');

	if (trigger == "prev") {
		var $next = $active.prev('img').length ? $active.prev('img') : $('#show img:last');
	}
	else {
		var $next = $active.next('img').length ? $active.next('img') : $('#show img:first');
	}

	$active.addClass('last-active');

	$next.css({ opacity: 0 })
		.addClass('active')
		.animate({ opacity: 1.0 }, 500, function() {
			$active.removeClass('active last-active');
		});
	if (trigger == "play") slideAuto();
}




function toggleControl() {
	toggleTarget = "#show #" + target;
	$(toggleTarget).fadeToggle();
}










$(function () {

	/*.............................................................*/
	/*'''''''''''''''''''' Début des JS "side" ''''''''''''''''''''*/

	// if (!msie6 && $("#infos #button").css("display") != "none") {
	if ($("#infos #button").css("display") != "none") {
		//var top = $('#side').offset().top - parseFloat($('#side').css('margin-top').replace(/auto/, 0)) -110;
		var top = $('#side').offset().top - 110;
		$(window).scroll(function (event) {
			var y = $(this).scrollTop();
			if (y >= top) {
				$('#side').addClass('fixed');
			} else {
				$('#side').removeClass('fixed');
			}
		});
	}
});

