$.ajaxSetup({
cache: false
});



$("a.remote").click(function(){
									var hash = $(this).attr('href');
									alert(hash);
									hash = hash.replace(/^.*#/, '');
									hash = hash.split(':')
									// moves to a new page. 
									// pageload is called at once. 
									// hash don't contain "#", "?"
									$.historyLoad(hash[1]);
									return false;
									});

$(document).ready( function () {


//FORMULAIRE DE RECHERCHE
//produits
	$("#searchForm").submit( function() {
	//On recherche le mot a la page 0
	//search($('#searchinput').val(),"0");
		var hash = "search('"+$('#searchinput').val()+"','0');";
		hash = hash.replace(/^.*#/, '');
		// moves to a new page. 
		// pageload is called at once. 
		// hash don't contain "#", "?"
		$.historyLoad(hash);
	return false;
	});

	$("#infolettre").submit( function() {
		
		
		//alert($('#info-courriel').val());
		//alert($('#info-nom').val());
		
		$.ajax({	
			async: true,
			type: "POST",
			url: "php/login/infolettre.php",
			data: "mail="+$('#info-courriel').val()+"&nom="+$('#info-nom').val()+"&lang=fr",
  		    success: function(msg){
			
			//alert(msg);
			
			if(msg == "add" || msg == "\nadd" || msg == "\r\nadd" )
			{alert('Inscription réussie');}
			else if(msg == "already" || msg == "\nalready" || msg == "\r\nalready")
			{
			alert('Vous êtes déjà inscrit');
			}
			else if(msg == "error"  || msg == "\nerror" || msg == "\r\nerror")
			{alert("Veuillez vérifier les informations inscritent");
			}
			else
			{alert("Veuillez utiliser le script correctement");}
			
			
					
					// on désactive l'affichage du formulaire et on affiche un message de bienvenue à la place
				

			}
			});
	
	return false;
	});

	
});

    
//CHARGEMENT AU DEMARAGE || CHANGEMENT DE PAGE


$(window).load(function(){


$.ajax({
			url: "php/blog/lastblog.php",
			async: true,
  		    success: function(msg){
			//alert(msg);

		$("div#lastblog").html(msg);
		 $("div#lastblog").slideDown("normal");

									//Lorsqu'on clique

									}
		   
 });	
 								

									
					
								
$.historyInit(pageload, "jquery_history.html");	

			$("a.remote").click(function(){
									var hash = $(this).attr('href');
									
									hash = hash.replace(/^.*#/, '');
									hash = hash.split(':')
									// moves to a new page. 
									// pageload is called at once. 
									// hash don't contain "#", "?"
									alert(hash[1]);
									if(!hash[1]){
									listblog();	
									}else{
									$.historyLoad(hash[1]);
									}
									
									return false;
									});
									
							var hash = window.location.href;
							hash = hash.split('#')
									if(!hash[1]){
									listblog();	
									}else{
									$.historyLoad(hash[1]);
									}							

return false;
		
});
 
///MENU


function stripslashes(str) {
str=str.replace(/\\'/g,'\'');
str=str.replace(/\\"/g,'"');
str=str.replace(/\\0/g,'\0');
str=str.replace(/\\\\/g,'\\');
return str;
}

 function listblog()
{
	var hash = "listbloginit();";
		hash = hash.replace(/^.*#/, '');
		// moves to a new page. 
		// pageload is called at once. 
		// hash don't contain "#", "?"
		$.historyLoad(hash);
 }
 function listbloginit()//
{
$.ajax({	
			async: true,
			url: "php/blog/blog.php",
			 success: function(msg){
			//alert(msg);
					
					$("div#colRightBlog").html(msg);
					// on désactive l'affichage du formulaire et on affiche un message de bienvenue à la place
				

		   }
 });
 archives('off');
 }
 function get_blog(id)
{
archives('on');
	var hash = "get_blog_init('"+id+"');";
		hash = hash.replace(/^.*#/, '');
		// moves to a new page. 
		// pageload is called at once. 
		// hash don't contain "#", "?"
		$.historyLoad(hash);
 }
 function get_blog_init(id)
{
 
$("div#colRightBlog").html("<div id='loader'><img  src='images/ajax-loader.gif'></div>");

$.ajax({	
			
			type: "POST",
			url: "php/blog/get_blog.php",
			data: "id="+id,
  		    success: function(msg){
			//alert(msg);
					$("div#colRightBlog").html(msg);
					// on désactive l'affichage du formulaire et on affiche un message de bienvenue à la place
				

		   }
 });
 archives('on');
 } 
function get_article(id,art)
{
archives('on');
	var hash = "get_article_init('"+id+"','"+art+"');";
		hash = hash.replace(/^.*#/, '');
		// moves to a new page. 
		// pageload is called at once. 
		// hash don't contain "#", "?"
		$.historyLoad(hash);
 }
 function get_article_init(id,art)
{
$("div#contenuRight").html("<div id='loader'><img  src='images/ajax-loader.gif'></div>");

$.ajax({	
			
			type: "POST",
			url: "php/blog/get_article.php",
			data: "id="+id+"&art="+art,
  		    success: function(msg){
			//alert(msg);
					$("div#colRightBlog").html(msg);
					// on désactive l'affichage du formulaire et on affiche un message de bienvenue à la place
				

		   }
 });
archives('on');
 }





 
 //##################################################################
//ARCHIVE
function get_archives()
{
archives('on');
	var hash = "get_archives_init();";
		hash = hash.replace(/^.*#/, '');
		// moves to a new page. 
		// pageload is called at once. 
		// hash don't contain "#", "?"
		$.historyLoad(hash);
 }
function get_archives_init(){

		$.ajax({	
			async: true,
			url: "php/blog/get_som_arch.php",
			 success: function(msg){
			$("div#colRightBlog").html(msg);
			}
		});
	
}
function get_month(date)
{
archives('on');
	var hash = "get_month_init('"+date+"');";
		hash = hash.replace(/^.*#/, '');
		// moves to a new page. 
		// pageload is called at once. 
		// hash don't contain "#", "?"
		$.historyLoad(hash);
 }
function get_month_init(date){

		$.ajax({
			type: "POST",		
			async: true,
			url: "php/blog/get_month_search.php",
			data: "getdate="+date,
			 success: function(msg){
			$("div#colRightBlog").html(msg);
		
			}
		});
	
}
function archives(option){

	if(option == "on"){
		$.ajax({	
			async: true,
			url: "php/blog/get_arch.php",
			 success: function(msg){
			$("div#archives").html(msg);
			}
		});
		
	}else{
		$.ajax({	
			async: true,
			url: "php/blog/get_arch.php",
			 success: function(msg){
		
		
	var presentation = "<h2>Municipalité<br />de Lac-Beauport</h2>"
    +"<p>"
    +"La qualité de vie, l’environnement, la famille et la tranquillité sont des valeurs partagées par l’ensemble de la communauté lac-beauportoise. La préservation de ce milieu de vie exceptionnel constitue une priorité dans les actions politiques et citoyennes. "
    +"</p>"
    +"<p>"
    +"<a class=\"flecheDroite\" href=\"http://www.lac-beauport.ca/\" target=\"_blank\">En savoir plus sur Lac-Beauport</a>"
    +"</p>";
	$("div#archives").html(presentation+msg);
		}
		});
	}

}


//##################################################################
//RECHERCHE

function search(mot,page,ob,direction,searchaction)
{
archives('on');
$("div#colRightBlog").html("<div id='loader'><img  src='images/ajax-loader.gif'></div>");

//alert(mot);
		$.ajax({
		
		   type: "POST",
		   url: "php/blog/get_search.php",
		   data: "search="+mot+"&page="+page+"&ob="+ob+"&direction="+direction+"&searchaction="+searchaction,
		    success: function(msg){
				//alert(msg);
			
				$("div#colRightBlog").html(msg);
				},
		    
			error: function(){
			alert('Erreur AJAX : 0006 - Cette erreur est normalement temporaire, veuillez recommencer l\'opération...\n etienne.latulippe@oragecommunication.com');
			}
			
		});
	
}
//même recherche..par page
function searchpage(mot,page,ob,direction,searchaction)
{
if(undefined===window.searchaction){
window.searchaction = [];
}
		var hash = "search('"+mot+"','"+page+"','"+ob+"','"+direction+"','"+searchaction+"');";
		hash = hash.replace(/^.*#/, '');
		// moves to a new page. 
		// pageload is called at once. 
		// hash don't contain "#", "?"
		$.historyLoad(hash);	
//return false;		
}

//##################################################################
//



function ouvre_popup(id_pic) {
alert("--");
 }
 
function pageload(hash) {

								//le nom de la page qui load le script
								var nom = window.location.pathname;
								nom = nom.split("/");
								nom = nom[nom.length - 1];
								//nom = nom.substr(0, nom.lastIndexOf("."));
								nom = nom.replace(new RegExp("(%20)", "g"), "");
								if(nom.indexOf('#')!=-1){var sentinelle = 1}
								nom = nom.replace("#", "");
								//On initialise l'historique du menu 
								
								
		if(hash && hash.indexOf("(") != -1) {
			// restore ajax loaded state
			if($.browser.msie) {
				// jquery's $.load() ne prend pas les caractères trop spéciaux ex: ë
				hash = encodeURIComponent(hash);
			}
			hash = "<script type='text\/javascript'>"+hash+"<\/script>";
			hash = unescape(hash);
			
			$("div#colRightBlog").html(hash);
			
		}
		else{
			// start page
			nom = nom+'#'+hash;
			window.location.replace(nom);
		}
	}
	
//ROLL OVER ###################################################################
function SimpleSwap(el,which){
  el.src=el.getAttribute(which || "origsrc");
}

function SimpleSwapSetup(){
  var x = document.getElementsByTagName("img");
  for (var i=0;i<x.length;i++){
    var oversrc = x[i].getAttribute("oversrc");
    if (!oversrc) continue;
      
    // preload image
    // comment the next two lines to disable image pre-loading
    x[i].oversrc_img = new Image();
    x[i].oversrc_img.src=oversrc;
    // set event handlers
    x[i].onmouseover = new Function("SimpleSwap(this,'oversrc');");
    x[i].onmouseout = new Function("SimpleSwap(this);");
    // save original src
    x[i].setAttribute("origsrc",x[i].src);
  }
}

var PreSimpleSwapOnload =(window.onload)? window.onload : function(){};
window.onload = function(){PreSimpleSwapOnload(); SimpleSwapSetup();}


