﻿
var Title = new Array();
Title['/accueil'] = 'Hugo GIRAUD - Accueil';
Title['/contact'] = 'Hugo GIRAUD - Formulaire de contact';
Title['/competences'] = 'Hugo GIRAUD - Compétences';
Title['/formations'] = 'Hugo GIRAUD - Formations';
Title['/experiences'] = 'Hugo GIRAUD - Expériences';
Title['/realisations'] = 'Hugo GIRAUD - Réalisations';
Title['/404'] = 'Hugo GIRAUD - Erreur 404';

var Pages = new Array('accueil', 'formations', 'competences', 'experiences', 'realisations', 'contact', '404');

function onPageLoad(id){
for (i=0; i<Pages.length; i++) { if($("#menu-"+Pages[i])) $("#menu-"+Pages[i]).addClass('page_item page-item-58');
														$("#menu-"+Pages[i]).removeClass('page-item-2 current_page_item');}

if($("#menu-"+id.substring(1, id.length))) { $("#menu-"+id.substring(1, id.length)).removeClass('page_item page-item-58');
											$("#menu-"+id.substring(1, id.length)).addClass('page-item-2 current_page_item'); }
}

function pageload(hash) {
	if($.inArray(hash.substring(1, hash.length), Pages) > -1) {
	var cache = $.jCache.getItem(hash);
	if(cache) {
		$("#main").html(cache);
		document.title = Title[hash];
		onPageLoad(hash);
	} else {
	$.ajax({ type: "GET", url: hash.substring(1, hash.length)+'.php', 
	success: function(data){
			$("#main").html(data);
			$.jCache.setItem(hash, data);
			document.title = Title[hash];
			onPageLoad(hash);},
	error: function(){
			$.historyLoad('/404');
		;},
	beforeSend: function() {
		$("#main").html("<img src='http://cv.yriase.fr/images/ajax-loader.gif' alt='Loading' />");
	}
		});
	}
	}
}

$(document).ready(function(){
 $.historyInit(pageload);
});

// Précharge en cache les pages du site pour une navigation plus fluide 
function preLoadPages() {
	for (i=0; i<Pages.length; i++) {
		var hash = "/"+Pages[i];
		var cache = $.jCache.getItem(hash);
		if(!cache) {
		$.ajax({ type: "GET", url: hash.substring(1, hash.length)+'.php', 
		success: function(data){
				$.jCache.setItem(hash, data);},
			});
		}	
	}
}

$(document).ajaxComplete(function(){
 // sélection de tous les liens a ayant l'attribut rel égal à history (valeur arbitraire)
 $(".history").click(function(){
   //suppression du mot cle history, pour que les liens ne soient surchargés qu'une seule fois
   this.rel = this.rel.replace(/history/, '');
   // mise à jour de l'ancre
   var hash = this.href;
   // suppression du caractère #
   hash = hash.replace(/^.*#/, '');
   // chargement dans l'historique et appel de pageload
   $.historyLoad(hash);
   // trés important : désactivation du clic du lien a
   return false;
 });
});

function show_real(type) {
	if(type == 'web') {
		$("#real_log").toggle('fast');
		$("#real_web").toggle('slow');
	}
	else {
		$("#real_web").toggle('fast');
		$("#real_log").toggle('slow');
	}
}

