function addContent(keyword, pane) {


	if (pane>=0) pane = pane; else pane=getNb()-1;
	//alert(pane);
	removeAfter(pane);

	setLeft(false);

	url = "page.php?k="+keyword+"&p="+getNb();
	//alert(url);
	
	$.get(url, function(data) {
		//$('.result').html(data);
		$(data).appendTo("#content");
		//$(".a_content").fadeTo('normal', 1);
		
		i=1; 
		$(".a_content .pad").each(function() {
			//paddIt(this, i);
			setTimeout("paddIt("+i+")", i*200);
			//alert(i);
			i=i+1;
		});
			//setTimeout("scroll()", 2000);
			scroll();
		
		
		//$(".scroll").fadeTo('normal', 0.15);
		//alert('Load was performed.');
		
		//removeContent(1);
		
		contentPos = getNb();
		activateLinks();
		
		$.get("fil.php", function(data) {
			$(data).appendTo("#breadcrumb");
		});
		
		$("#breadcrumb b:last").click(function() {
			bcpos = BCgetPos(this);
			removeAfter(bcpos, true);
		});

		var motfois=0;
		
		$(".mot").one("click", function () {
			//alert($(this).attr("rel") + " " + getPos(this));
			if (motfois==0) addContent($(this).attr("rel"), getPos(this));
			//alert("?-=" + motfois);
			motfois = motfois+1;
		});


		$.get("url.php", function(data) {
			window.history.pushState("-", "-", data);
			//$(data).appendTo("#breadcrumb");
		});


	});
	
	
	
}

function scroll() {
		//scrollbar
		//alert("///");
		$(".a_content:last").jScrollPane();

}

function setLeft(force) {
	
	//alert("?");

		nbleft = getNb();
		if (force==true) nbleft = nbleft-1;
		lef = ((nbleft-1)*330-29);
		if (lef<0) lef=0;
		if (nbleft>-10) $("#content").animate({"left":"-"+lef+"px"}, function(){
			
			//alert("getnb : " + getNb());
		
			if (nbleft>1) {
				$("#breadcrumb").slideDown(); //fadeIn("normal");
				$("#back").show(); //fadeIn("normal");	
			}

		
		});


		
		if (nbleft<2) {
			$("#breadcrumb").hide(); //fadeOut("fast");
			$("#back").hide(); //fadeOut("fast");
		}

		//alert(getNb());
		
}

function getNb() {
	return $(".a_content").length;
}

function removeContent(pos) {
	v = Math.floor(Math.random()*3)+1;
	//alert(v);
	//$(".a_content:eq("+v+")").css("border", "1px solid black");
	$(".a_content:eq("+v+")").fadeOut("normal", function() {
		$(".a_content:eq("+v+")").remove();
		setLeft(force);
		

		
	});
	
	$("#breadcrumb b:eq("+(v+1)+")").remove();

}
 

function removeLast() {
	nb = getNb();
	//alert(nb);
	removeAfter(nb-2, true); 
	//alert(nb);
	//alert(getNb());
	//setLeft();
}

function removeAfter(pos, force) {

		if (pos==(-1)) $(".a_content").remove();
		else $(".a_content:eq("+pos+")").nextAll(".a_content").remove();
	
		if (pos>(-1)) $("#breadcrumb b:eq("+(pos)+")").nextAll("b").remove();
		else $("#breadcrumb b").remove();
		//alert(pos);

		setLeft(force);
		
}

function paddIt(j) {
	//$(which).animate({"padding-left":"25px", "opacity":"1"}, 400+j*280, 'easeInQuad');
	//alert(j);
	$(".a_content:last div.pad:nth-child("+j+")").animate({"padding-left":"25px", "opacity":"1"}, 400);
}


function activateLinks() {
	//$(".a_content:last").css("border", "1px solid red");
	//alert(pos);
	
	return;
	
	$(".a_content:last").find("a").click(function() {
		nb = getPos(this);
		removeAfter(nb, false);
		addContent(nb+1);
	});
}


function getPos(th) {
		n = $(th).parents("div.a_content").index(".a_content");
		return n;
		//alert(n);

}



function BCgetPos(th) {
		n = $("b").index(th);
		return n;
		//alert(n);

}


function moveLeft() {
	$("#left_menu span").each(function(index) { 
		div_larg = $(this).find("div").width();
   		this_larg = $(this).width();
	    larg = "-" + this_larg + "px";
	    $(this).next(".roll").css("margin-left", larg);
	});

}

//###################
//###### onLoad #####
//###################
$(document).ready(function() {




$("#back").click(function() {
	removeLast();
});




$("#keywords span").click(function () {

	$("#content").show();
	
	moveLeft();

	
	$("s").fadeOut("fast");
	$("#home").fadeOut("normal");

	$("#menu").fadeTo("normal", 1, function() {
	});
	$("#left_pane").fadeTo('normal', 1);
	
	addContent($(this).html());

});


$("#left_menu span").click(function () {
	
	removeAfter(-1);
	//addContent("page.php");
	//alert($(this).html());
	addContent($(this).html());

});




$("#keywords span").each(function(index) { 
	div_larg = $(this).next(".roll").width();
    this_larg = $(this).width();
    //alert(div_larg);
    larg = (div_larg+this_larg)/2;
    larg = "-" + larg + "px";
    $(this).next(".roll").css("margin-left", larg);

});


$("s").hide();



//glower();

$("span").hover(
  function () {
  	$(this).next(".roll").addClass("span_hover");
    $(this).next(".roll").find("s").fadeIn(200);
  }, 
  function () {
  	$(this).next(".roll").removeClass("span_hover");
    $(this).next(".roll").find("s").fadeOut(100);
  }
);



//alert($("#keywords span").length);   


});





function glower() {
	$("#left_pane").fadeTo('slow', 0.1, function() {
		$("#left_pane").fadeTo('slow', 0.2);
	
	});
	//alert("..");
	setTimeout("glower()", 3000);
}



