/*
 * CRAIE O.S.B.L. — Left side
 * Custom animations for our corporative website
 * Coded by Laurent LaSalle using jQuery 1.2.3
 *
 * May 27th 2008
 *
 */

var cible = "gauche", anchor, prevcontenu = "melasse", prevcible = "gauche", largeur, slargeur, newest = true, safari = navigator.userAgent.toLowerCase().indexOf('safari'), explorer = /*@cc_on function(){ switch(@_jscript_version){ case 1.0:return 3; case 3.0:return 4; case 5.0:return 5; case 5.1:return 5; case 5.5:return 5.5; case 5.6:return 6; case 5.7:return 7; }}()||@*/ 0;

if ((explorer <= 6) && (explorer > 1)) { var flexwidth = "500px"; } else { flexwidth = "auto";}

function analyzecontent(contenu) { // Determine where to go and how to get there based on context
	largeur = ($("#top").width()) + "px";
	slargeur = ($("#top").width()) - 250 + "px";
	switch(contenu) {
	case "accueil":
		cible = "droite";
		anchor = "droite";
		break;
	case "contact":
		cible = "droite";
		anchor = "contact";
		break;
	default:
		cible = "gauche";
		anchor = contenu;
	}
	switch(prevcontenu) {
	case contenu:
		movingtodestination();
		break;
	default:
		loaddestination(contenu);
		switchingside(contenu);
		break;
	}
	prevcontenu = contenu;
	prevcible = cible;
	return false;
}

function loaddestination(contenu) { // Load the desired content in background
	switch(cible) {
	case "droite":
		movingtodestination();
		break;
	case prevcible:
		if (explorer > 0) {
			$("#container01").load(contenu+".php #"+contenu, function() {
				movingtodestination();
			});
		} else {
			$("#gauche").animate({ opacity: "0" }, 300, function() {
				$("#container01").load(contenu+".php #"+contenu, function() {
					$("#gauche").animate({ opacity: "1" }, 300, function() {
						movingtodestination();
					});
				});
			});
		}
		break;
	case "gauche":
		$("#container01").load(contenu+".php #"+contenu);
		break;
	}
}

function switchingside(contenu) { // Switch sides when necessary
	var bgclr = "#666", mclr = "#000";
	if (contenu == "bulletin") {
		bgclr = "#003866";
		mclr = "#fff";
	}
	$("#gauche>div").css("width", slargeur);
	$("#menu>ul>li").animate({ fontSize: "18px" }, 100);
	switch(cible) {
	case prevcible:
		$("#menu a").animate({ color: mclr }, 600);
		$("#top").animate({ backgroundColor: bgclr }, 600);
		$("#gauche>div").css("width", flexwidth);
		return false;
		break;
	case "gauche":
		$("#menu a").animate({ color: mclr }, 600);
		$("#top").animate({ backgroundColor: bgclr }, 600);
		if ((safari > 0) || (explorer > 0)) {
			$("#gauche").css("marginRight", "0");
			largeur = slargeur;
		} else {
			$("#gauche>div").css("float", "right");
		}
		$("#gauche").animate({ width: largeur }, 600, function() { 
			$("#droite").css("width", "0");
			$("#gauche").css("width", "50%");
			if ((safari > 0) || (explorer > 0)) { 
				$("#gauche").css("marginRight", "-250px");
			}
			$("#gauche>div").css("width", flexwidth);
		});
		break;
	case "droite":
		if ((explorer <= 6) && (explorer > 1)) {
			largeur = slargeur;
		}
		$("#droite").css("width", largeur);
		if ((safari > 0) || (explorer > 0)) {
			$("#gauche>div").css("float", "none");
			$("#gauche").css("marginRight", "0");
			$("#gauche").css("width", slargeur);
		} else {
			$("#gauche>div").css("float", "right");
		}
		$("#menu a").animate({ color: "#808080" }, 600);
		$("#top").animate({ backgroundColor: "#1a1a1a" }, 600);
		$("#gauche").animate({ width: "0" }, 600, function() {
			movingtodestination();
		});
		break;
	}
}

function movingtodestination() { // Scroll to content
	$.scrollTo("#"+anchor, 600);
}

$(document).ready(
	function() {
		$("#menu a").click(function() {
			analyzecontent(this.className);
			return false;
		});
		$("#menu>ul>li").hover(
			function() {$(this).animate({ fontSize: "24px" }, 100);}, 
			function() {$(this).animate({ fontSize: "18px" }, 100);}
		);
		$.localScroll({lazy: true});
	}
);