//variables globales pour la home
var width_work;
var nb_work;
var delay_transition_work = 6000;
var timer_transition_home;

//variables globales pour mozaic et list des réalisations
//nb_works,nb_work_page,nb_work_list,nb_page_s,mozaic_active sont globales et 
//déjà déclarées
var width_nav_bar_div;
var jquery_object_mozaic_div;
var content_ajax = "";
var nb_works_s;
var pagination_history = new Array();
var first_load = true;
var height_container_page;
//variables globales pour la page detail de réalisation
var width_picture;
var nb_pictures;
var delay_transition_pict = 4000;
var timer_transition_gallery; 
var width_div = 600;
var first_load = true;
var last_nb_page;
//variables globales pour agence
var selected_agency_part ;
var selected_skills_part ;
var selected_jobs_part ;
//contact
var old_active_btn;
//msie for timer gallery
if($.browser.msie)
{
delay_transition_work = 4500;
delay_transition_pict = 4500;	
}

$(document).ready(initSite);

function initSite()
{
	//réinit pagination
	if(!$('body').hasClass('work'))
	{
		$.post('/ajax/setPaginationNumber',{nb_page:1});
	}
	
	//globale au site
	$('a[rel=ext_links]').click(openWindow);
	//$(".back_link_works").click(backToPage);
	//on supprime le no js
	$('body').removeClass('nojs');
	
	//pour le menu
	initMenu();
	$("#access_plan_btn").toggle(setContactCat,disableContact);
	//pour la gestion de plan d'access
	$("#contact_cat a,.contact_link,#top_links .contact_cat").click(function(){$("#access_plan_btn").click();return false;});
	$("#close_plan").live('click',function(){$("#access_plan_btn").click();return false;});
	
	//pour le formulaire
	$("#form_contact").submit(sendMail);
	$("#overlay_contact").css('opacity','0.6');
	
	//pour la home
	if($('body').hasClass('home'))
	{
		initHomeGallery();
	}
	
	//pour la page réalisations
	if($('.work_expose').length != 0)
	{
		initWorksApp();
	}
	
	//pour la page detail de réalisation
	if($('#gallery').length != 0)
	{
		initGallery();
	}
	
	//pour la page sitemap
	if($("#sitemap").length != 0)
	{
		initSiteMap();
	}
	//pour la gestion des hash
	$(window).bind("hashchange",getContent);
	$(window).trigger('hashchange');
	
	//gestion d'IE6
    $.reject(
    {
        imagePath:'/img/default/',
        header: 'Le navigateur que vous utilisé est dépassé.',
        paragraph1: 'Votre navigateur est ancien et est possible de pas être compatible avec ce site. Une liste des navigateurs les plus populaires est affichée ci-dessous.',
        paragraph2: 'Cliquez simplement sur le navigateur de votre choix pour accéder à sa page de téléchargement.',
        closeMessage: 'En fermant cette fenêtre, vous prenez connaissance et accepter que votre expérience utilisateur puisse être altérée sur ce site.',
        closeLink: 'Fermer cette fenêtre',
        closeCookie: true,
        cookieSettings: {  
        path: '/', // Path for the cookie to be saved on (should be root domain in most cases)  
         expires: 0 // Expiration Date (in seconds), 0 (default) means it ends with the current session  
     }
    });
    
    //fonction gestion key press
    $(document).bind('keypress',goToCategory);
    $("#contact_form input,#contact_form textarea").focus(function(){$(document).unbind('keypress');});
    $("#contact_form input,#contact_form textarea").blur(function(){$(document).bind('keypress',goToCategory);});
    
    //pour la page job
    if($('body').hasClass('jobs'))
    {
    	initJobs();
    }
}

//gestion des touches entrées
function goToCategory(event)
{
	if(event.which > 48 && event.which < 53)
	{
		if(event.which != 52)
		{
			cat_value_number = parseInt(String.fromCharCode(event.which))-1;
			var value_target = $("#main_menu>ul>li:eq("+cat_value_number+") a").attr('href');
			document.location = value_target;	
		}
		else
		{
			$("#access_plan_btn").click();
		}
	}	
	return false;
}

//ouvre un nouvel onglet
function openWindow()
{
	var target_value = $(this).attr('href');
	window.open(target_value);
	return false;
}

function backToPage()
{
	history.back();
	return false;
}

//gère les hash
function getContent()
{
	var hash = location.hash;
	//on récupère le hash
	if(hash != null && hash != "")
	{
		var reg = new RegExp('#?\/?([A-Za-z]+\-?[A-Za-z]*)+\/?');
		var tab = reg.exec(hash);
		// on retire les slash
		var final_hash = tab[0].replace('/','');
		final_hash = final_hash.replace('/','');
		//si c'est contact, on load l'access map
		switch(final_hash)
		{
			case 'all' :
			case 'web' :
			case 'e-commerce' :
			case 'applications-mobiles' :
			case 'marketing' :
			case 'ingenierie' :
			case 'graphisme' :
			case 'marketing' :
				loadSearchController(final_hash);
			break;
			case 'access-plan':
			case 'contact':
				$("#access_plan_btn").click();
			break;
			case 'team':
			case 'skills':
			case 'philosophy':
				setAgencyContent(final_hash) ;
				break;
			case 'trainee-webdesigner' :
			case 'trainee-development' :
			case 'development' :
			case 'webdesigner' :
				setJobContent(final_hash);
			break;
		}
	}
}

function setContactCat()
{
	$(document).unbind('keypress');
	$("#wrapper").append('<div id="overlay_wrap"></div>');
	if(!$('body').hasClass('home'))
	{
		$("#overlay_wrap").css({opacity:'0.5'});
	}
	else
	{
		$("#overlay_wrap").css({opacity:'0.5',top:'-152px'});
	}
	$("#overlay_wrap").click(function(){$("#access_plan_btn").click();return false;});
	//on l'envoie direct
	$("#nameid").focus();
	//on modifie le menu
	old_active_btn = $(".active_menu").attr('id');
	$("#main_menu>ul>li:not(#contact_cat)>a").animate({height:'43px',backgroundColor:"#FFF",backgroundPosition:'0 0'},200,'easeOutElastic');
	$("#main_menu>ul>li:not(#contact_cat)>a").children('span').animate({color:'#4C443D',fontSize:'28px'}).css({fontWeight:'normal'});	
	$("#contact_cat>a").stop(true,false).animate({height:'53px',backgroundColor:"#f71c57",backgroundPosition:'0 -53px'},200,'easeInOutCubic');
	$("#contact_cat>a>span").stop(true,false).animate({color:'#FFFFFF',fontSize:'32px'}).css({fontWeight:'bold'});	
	$("#contact_cat").addClass('prioritory_active');
	$("#picture_category").addClass('contact');	
	//load plan
	loadAccessPlan();
}

function disableContact()
{
	$(document).bind('keypress',goToCategory);
	$("#access_plan").css('display','none');
	$("#contact_cat").removeClass('prioritory_active');
	$("#picture_category").attr('class',$('body').attr('class'));
	$("#main_menu>ul>li>a").stop(true,false).animate({height:'43px',backgroundColor:"#FFF",backgroundPosition:'0 0'},200,'easeOutElastic');
	$("#main_menu>ul>li>a").children('span').stop(true,false).animate({color:'#4C443D',fontSize:'28px'}).css({fontWeight:'normal'});
	$("#overlay_wrap").fadeOut(400,function(){$(this).remove();});
	enableMainCat();
	return false;
}

function loadAccessPlan()
{
	if($("#access_plan").length == 0)
	{
		//on load le plan
		$.get('/ajax/getAccessPlan',
			function(data)
			{
				$(data).css({display:'none'}).appendTo("#right_column");
				$("#google_map").css({width:'320px',height:'274px'});
				//on met en place le google map
	            var myLatlng = new google.maps.LatLng(47.305751,-2.389923);
	            var myOptions = {
	              zoom: 15,
	              center: myLatlng,
	              mapTypeId: google.maps.MapTypeId.ROADMAP
	            };
	            var googleicon = "/img/default/marker_map.png";        
	            var map = new google.maps.Map(document.getElementById("google_map"),myOptions);
	            var marker = new google.maps.Marker({
	                  position: new google.maps.LatLng(47.304949,-2.389296),
	                  map:map,
	                  title:"Image WebDesign",
	                  icon:googleicon, //"http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png"
	                  animation: google.maps.Animation.DROP
	            });
	            $("#google_map a[href=http://www.google.com/intl/fr_US/help/terms_maps.html]").attr('test','test');
	            $("#access_plan").css('display','block');
				
				
			}
		);	
	}
	else
	{
		$("#access_plan").css('display','block');
	}
	
}

function removeAccessPlan()
{
	$("#access_plan").css('display','none');
	$("#overlay_wrap")
}

function sendMail()
{
	//on met en place l'overlay
	$("#overlay_contact").slideDown();
	//on supprime les error input
	$('.error_input').removeClass('error_input');
	//on récupère les informations et on envoie
	$.post('/ajax/sendMail',$("#form_contact").serialize(),
		function(data)
		{
			if(data.response)
			{
				$(data.confirmMsg).insertBefore('#form_contact');
			}
			else
			{
				for(key in data.errors)
				{
					if(!data.errors[key])
					{
						$("input[name="+key+"]").parent().addClass('error_input');
						$("textarea[name="+key+"]").parent().addClass('error_input');
					}
				}
			}
			$("#overlay_contact").slideUp();
		}
	);
	return false;
}
/***********************************Menu**************************************/
function initMenu()
{
	//on active la bonne rubrique
	var classBody = $('body').attr('class');
	$("#"+classBody+"_cat").addClass('active_menu');
	$('.active_menu').children('a').animate({height:'53px',backgroundColor:"#f71c57",backgroundPosition:'0 -53px'},400,'easeInOutCubic');
	$('.active_menu').children('a').children('span').animate({color:'#FFFFFF',fontSize:'32px'}).css({fontWeight:'bold'});		
	$('.active_menu').children('ul').css('display','block');
	//définition des écouteurs
	$("#main_menu>ul>li:not(.active_menu)>a").css('height','43px');
	$("#main_menu>ul>li>a").mouseleave(disableCat).mouseenter(enableCat);
	$("#left_column").mouseleave(enableMainCat);
	//on met des écouteurs sur le sous menu
	if($('#main_menu>ul>li>ul').length > 0)
	{
		$('#main_menu>ul>li>ul').mouseenter(
				function()
				{
					$(this).parent().children('a').stop(true,false).animate({height:'53px',backgroundColor:"#f71c57",backgroundPosition:'0 -53px'},200,'easeInOutCubic');
					$(this).parent().children('a').children('span').stop(true,false).css({color:'#FFFFFF',fontSize:'32px'}).css({fontWeight:'bold'});
				}
		);
		$('#main_menu>ul>li>ul').mouseleave(
				function()
				{
					if(!$(this).parent().hasClass('active_menu'))
					{
						$(this).parent().children('a').stop(true,false).css({height:'43px',backgroundColor:"#FFF",backgroundPosition:'0 0'});
						$(this).parent().children('a').children('span').stop(true,false).css({color:'#4C443D',fontSize:'28px'}).css({fontWeight:'normal'});	
					}
				}
		);
	}
}

function enableCat()
{	
	$(this).stop(true,false);
	//$('.active_menu,.prioritory_active').children('ul').stop(true,false).css('display','none');
	if($(this).css('height') != "53px")
	{
		$('.active_menu,.prioritory_active').children('a').stop(true,false).css({height:'43px',backgroundColor:"#FFF",backgroundPosition:'0 0'});
		$('.active_menu,.prioritory_active').children('a').children('span').stop(true,false).css({color:'#4C443D',fontSize:'28px'}).css({fontWeight:'normal'});
		$(this).animate({height:'53px',backgroundColor:"#f71c57",backgroundPosition:'0 -53px'},200,'easeInOutCubic');
		$(this).children('span').animate({color:'#FFFFFF',fontSize:'32px'}).css({fontWeight:'bold'});		
	}
}

function disableCat()
{
	if(!$(this).parent().hasClass('active_menu'))
	{
		$(this).stop(true,false);
		$(this).animate({height:'43px',backgroundColor:"#FFF",backgroundPosition:'0 0'},200);
		$(this).children('span').animate({color:'#4C443D',fontSize:'28px'}).css({fontWeight:'normal'});			
	}
}

function enableMainCat()
{
	//on arrete toutes les annimations et on re init le menu
	$("#main_menu>ul>li:not(.active_menu)>a").stop(true,false).css({height:'43px',backgroundColor:"#FFF",backgroundPosition:'0 0'});
	$("#main_menu>ul>li:not(.active_menu)>a>span").stop(true,false).css({color:'#4C443D',fontSize:'28px'}).css({fontWeight:'normal'});
	$("#main_menu>ul>li:not(.prioritory_active)>a").stop(true,false).css({height:'43px',backgroundColor:"#FFF",backgroundPosition:'0 0'});
	$("#main_menu>ul>li:not(.prioritory_active)>a>span").stop(true,false).css({color:'#4C443D',fontSize:'28px'}).css({fontWeight:'normal'});
	//on remet en activ la bonne catégorie
	if($('.prioritory_active').length == 0)
	{
		$('.active_menu').children('a').css({height:'53px',backgroundColor:"#f71c57",backgroundPosition:'0 -53px'});
		$('.active_menu').children('a').children('span').css({color:'#FFFFFF',fontSize:'32px'}).css({fontWeight:'bold'});		
		$('.active_menu').children('ul').css('display','block');	
	}
	else
	{
		$('.prioritory_active').children('a').css({height:'53px',backgroundColor:"#f71c57",backgroundPosition:'0 -53px'});
		$('.prioritory_active').children('a').children('span').css({color:'#FFFFFF',fontSize:'32px'}).css({fontWeight:'bold'});		
		$('.prioritory_active').children('ul').css('display','block');		
	}
}
/***************************Gallery Home**************************************/
function initHomeGallery()
{
	//récupération du nombre de projet et leur taille
	nb_work = $('.one_work').length;
	width_work = parseInt($('.one_work').css('width'));
	$("#overflow_work").css('width',nb_work*width_work+"px");
	//pour chaque projet, on attribut un chiffre
	$('.one_work').each(function(i){$(this).attr('multiple',i);});
	//on créer les breadcrumbs
	width_bread = parseInt($('.nav_bar').css('width'))/nb_work;
	$(".nav_bar>div").css('width',width_bread+"px").fadeIn();
	//on désigne comme active la première real
	$('.one_work:first-child').addClass('active_work');
	//on lance le défilement automatique
	timer_transition_home = setInterval("slideAutoHome()", delay_transition_work);
	//mise en place des écouteurs
	if($('.one_work').length > 1)
	{
		$(".prev_work,.next_work").mousedown(function(event){event.preventDefault();});
		$(".prev_work,.next_work").css('cursor','pointer').click(slideManHome);	
		//gestion de l'entrée mouse enter sur les div concernées
		$("#works_home").mouseover(showControls);
		$("#header_home").mouseover(showControls);
		$("#header_home").mouseout(hideControls);
		$("#works_home").mouseout(hideControls);
		//gestion des boutons play/pause
		$("#play_btn").addClass('active');
		$("#controls_btn a").click(switchEnableSlideHome);
		$("#header_home>div").select(function(){return false;});
	}
}

function switchEnableSlideHome()
{
	$(this).addClass('active');
	if($(this).attr('id') == "play_btn")
	{
		clearInterval(timer_transition_home);
		$("#stop_btn").removeClass('active');
		timer_transition_home = setInterval("slideAutoHome()", delay_transition_work);
	}
	else
	{
		$("#play_btn").removeClass('active');
		clearInterval(timer_transition_home);
	}
	return false;
}

function showControls()
{
	$(this).children('.prev_work').show();
	$(this).children('.next_work').show();
	//$("#stop_btn").click();
}

function hideControls()
{
	$(this).children('.prev_work').hide();
	$(this).children('.next_work').hide();
	//$("#play_btn").click();
}

function slideAutoHome()
{
	//afficher les controleurs
	$(".around_span").css('visibility','visible');
	//on vérifie qu'il y a bien un next sinon on retourne au départ
	if($('.active_work').next().hasClass('one_work'))
	{
		var multiple = $('.active_work').next().attr('multiple');
		//on définis le nouvel active
		$('.active_work').removeClass('active_work').next().addClass('active_work');
		$("#overflow_work").animate({marginLeft:-multiple*width_work},500);
		//on change le chiffre
		$("#current_work").empty().html(parseInt(multiple)+1);
		
		//on déplace les breadcrumbs
		$(".nav_bar>div").animate({left:width_bread*multiple+"px"});
	}
	else
	{
		$('.active_work').removeClass('active_work');
		$('.one_work:first-child').addClass('active_work');
		$("#overflow_work").animate({marginLeft:0},500);
		$("#current_work").empty().html(1);
		
		//déplacement breadcrumbs
		$(".nav_bar>div").animate({left:"0px"});
	}
	
	//on verifie qu'il y a un prev.
	if($('.active_work').prev().hasClass('one_work'))
	{
		$('.prev_work').css({visibility:'visible'});
	}

	//on verifie qu'il y a un prev.
	if($('.active_work').next().hasClass('one_work'))
	{
		$('.next_work').css({visibility:'visible'});
	}
}

function slideManHome(event)
{
	$("#stop_btn").click();
	var width_to_use;
	if($(this).hasClass('prev_work'))
	{
		//vérification 
		var multiple = $('.active_work').prev().attr('multiple');
		if(multiple != null && multiple != "")
		{
			//récupération du nb multiple
			var nb_multiple = $('.active_work').removeClass('active_work').prev().addClass('active_work').attr('multiple');	
			width_to_use = nb_multiple*width_work;
			//on change le chiffre
			$("#current_work").empty().html(parseInt(nb_multiple)+1);
			//on regarde si on a un enfant encore avant. Sinon on désactive le btn
			if(!$('.active_work').prev().hasClass('one_work'))
			{
				$('.prev_work').css('visibility','hidden');
			}
			$('.next_work').css('visibility','visible');
		}
	}
	else
	{
		//vérification 
		var multiple = $('.active_work').next().attr('multiple');
		if(multiple != null && multiple != "")
		{
			//récupération du nb multiple
			var nb_multiple = $('.active_work').removeClass('active_work').next().addClass('active_work').attr('multiple');	
			width_to_use = nb_multiple*width_work;
			//on change le chiffre
			$("#current_work").empty().html(parseInt(nb_multiple)+1);
			//on regarde si on a un enfant encore après. Sinon on désactive le btn
			if(!$('.active_work').next().hasClass('one_work'))
			{
				$('.next_work').css('visibility','hidden');
			}
			$('.prev_work').css('visibility','visible');
		}		
	}
	
	//on déplace les breadcrumbs
	if($('.active_work').attr('multiple') == 0)
	{
		$(".nav_bar>div").animate({left:"0px"});		
	}
	else
	{
		$(".nav_bar>div").animate({left:width_bread*nb_multiple+"px"});
	}
	//on déplace
	$("#overflow_work").animate({marginLeft:-width_to_use+"px"},500);
	
	return false;
}

/***************************Agence**********************************************/
function initAgency()
{
	//konami
	konamiLaunch();
	//affichage du premier bloc si aucun sélectionné
	if(!selected_agency_part) setAgencyContent('team') ;
	
	//affichage du premier bloc de détail des compétences
	setSkillsPart($('.site_type_detail').first().attr('id').split('_').pop(), false) ;
	
	//intéraction compétences
	$('#skills .skills_list li').click(function()
			{ 
				setSkillsPart($(this).attr('id').split('_').pop(), true) ;
			}) ;
	
	//l'équipe
	$('#team_people li').each(function(){
		var li = $(this) ;
		var overlay = $('<div></div>').css({
			width:li.width()+'px',
			height:li.height()+'px',
			position:'absolute',
			top:0,
			left:0,
			'z-index':120
		}) ;
		li.append(overlay) ;
		overlay.bind({
			'mouseenter':function(){
				li.addClass('crazy') ;
			},
			'mouseleave':function(){
				li.removeClass('crazy') ;
			}
		}) ;
	}) ;
	//set du click sur le people_job
	$("#people_job>div").click(goToJob);
}

function goToJob()
{
	var href_link = $("#text_job .post_txt>a").attr('href');
	window.location.href = href_link;
	return false;
	
}

function setAgencyContent(part)
{
	if($("#overlay_wrap").length >0)
	{
		$("#access_plan_btn").click();
	}
	if(selected_agency_part)
	{
		if(part == selected_skills_part) return ;
		
		$('#'+selected_agency_part).slideUp() ;
		$('#accordion_'+selected_agency_part).css({overflow:'hidden',position:'relative'}).slideDown(function(){
			if(!$.browser.msie)
				$(this).css('overflow','visible');
			}) ;
		$('#'+selected_agency_part+'_cat').removeClass('active') ;
	}
	selected_agency_part = part ;
	$('#'+selected_agency_part).css({overflow:'hidden',position:'relative'}).slideDown(function(){
		if(!$.browser.msie)
			$(this).css('overflow','visible');
		}) ;
	$('#accordion_'+selected_agency_part).css({overflow:'hidden',position:'relative'}).slideUp(function(){
		if(!$.browser.msie)
			$(this).css('overflow','visible');
		}) ;
	$('#'+selected_agency_part+'_cat').addClass('active') ;
	
}
function setSkillsPart(part, animate)
{
	if(selected_skills_part)
	{
		if(part == selected_skills_part) return ;
		
		if(animate)
		{
			$('#site_type_detail_'+selected_skills_part).animate({
				left: '-376px',
				opacity:0
			}) ;
			$('#site_type_samples_'+selected_skills_part).animate({
				top: '-200px',
				opacity:0
			}) ;
		}
		else
		{
			$('#site_type_detail_'+selected_skills_part).hide() ;
			$('#site_type_samples_'+selected_skills_part).hide() ;
		}
		
		$('#site_type_'+selected_skills_part).first().removeClass('active') ;
	}

	selected_skills_part = part ;
	
	if(animate)
	{
		$('#site_type_detail_'+selected_skills_part)
		.css({
			left: '376px',
			opacity: 0
		})
		.show()
		.animate({
			left: '0px',
			opacity:1
		}) ;
		$('#site_type_samples_'+selected_skills_part)
		.css({
			top: '200px',
			opacity: 0
		})
		.show()
		.animate({
			top: '0px',
			opacity: 1
		});
	}
	else
	{
		$('#site_type_detail_'+selected_skills_part)
		.css({
			left: '0px',
			opacity: 1
		})
		.show() ;
		$('#site_type_samples_'+selected_skills_part)
		.css({
			top: '0px',
			opacity: 1
		})
		.show() ;
	}
	$('#site_type_'+selected_skills_part).first().addClass('active') ;
}
/***************************Gallery Mozaic**************************************/

//fonction initialisant l'application
function initWorksApp()
{
	//on met le loader en place
	$('#overlay_works').fadeTo(400,0.7);
	//on sauvegarde la mozaic générée par php
	if(jquery_object_mozaic_div == null || jquery_object_mozaic_div == "")
	{
		jquery_object_mozaic_div = $('#container_work_expose>div:first-child');
	}
	
	//on définie la taille du container de works
	//on prend par default nb_work_page car on veux simplement que la width soit
	//au moins aussi grande que la width totale de nombre d'enfant qu'elle a
	var width_parent_work = parseInt($('.work_expose').parent().css('width'));
	$("#container_work_expose").css('width',width_parent_work*nb_work_page+"px");
	//récupération de la width du container de la barre de navigation
	width_nav_bar_div = parseInt($(".nav_bar").css('width'));
	//on met en place les écouteurs
	$("#mozaic").click(setMozaicShell);
	$("#list").click(setListShell);
	$("#all").addClass('active');
	//on affiche les boutons de recherches
	$("#header_button").slideDown();
	//on met une opacité sur l'overlay
	$("#overlay_works").css('opacity','0.5');
	//on récupère la width du container
	height_container_page = parseInt($("#container_work_expose>div").css('height'));
	//en fonction de mozaic_active on lance la fonction
	if(mozaic_active)
	{
		$('#mozaic').addClass('active');
		initMozaicShell();
	}
	else
	{
		$('#list').addClass('active');
		initListShell();
	}
	if(window.location.hash == null || window.location.hash == "")
	{
		$.bbq.pushState('#!/all/toutes-nos-realisations.html');
	}
	return false;
}

//fonction gérant les hash passés et le chargement
function loadSearchController(ahref)
{
	//on active le bon bouton
	$('#right_button a').removeClass('active');
	id_to_active = ahref.replace('-','_');
	search_id = $("#"+id_to_active).addClass('active').attr('rel');
	//l'user demande toutes les réals
	if(search_id == null || search_id == "")
	{
		//on charge le content qu'on a besoin
		loadContentWorks(1,false);
		//on affiche le content
		showContentWork(content_ajax,true,false);			
	}
	//l'user demande la recherche
	else
	{
		//on load ce que l'utilisateur veux
		loadContentWorks(1,true,search_id);
		//on l'affiche
		showContentWork(content_ajax,true,true,1);
		//on move le content
		//moveContainerAndBread(1);
	}
}
//fonction gérant les content a récupérer
function loadWorkController(current_page)
{
	if(first_load)
	{
		return false;
	}
	//si on a déja loadé le content on fait bouger la page sinon on charge
	last_nb_page = current_page+1;
	if(!in_array(pagination_history,last_nb_page))
	{
		//stockage du num de page dans le tableau
		pagination_history.push(last_nb_page);
		//on charge le content demandé
		var id_to_load = $('#right_button .active').attr('rel');
		if(id_to_load != null && id_to_load != "")
		{
			//on charge le contenu
			loadContentWorks(last_nb_page,true,id_to_load);
			//on l'ajoute
			showContentWork(content_ajax,false,true,last_nb_page);
		}
		//sinon c'est les réalisations de tous qui sont demandées
		else
		{
			//on charge le contenu
			loadContentWorks(last_nb_page,false);
			//on l'ajoute
			showContentWork(content_ajax,false,false,last_nb_page);	
		}
		//on fait bouger le content
		moveContainerAndBread(last_nb_page);
	}
	else
	{
		moveContainerAndBread(last_nb_page);
	}
	return false;
}

//fonction initialisant la présentation en miniatures des réalisations
function initMozaicShell()
{
	//on affiche le loader
	$('#overlay_works').fadeTo(400,0.7);
	//on définis la breadcrumb
	width_to_bread_work = width_nav_bar_div/Math.ceil(nb_works/nb_work_page);
	$(".nav_bar>div").animate({width:width_to_bread_work+"px",marginLeft:'0px'});
	$(".nav_bar>div").fadeIn();	
	//on donne un left a chaque enfant de container_work_expose
	setParentOneWorkPosition();
	//si la première div n'a pas d'id on le définie
	first_id_div = $("#container_work_expose>div:first-child").attr('id');
	if(first_id_div != null || first_id_div != "")
	{
		var nb_page = $(".pagination .current").html();
		$("#container_work_expose>div:first-child").attr('id','id_1');	
	}
	//on cache l'overlay
	$("#overlay_works").fadeOut();
//	//on load ce que l'utilisateur veux
//	loadContentWorks(1,false);
//	//on l'affiche
//	showContentWork(content_ajax,true,false,1);
	return false;
}

//fonction initialisant la présentation en miniatures en liste
function initListShell()
{
	//on affiche le loader
	$('#overlay_works').fadeTo(400,0.7);
	//on définis la breadcrumb
	width_to_bread_work = width_nav_bar_div/Math.ceil(nb_works/nb_work_page);
	$(".nav_bar>div").animate({width:width_to_bread_work+"px",marginLeft:'0px'});
	$(".nav_bar>div").fadeIn();	
	//on donne un left a chaque enfant de container_work_expose
	setParentOneWorkPosition();
	//si la première div n'a pas d'id on le définie
	first_id_div = $("#container_work_expose>div:first-child").attr('id');
	if(first_id_div != null || first_id_div != "")
	{
		var nb_page = $(".pagination .current").html();
		$("#container_work_expose>div:first-child").attr('id','id_1');	
	}
	//on redimensionne le container
	$("#container_work_expose").animate({height:"550px"},400);
	//on cache l'overlay
	$("#overlay_works").fadeOut();
	//on load ce que l'utilisateur veux
//	loadContentWorks(1,false);
//	//on l'affiche
//	showContentWork(content_ajax,true,false,1);	
	return false;
}

//fonction remettant en place le shell au format mozaic
function setMozaicShell()
{
	//on passse en mode mozaic
	$("#list").removeClass('active');
	$("#mozaic").addClass('active');
	mozaic_active = 1;
	$("#container_work_expose").animate({height:height_container_page+"px"},400);
	//on recharge la derniere recherche
	$(window).trigger('hashchange');
	
	return false;
}

//fonction remettant en place le shell au format list
function setListShell()
{
	//on passe en mode list
	$("#mozaic").removeClass('active');
	$("#list").addClass('active');
	mozaic_active = 0;
	$("#container_work_expose").animate({height:"550px"},400);
	//on recharge la derniere recherche
	$(window).trigger('hashchange');
	
	return false;
}
//fonction initialisant la position des enfants de container_work_expose
function setParentOneWorkPosition()
{
	var width_parent_work = parseInt($('.work_expose').parent().css('width'));
	//on définie la taille des enfant suivant de container_work_expose
	$("#container_work_expose>div").each(function(e){$(this).css('left',width_parent_work*(e)+'px');});
	$("#container_work_expose>div").fadeIn();	
}

//fonction chargeant en ajax ce que l'utilisateur veux et retourne le contenu
//Param : nb_page int,searchLoad boolean,search_id int
function loadContentWorks(nb_page,searchLoad,search_id)
{
	//on regarde si nb_page_s est vide. Si oui on lui donne une valeur
	if(nb_page == null && nb_page == "")
	{
		nb_page = 1;
	}
	//on load ce que l'utilisateur souhaite. Si searchLoad = true alors ca vient
	//du moteur de recherche
	if(searchLoad)
	{
		var option_ajax = {nb_page:nb_page,search_id:search_id,mozaic:mozaic_active};
		$.ajax({type:"POST",async:false,url:'/ajax/getWorkSearch',data:option_ajax,success:function(data)
	    	{
			  	if(data.response)
		  		{
			  		content_ajax = data.works;
		  		}	 
			  	else
			  	{
			  		content_ajax = data.works;
			  	}
		  		nb_works_s = data.nb_works;
	    	}});		
	}
	else
	{
		if(first_load)
		{
			nb_page = 1;
		}
		var option_ajax = {nb_page:nb_page,mozaic:mozaic_active};
		$.ajax({type:"POST",async:false,url:'/ajax/getWorksList',data:option_ajax,success:function(data)
	    	{
				content_ajax =  data;
	    	}
	    });
	}
}

//fonction chargée d'afficher le contenu en fonction du type de shell utilisé
//elle gère également la width des breadcrumbs et de la pagination
function showContentWork(content_ajax,delete_content,searchLoad,nb_page)
{
	//on met le loader
	$("#overlay_works").fadeTo(400,0.7);
	//si le delete n'est pas définie on le met à false
	if(delete_content == "" || delete_content == null)
	{
		delete_content = false;
	}
	
	//si on récupère bien quelque chose on l'ajoute
	if(content_ajax != "" && content_ajax != null)
	{
		if(delete_content)
		{
			$("#container_work_expose").empty().css('marginLeft','0px');
			$('.pagination').empty();
			//on créer la pagination
			pagination_history = new Array();
			pagination_history.push(1);
			//config de la pagination en fonction du shell utilisé
			if(mozaic_active)
			{
				if(first_load)
				{
					option_pagination = {items_per_page:nb_work_page,current_page:session_page,prev_text:false,next_text:false,callback:loadWorkController};
					first_load = false;
				}
				else
				{
					option_pagination = {items_per_page:nb_work_page,prev_text:false,next_text:false,callback:loadWorkController};	
				}
									
			}
			else
			{
				if(first_load)
				{
					option_pagination = {items_per_page:nb_works_list,prev_text:false,next_text:false,callback:loadWorkController,current_page:session_page};
					first_load = false;	
				}
				else
				{
					option_pagination = {items_per_page:nb_works_list,prev_text:false,next_text:false,callback:loadWorkController};
				}
					
			}
			//on set la pagination
			if(searchLoad)
			{
				if(nb_works_s >0)
				{
					$(".pagination").pagination(nb_works_s,option_pagination);
					if(mozaic_active)
					{
						width_to_bread_work = width_nav_bar_div/Math.ceil(nb_works_s/nb_work_page);
					}
					else
					{
						width_to_bread_work = width_nav_bar_div/Math.ceil(nb_works_s/nb_works_list);
					}	
				}
				else
				{
					$('#right_button .active').click(function(){return false;}).css({textDecoration:'line-through'}).animate({opacity:0.5});
					width_to_bread_work = width_nav_bar_div;
				}
			}
			else
			{
				if(mozaic_active)
				{
					width_to_bread_work = width_nav_bar_div/Math.ceil(nb_works/nb_work_page);
				}
				else
				{
					width_to_bread_work = width_nav_bar_div/Math.ceil(nb_works/nb_works_list);
				}
				$(".pagination").pagination(nb_works,option_pagination);
			}
			//on redéfinis la breadcrumb
			$(".nav_bar>div").stop(true,true).animate({width:width_to_bread_work+"px",marginLeft:'0px'});
			$(".nav_bar>div").fadeIn();	
			
		}
		//on ajoute le contenu récupéré
		$("#container_work_expose").append(content_ajax);
		//on set les listeners si c'est mozaic
		if(mozaic_active)
		{
			$('#container_work_expose>div:last-child .work_expose').addClass('new_work');
			setListenerWork(mozaic_active);
		}
		else
		{
			$("#container_work_expose>div:last-child a").addClass('new_list_a');
			//on définit une width
			$('#container_work_expose>div').css('height','550px');
			//on définit des ecouteurs
			$('a.new_list_a').each
			(
				function()
				{
					$(this).click(
							function()
							{
							//on set la pagination en session
							var href_work = $(this).attr('href');
							$.post('/ajax/setPaginationNumber',{nb_page:last_nb_page},
									function()
									{
										window.location = href_work;
									}
							);
							return false;
							}
						);
					$(this).removeClass('new_list_a');
				}
			);
		}
		//on attribue une taille a ce nouveau content
		var width_work = parseInt($("#container_work_expose>div:last-child").css('width'));
		$("#container_work_expose>div:last-child").css('left',width_work*(nb_page-1)+'px');
		//on montre le contenu
		$('#container_work_expose>div:last-child').fadeIn();
	}
	else
	{

	}
	//on cache l'overlay
	$("#overlay_works").fadeOut();
}

//fonction chargée de faire bouger le container et la breadcrumb
function moveContainerAndBread(nb_page)
{
	$(".nav_bar>div").stop(true,true).animate({marginLeft:width_to_bread_work*(nb_page-1)});
	width_total = width_div*(nb_page-1)+"px";
	$("#container_work_expose").stop(true,true).animate({marginLeft:-width_div*(nb_page-1)});
}

//fonction définissant les écouteurs pour chaque shell
//Param : mozaic type boolean
function setListenerWork(mozaic)
{
	if(mozaic)
	{
		  $('.new_work').css('cursor','pointer').click(goToWork);
		  $(".new_work .btn_over").mouseenter(show_btn);
		  $(".new_work").mouseleave(hide_btn).removeClass('new_work'); 		  
	}
}

//fonction redigireant l'utilisateur vers la réalisation qu'il a cliqué
function goToWork()
{
	//on set la pagination en session
	var href_work = $(this).children('div').children('.title_work_expose').children('a').attr('href');
	$.post('/ajax/setPaginationNumber',{nb_page:last_nb_page},
			function()
			{	
				window.location = href_work;
			}
	);
	return false;
}

function show_btn()
{
	$(this).children('img').css('top','-135px');
	$(this).prev().css('display','inline');
}

function hide_btn()
{
	$(this).children('.work_img').children('a').children('img').css('top','0px');
	$(this).children('.work_img').children('.link_work').css('display','none');
}

function in_array(array_to_check,value_to_check)
{
  for(key in array_to_check)
  {
    if(array_to_check[key] == value_to_check)
    {
        return true;
    }
  }
  return false;
}

/**************************Gallery detail page********************************/
function initGallery()
{
	//récupération du nombre de miniatures && leur taille
	nb_pictures = $('.one_picture').length;
	width_picture = parseInt($('.one_picture').css('width'));
	$("#container_galleries").css('width',width_picture*nb_pictures+"px");
	//on définis la breadcrumb
	var width_nav_bar_div = parseInt($('.nav_bar').css('width'));
	width_to_bread_work = width_nav_bar_div/nb_pictures;
	$(".nav_bar>div").css('width',width_to_bread_work+"px");
	$(".nav_bar>div").fadeIn();
	//on définit le premier enfant
	$('.one_picture:first-child').addClass('active_picture');
	//on leur donne des multiplicateurs
	$('.one_picture').each(function(i){$(this).attr('multiple',i);});
	//on lance le défilement auto
	$(".next_pict").fadeIn();
	$('.prev_pict').css({display:'none',opacity:0});	
	//mise en place des écouteurs
	if($('.one_picture').length > 1)
	{
		$(".prev_pict,.next_pict").css({cursor:'pointer'}).click(slideManGallery);	
		//gestion de l'entrée mouse enter sur les div concernées
		$("#gallery").mouseover(showControlsPict);
		$("#gallery").mouseout(hideControlsPict);
		timer_transition_gallery = setInterval("slideAutoGallery()", delay_transition_pict);
	}
}

function slideAutoGallery()
{
	//on vérifie qu'il y a bien un next sinon on retourne au départ
	if($('.active_picture').next().hasClass('one_picture'))
	{
		var multiple = $('.active_picture').next().attr('multiple');
		//on définis le nouvel active
		$('.active_picture').removeClass('active_picture').next().addClass('active_picture');
		$("#container_galleries").animate({marginLeft:-multiple*width_picture+"px"},500);
		var width_bread = parseInt($('.nav_bar>div').css('width')); 
		//on déplace les breadcrumbs
		$(".nav_bar>div").animate({left:width_bread*multiple+"px"});
	}
	else
	{
		$('.active_picture').removeClass('active_picture');
		$('.one_picture:first-child').addClass('active_picture');
		$("#container_galleries").animate({marginLeft:0+"px"},500);		
		//déplacement breadcrumbs
		$(".nav_bar>div").animate({left:0+"px"});
	}	
	
	//on verifie qu'il y a un prev.
	if($('.active_picture').prev().hasClass('one_picture'))
	{
		$('.prev_pict').css('opacity',1);
	}

	//on verifie qu'il y a un prev.
	if($('.active_picture').next().hasClass('one_picture'))
	{
		$('.next_pict').css('opacity',1);
	}
}

function slideManGallery()
{
	clearInterval(timer_transition_gallery);
	var width_to_use;
	var width_bread = parseInt($('.nav_bar>div').css('width'));
	if($(this).hasClass('prev_pict'))
	{
		//vérification 
		var multiple = $('.active_picture').prev().attr('multiple');
		if(multiple != null && multiple != "")
		{
			//récupération du nb multiple
			var nb_multiple = $('.active_picture').removeClass('active_picture').prev().addClass('active_picture').attr('multiple');	
			width_to_use = nb_multiple*width_picture;
			//on regarde si on a un enfant encore avant. Sinon on désactive le btn
			if(!$('.active_picture').prev().hasClass('one_picture'))
			{
				$('.prev_pict').fadeTo(400,0,function(){$(this).css('display','none');});
			}
			$('.next_pict').fadeTo(400,1);
		}
	}
	else
	{
		//vérification 
		var multiple = $('.active_picture').next().attr('multiple');
		if(multiple != null && multiple != "")
		{
			//récupération du nb multiple
			var nb_multiple = $('.active_picture').removeClass('active_picture').next().addClass('active_picture').attr('multiple');	
			width_to_use = nb_multiple*width_picture;
			//on regarde si on a un enfant encore après. Sinon on désactive le btn
			if(!$('.active_picture').next().hasClass('one_picture'))
			{
				$('.next_pict').fadeTo(400,0,function(){$(this).css('display','none');});
			}
			$('.prev_pict').fadeTo(400,1);
		}		
	}
	
	//on déplace les breadcrumbs
	if($('.active_picture').attr('multiple') == 0)
	{
		$(".nav_bar>div").animate({left:"0px"});		
	}
	else
	{
		$(".nav_bar>div").animate({left:width_bread*nb_multiple+"px"});
	}
	//on déplace
	$("#container_galleries").animate({marginLeft:-width_to_use+"px"},500);
	
	return false;
}

function showControlsPict()
{
	$(this).children('.next_pict').show();
	$(this).children('.prev_pict').show();
	clearInterval(timer_transition_gallery);
}

function hideControlsPict()
{
	clearInterval(timer_transition_gallery) ; 
	$(this).children('.prev_pict').hide();
	$(this).children('.next_pict').hide();
	timer_transition_gallery = setInterval("slideAutoGallery()", delay_transition_pict);
}
/**************************************Sitemap**************************************************************/
function initSiteMap()
{
	$('#sitemap li ul').slideUp();
	$('#sitemap>li:has(ul)>a').click(showSubMenu);
}

function showSubMenu()
{
	if($(this).parent().children('ul').hasClass('active_menu'))
	{
		$(this).parent().children('ul').removeClass('active_menu').slideUp();
	}
	else
	{
		$('.active_menu').removeClass('active_menu').slideUp();
		$(this).parent().children('ul').addClass('active_menu').slideDown();	
	}
	return false;
}

function konamiLaunch()
{
	var konami = new Konami();
	konami.code =function(){$("#team_people li").addClass('crazy');};
	konami.load();
}
/**************************************Jobs*****************************************************************/
function initJobs()
{
	var hash = window.location.hash;
	if(hash != null && hash != "") return ;
	setJobContent('trainee-webdesigner');
}

function showJob()
{
//	//on affiche remontre le lien caché
//	$('.accordion_title[job=active]').next().slideUp();
//	$('.accordion_title[job=active]').removeAttr('job').slideDown();
//	//activation du job
//	$(this).attr('job','active').slideUp();
//	$(this).next().slideDown();
//	return false;
}

function setJobContent(part)
{
	if(part == null || part == "") return ;
	
	//on affiche la bonne category
	$('.accordion_title[job=active]').next().slideUp();
	$('.accordion_title[job=active]').removeAttr('job').slideDown();
	$('.accordion_title').next(':not(#'+part+')').slideUp();
	$('#'+part).stop(true,true).slideDown().attr('job','active');
	$('#'+part).prev().attr('job','active').slideUp();
}
