// JavaScript Document


hash_en_cours = document.location.hash.substring(1);


if ( hash_en_cours == "" || hash_en_cours == "/home.php" || hash_en_cours == "home") {
	//alert ("home")
	
	//alert ("home : "+hash_en_cours)	;
	//chargePage('home.php',true);
	//setTimeout( "chargePage( 'home.php' , true )" , 500 );

}else{
	
	var maVariable = hash_en_cours;
	maVariable = maVariable.substr( 0 , maVariable.indexOf("-") );
	
	var nuit_z = new String(document.location.hash.substring(1));
	nuit_z = nuit_z.substr( 0 , nuit_z.indexOf("-") );
	
	var artistes_z = new String(document.location.hash.substring(1));
	artistes_z = artistes_z.substr( 0 , artistes_z.indexOf("-") )
		
	if ( hash_en_cours == "/agenda.php"){
		setTimeout( "chargePage( 'agenda.php' , true )" , 500 );
	}
	
	if ( hash_en_cours == "/info.php"){
		setTimeout( "chargePage( 'info.php' , true )" , 500 );
	}
	
	if ( maVariable == "/artiste"){
		indice = new String(document.location);
		//page = page.substr( 50 , page.indexOf("/")-2 );
		indice = indice.substr( indice.indexOf("-")+1 , indice.length )
		indice = indice.substring( 0 , indice.indexOf(".") );
		setTimeout( "chargePage( 'artiste-"+indice+".html' , true )" , 500 );
	}
	
	if ( maVariable == "/nuit"){
		indice = new String(document.location);
		//page = page.substr( 50 , page.indexOf("/")-2 );
		indice = indice.substr( indice.indexOf("-")+1 , indice.length );
		indice = indice.substr( indice.indexOf("-")+1 , indice.length );
		indice = indice.substring( 0 , indice.indexOf(".") );
		setTimeout( "chargePage( 'nuit-zebree-"+indice+".html' , true )" , 500 );
		
	}
	
}
	


function chargePage( page , changeHash , nom ){	
	hash_en_cours = page;
	writeURL = page.substring( 0 , page.length - 5 );

	//
	if ( changeHash ){
		
		if ( hash_en_cours == "#"){
			document.location.hash = "#";
		} else {
			
			if ( nom == "" || nom == undefined ){
				document.location.hash = "/"+page; 
				
			} else {
				document.location.hash = "/"+page+"?recherche="+nom;
			}
		}
	}
	
	envoiediv( page , "#contenu" );
	
}


function redirectURL(url){
	document.location = "http://www.lesnuitszebrees.com/#/"+url;
}




window.setInterval(function () {
	if (hash_en_cours == "#"){
		hash_en_cours = "home";
	}
							 
	if ( hash_en_cours != document.location.hash.substring(2) )
		chargePage( document.location.hash.substring(2) , false );
} , 100 )


function envoieRequete( url , id )
{	
	
	var xhr_object = null;
	var position = id;
	   if(window.XMLHttpRequest)  xhr_object = new XMLHttpRequest();
	  else
	    if (window.ActiveXObject)  xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 

	// On ouvre la requete vers la page désirée
	
	xhr_object.open( "GET" , url, true);
	
	xhr_object.onreadystatechange = function(){
		if ( xhr_object.readyState == 4 ){
			// j'affiche dans la DIV spécifiées le contenu retourné par le fichier
			
			document.getElementById(position).innerHTML = xhr_object.responseText;
		}
	}
	
	// dans le cas du get
	
	xhr_object.send( null );
	
}


function envoiediv( url , div )	{

	
	if( url != "" ){
		envoieRequete( url  , "contenu");
		/*
		if( url == "home.php"){
			chargePub();
		}
		*/
	} 
	else if ( url == "#"){
		envoieRequete( "#" , "contenu");
	}		

/*	

    $.ajax({
        url: url,
        success: function(msg){
            $(div).fadeOut(300, function() {
									   
				if( url != "" ){
					envoieRequete( url  , "contenu");
				} 
				else if ( url == "#"){
					envoieRequete( "#" , "contenu");
				}				   
									   
                $(div).empty();          
                $(div).append(msg);
                $(div).fadeIn(800);
            });
        }
    });
*/
}

function ouvre( id ){
	//document.getElementById('id_artiste').echo_4(); return false;
	appel_2(id);
}


function nomPage( nom ){
	//
	document.title = nom;
	
}


// lance player par facebook

function getVar (nomVariable)
{
	
	
	var infos = location.href.substring(location.href.indexOf("?")+1, location.href.length)+"&"
	if (infos.indexOf("#")!=-1)
		infos = infos.substring(0,infos.indexOf("#"))+"&"
	var variable=0
	{
		nomVariable = nomVariable + "="
		var taille = nomVariable.length
		if (infos.indexOf(nomVariable)!=-1)
			variable = infos.substring(infos.indexOf(nomVariable)+taille,infos.length).substring(0,infos.substring(infos.indexOf(nomVariable)+taille,infos.length).indexOf("&"))
	}
	
	if ( variable == 1){

		indice = new String(document.location);
		//page = page.substr( 50 , page.indexOf("/")-2 );
		indice = indice.substr( indice.indexOf("-")+1 , indice.length );
		indice = indice.substr( indice.indexOf("-")+1 , indice.length );
		indice = indice.substring( 0 , indice.indexOf(".") );
		//
		ouvre(indice);

	}
}
//variable=getVar('variable')
getVar('facebook')




