<!-- Debut
// JavaScript pris sur le site: "http://www.java.scripts-fr.com"
var urlBase=$('meta[name=root]').attr('content');
$(document).ready(function(){
changelinks();
changeforms();
 })


			

// My mini "Ajax" (DHTML) app
function PromptMe() {
	// some application vars
	var stateVar = "nothin'", displayDiv = document.getElementById("HistoryState");
	
	// the sole public method to manipulate this application
	this.promtForNew = function() {
		// do the stuff that changes the state
		var newVal = window.prompt("Please enter some value to store in the history and url");
		// Set the new history hash. This value must be a string, so serializtion is up to you.
		// JSON works nicely, if you need something quick: http://www.json.org
		// When a new entry is made, unFocus.History will notify the historyListener 
		// method of the change, even on the first call. For this demo app we can 
		// rely on the historyListener method to update the state, and view.
		unFocus.History.addHistory(newVal);
	};
	
	// This is the method that will recieve notifications from the History Keeper,
	// which will then update the state of the app.
	// :NOTE: This will be called when a new entry is added.
	// :NOTE: This will be called if another app on the page sets a history,
	//        so you will need to watch out for this, if you have more than
	//        one script using the history keeper, by doing some kind of 
	//        check to make sure that the new hash belongs to this app.
	//        I wouldn't expect this to be a problem all that frequently.
	this.historyListener = function(historyHash) {
		// update the stateVar
		stateVar = historyHash;
		// update display content
		if(historyHash==""){return false;}
		if(historyHash=="accueil"){loadPage(urlBase+"/");}else{
		loadPage(urlBase+"/"+historyHash);}
		// update document title
		var jolititle=(historyHash.charAt(0).toUpperCase() + historyHash.substr(1).toLowerCase()).replace( "-", " " );

		//document.title = "Pur et caetera - " + jolititle;
	};
	// subscribe to unFocus.History
	unFocus.History.addEventListener('historyChange', this.historyListener);
	
	// Check for an initial value (deep link).
	// In this demo app, the historyListener can handle the task.
	this.historyListener(unFocus.History.getCurrent());
};
// instantiate and inialize the app. DOM has to be ready so we can get a ref to
// the HistoryState DOM element (aka the view), so we use QuickLoader to make
// sure it's ready.
var demoApp;

function gotoPageMan(hashtogive){
			unFocus.History.addHistory(hashtogive);
			}

function changeforms(){
	$('#searchsubmit').click(function(){
		var str = $(this).serialize();
		window.location=urlBase+"/#?s="+$("#s").val();
		return false;
		})

	}

function changelinks(){
			var i=0;
			var urlAenlever=urlBase+"/";
			$('a').each(function(index) {
								 if(($(this).attr("href").substring(0,urlBase.length)==urlBase) || ($(this).attr("href")=="") || ($(this).attr("href").substring(0,1)=="?")|| ($(this).attr("href").substring(0,1)=="/")){
									 if($(this).attr("href").substring(urlAenlever.length,urlAenlever.length+8)!="wp-admin"){
										 if($(this).attr("href").substring(urlAenlever.length,urlAenlever.length+4)!="feed"){
			var href=$(this).attr("href");
			href=href.substring(urlAenlever.length,href.length);
			
			if((href=="") || (href=="/")){href="accueil";}
			if(href.substring(0,1)=="#"){$(this).attr("href",urlAenlever+href);}else{
			$(this).attr("href",urlAenlever+"#"+href);}
			}else{$(this).attr("target","_blank");}
			}else{$(this).attr("target","_blank");}
			}else{$(this).attr("target","_blank");}
								 
  });
		/*for(i=0;i<document.getElementsByTagName("a").length;i++){
			$extension=document.getElementsByTagName("a").item(i).href;
			$debuturl=document.getElementsByTagName("a").item(i).href;
			$extension=$extension.substring($extension.length-3,$extension.length);
			$debuturl=$debuturl.substring(0,urlAenlever.length);
			if(($extension!="jpg") &&($extension!="pdf") &&($extension!="gif")&&($extension!="png")&& ($debuturl=="http://www.pur-etc.fr/")){
			var urlenter=document.getElementsByTagName("a").item(i).href;
			var hashtogive=urlenter.substring(urlAenlever.length,urlenter.length);
			
		document.getElementsByTagName("a").item(i).href="javascript:gotoPageMan('"+hashtogive+"');"
			}else{document.getElementsByTagName("a").item(i).target="_blank"}
			if($extension=="jpg"){document.getElementsByTagName("a").item(i).rel="clearbox";}
			}*/
		}
		
		
function loadPage(urlString){
	$("#chargement").stop();
	$("#chargement").animate({
    top:0}, 200);
	$.ajax({
   type: "POST",
   url: urlString,
   data: "goJav=1",
   dataType: "html",
   success: function(msg){
	   scrollToPos("#head");
	   $("#chargement").stop();
	   	$("#chargement").animate({
    top:"-40px"}, 200);
	   $("#center").html(msg);
	   $("#center").css("display","block");
	   //$("#center").html($("#center", msg).html());
		changelinks();
		
		if($("#main").hasClass("fullwidth")==true){
			$("body").addClass("fullwidth");
			}else{$("body").removeClass("fullwidth");};
   }
 });
	}
			
function scrollToPos(id){
	$('html,body').animate({
scrollTop: $(id).offset().top
}, 500);}
