function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}
var http = createRequestObject();
function sndReq(page) {
    http.open('get', 'rpcajax.php?page='+page);
    http.onreadystatechange = handleResponse;
    http.send(null);
}
function handleResponse() {
    if(http.readyState == 4){
        var response = http.responseText;
if (response!='404'){
        var update = new Array();
	if(response.indexOf(',next!,' != -1)) {
        	update = response.split(',next!,');
		$('#loading').animate({ opacity:0 }, 'slow', function(){$('#loading').remove();});
		$.address.title($.address.title().split(' | ')[0] + ' | ' + update[0]);
		$('#mainContent').html(update[1]);
		$("#taille").animate({ height: document.getElementById('mainContent').offsetHeight, opacity:1 }, "slow");
		}
}else{
			window.location = "/#";
		}
	}
}
var idact = new String;
$(document).ready(function(){
	$("#menu a")
	.mouseover(function(){
		var idck = $(this).attr('class');
		if (idck!=idact){
			$('#'+idck+' td').animate( {backgroundPosition:'(0px -48px)'}, 0)
		}
	} )
	.mouseout(function(){
		var idck = $(this).attr('class');
		if (idck!=idact){
			$('#'+idck+' td').animate( {backgroundPosition:'(0px 0px)'}, 0)
		}
	} )
	.mousedown(function(){
		var idck = $(this).attr('class');
		if (idck!=idact){
			$('#'+idck+' td').animate( {backgroundPosition:'(0px -96px)'}, 0)
		}
	})
	.click(function(){
		return false;
	})
})
$.address
.init(function(event) {
})
.change(function(event) {
	if (event.value!='/'){
		var teste = event.value.replace(RegExp('/', 'g'),'');
		teste = teste.replace(RegExp('.html', 'g'),'');
		idact= teste;
		$('#menu #tablemenu table td').animate( {backgroundPosition:'(0px 0px)'}, 0);
		$('#'+idact+' td').stop();
		$('#'+idact+' td').animate( {backgroundPosition:'(0px -144px)'}, 0);
		if($('body').children().is('#loading')==false){
			$('<div id="loading"></div>').prependTo('body');
		} else {
			$("#loading").stop();
			$("#taille").stop();
			http.abort();
		}
		$("#loading").animate({ opacity:0 }, 0, "linear", function(){$('#loading').animate({ opacity:0.7 }, 1000, "linear", function(){ sndReq(teste)})});
		$("#taille").animate({ opacity:0 },"fast", "linear", function(){$('#mainContent').empty()});
	}else{
		var adress = window.location.pathname;
if (adress=='/'){
			adress='/accueil.html';
		}
       		window.location = "/#"+ adress;
	}
});
