$(document).ready(function() {
	$("#box1 .boxtitre").click(function() {
		switchBox(1);
	});
	
	$("#box2 .boxtitre").click(function() {
		switchBox(2);
	});
	
	$("#box3 .boxtitre").click(function() {
		switchBox(3);
	});
	
	$("#box4 .boxtitre").click(function() {
		switchBox(4);
	});
	
	$("#box5 .boxtitre").click(function() {
		switchBox(5);
	});
	
	$("#box10 .boxtitre").click(function() {
		switchBox(10);
	});
	
	$("#box11 .boxtitre").click(function() {
		switchBox(11);
	});
	
	initRollOverPuce();
	iniActifClick();
});

function switchBox(a) {
	
	if (a==1) {
		
		if ($("#box1 .boxdata").css('display') == "block") {
			$("#box1 .boxdata").hide();
		} else if ($("#box2 .boxdata").css('display') == "block") {
			$("#box2 .boxdata").hide();
			$("#box1 .boxdata").show();
		} else {
			$("#box1 .boxdata").show();
		}	
		
	}
	
	if (a==2) {
		
		if ($("#box2 .boxdata").css('display') == "block") {
			$("#box2 .boxdata").hide();
		} else if ($("#box1 .boxdata").css('display') == "block") {
			$("#box1 .boxdata").hide();
			$("#box2 .boxdata").show();
		} else {
			$("#box2 .boxdata").show();
		}	
	}
	
	if (a==3) {
		if ($("#box3 .boxdata").css('display') == "block") {
			//$("#box3 .boxdata").hide();
		} else if ($("#box4 .boxdata").css('display') == "block") {
			$("#box4 .boxdata").hide();
			$("#box5 .boxdata").hide();
			$("#box3 .boxdata").show();
		} else if ($("#box5 .boxdata").css('display') == "block") {
			$("#box4 .boxdata").hide();
			$("#box5 .boxdata").hide();
			$("#box3 .boxdata").show();
		} else {
			$("#box3 .boxdata").show();
		}	
	}
	
	if (a==4) {
		if ($("#box4 .boxdata").css('display') == "block") {
			//$("#box4 .boxdata").hide();
		} else if ($("#box3 .boxdata").css('display') == "block") {
			$("#box3 .boxdata").hide();
			$("#box5 .boxdata").hide();
			$("#box4 .boxdata").show();
		} else if ($("#box5 .boxdata").css('display') == "block") {
			$("#box3 .boxdata").hide();
			$("#box5 .boxdata").hide();
			$("#box4 .boxdata").show();
		} else {
			$("#box4 .boxdata").show();
		}	
	}
	
	if (a==5) {
		if ($("#box5 .boxdata").css('display') == "block") {
			//$("#box5 .boxdata").hide();
		} else if ($("#box3 .boxdata").css('display') == "block") {
			$("#box3 .boxdata").hide();
			$("#box4 .boxdata").hide();
			$("#box5 .boxdata").show();
		} else if ($("#box4 .boxdata").css('display') == "block") {
			$("#box3 .boxdata").hide();
			$("#box4 .boxdata").hide();
			$("#box5 .boxdata").show();
		} else {
			$("#box5 .boxdata").show();
		}	
	}
	
	if (a==10) {
		if ($("#box10 .boxdata").css('display') == "block") {
			$("#box10 .boxdata").hide();
		} else if ($("#box11 .boxdata").css('display') == "block") {
			$("#box11 .boxdata").hide();
			$("#box10 .boxdata").show();
		} else {
			$("#box10 .boxdata").show();
		}	
	}
	if (a==11) {
		if ($("#box11 .boxdata").css('display') == "block") {
			$("#box11 .boxdata").hide();
		} else if ($("#box10 .boxdata").css('display') == "block") {
			$("#box10 .boxdata").hide();
			$("#box11 .boxdata").show();
		} else {
			$("#box11 .boxdata").show();
		}	
	}
}

function switchSub(a) {
	
	if (a == "subcons") {
		if ($("#subrea").css('display') == "block") {
			$("#subrea").slideToggle(800);				
		}
		$("#"+a).slideToggle(800);
	} else if (a == "subrea") {	
		if ($("#subcons").css('display') == "block") {
			$("#subcons").slideToggle(800);				
		}
		$("#"+a).slideToggle(800);
	} else {
		$("#subcons").slideUp(800);
		$("#subrea").slideUp(800);		
	}
	
}


function initRollOverPuce() {

	$(".subnav a").mouseover(function() {	
		if (!$(this).hasClass("actif")) {
			var tmp = $(this).parent().parent().children('td').children('img');
			$(tmp).attr('src','images/puce_n.gif')
		}
	}).mouseout(function() {
		if (!$(this).hasClass("actif")) {
			var tmp = $(this).parent().parent().children('td').children('img');
			$(tmp).attr('src','images/puce_m.gif')
		}
	});

}

function iniActifClick() {
	
	$("#nav a").click(function() {
	
		if ($("#nav a.actif").length) {
			
			var tmp = $("#nav a.actif").parent().parent().children('td').children('img');
			if ($(tmp).length) {
				$(tmp).attr('src','images/puce_m.gif')
			}
			
			$("#nav a.actif").removeClass("actif");
		}
	
		$(this).addClass("actif");
							   
	});

}
