// JavaScript Document
//$(document).ready(function () {
//	$('#v_b_menu_in a').each(function(){
//		$(this).click(function(){
//			return gi_load_content(this.href);
//		});
//	});
//});
//function gi_load_content(url){
//	gi_loading('#g_content');
//	var new_url = url+'/content/true';
//	$("#g_content").load(new_url,'',function(){
//		// on modifie les urls pour la modification de langue
//		$('#g_lang a').each(function(){
//			var url_ = $(this).attr('href');
//			url_ = url+'/lang/'+$(this).attr('class');
//			$(this).attr('href',url_);
//			if($('#v_p_accueil')){
//				// uniquement pour la page de recherche google
////				google_searcher_init();
//			}
//		});
//	});
//	return false;
//}
//function gi_loading(block){
//	$(block).prepend('<div id="extra_chargement">'+loading_msg+'</div>');
//	return;
//}

// on ne peux pas charger un second fichier tant qu'il y Ã  un fichier en train de se charger
var v_b_menu_loading = false;
var v_b_menu_init = true;
$(document).ready(function () {
	// Agir dÃ¨s que le DOM est prÃªt
	var gi_hash = window.location.hash;
	if(gi_request_uri=='/'){
		gi_request_uri='';
	}
	if(gi.empty(gi_hash) && gi.empty(gi_request_uri)){
		window.location.hash = '/index/index';
	}
//	else if(!gi.empty(gi_request_uri)){
//		window.location.hash = gi_request_uri;
//	}
	else{
		v_b_menu_init = false;
	}

	// Initialize history plugin.
	// The callback is called at once by present location.hash.
	$.historyInit(pageload);

	// set onlick event for buttons
	$("a[@rel='history']").click(function(){
		//
		var _href = $(this).attr('href');
		$(this).attr('href','#'+_href);
		var hash = this.href;
		hash = hash.replace(/^.*#/, '');
		// moves to a new page.
		// pageload is called at once.
		v_b_menu_init = false;
		v_b_menu_loading = false;
		$.historyLoad(hash);
		return false;
	});
});
// PageLoad function
// This function is called when:
// 1. after calling $.historyInit();
// 2. after calling $.historyLoad();
// 3. after pushing "Go Back" button of a browser
function pageload(hash) {
//	alert('hash : '+hash+'; uri : '+gi_request_uri);
	if(hash.match('/index/index') && (gi.empty(gi_request_uri) || gi_request_uri.match('/index/index'))){
		return;
	}
	// hash doesn't contain the first # character.
	if(gi.empty(hash) || v_b_menu_init==true){
		v_b_menu_init = false;
		return;
		//		hash='/index/index';
	}
	if(hash.match(/tab-.*?/)){
//		var gi_reg=new RegExp("tab-", "g");
//		var gi_reg_tableau=hash.split(rwf_reg);
		return;
	}
	//	if((hash==gi_request_uri && gi_hash_init==true) || (gi_empty(gi_request_uri) && hash=='/index/index' && gi_hash_init==true)){
	//		gi_hash_init = false;
	//		return;
	//	}
	if(!gi.empty(hash) && v_b_menu_loading==false) {
		gi_loading('#g_content');
		v_b_menu_loading = true;
		// restore ajax loaded state
		$("#g_content").load(hash+'/content/true','',function(){
			v_b_menu_loading = false;
			// on modifie les urls pour la modification de langue
//			$('#v_b_lang a').each(function(){
//				url = hash;
//				var url_ = $(this).attr('href');
//				url_ = url+'/lang/'+$(this).attr('class');
//				$(this).attr('href',url_);
//
//			});
		});
	}
}
function gi_loading(block){
	$(block).prepend('<div id="extra_chargement">'+loading_msg+'</div>');
	return;
}