// JavaScript Document
var current_slide=1;
var lecture_slide=true;
var le_focus="";
var id_en_cours="";
var survol="";

var nom_page = window.location.pathname;
nom_page = nom_page.split("/");
nom_page = nom_page[nom_page.length - 1];
//alert(nom_page);

function goTo(ancre){
	//$(ancre).offset().top;
	$("html,body").animate({scrollTop: $(ancre).offset().top},500,'easeInSine',function(){
		if(ancre != 'body')
			window.location.hash = ancre;
		else
			window.location.hash = '#';
		$(ancre).attr('tabindex','-1');
		$(ancre).focus();
		$(ancre).removeAttr('tabindex');
	});
}

function goto_slide(num_slide){
	pause();
	document.getElementById('bt_slide_'+current_slide).className="bt_slide";
	$('#slide'+current_slide).animate({marginTop: '-410px'}, 1000);
	current_slide=num_slide;
	document.getElementById('bt_slide_'+current_slide).className="bt_slide_actif";
	var new_margin=(current_slide-1)*100;
	$('#all_slides').animate({marginLeft: -new_margin+'%'}, 1000);
	$('#slide'+current_slide).animate({marginTop: '0px'}, 1500);
}

function slide_auto(){
	if(lecture_slide==true){
		document.getElementById('bt_slide_'+current_slide).className="bt_slide";
		$('#slide'+current_slide).animate({marginTop: '-410px'}, 1000);
		if(current_slide==max_slide){
			current_slide=1;
		}else{
			current_slide++;
		}
		document.getElementById('bt_slide_'+current_slide).className="bt_slide_actif";
		var new_margin=(current_slide-1)*100;
		$('#all_slides').animate({marginLeft: -new_margin+'%'}, 1000);
		$('#slide'+current_slide).animate({marginTop: '0px'}, 1500, function(){
			setTimeout("slide_auto()",5000);
		});	
	}
}
function pause(){
	lecture_slide=false;
}

$(document).ready(function() {
	var largeur_ecran=window.innerWidth;
	var hauteur_ecran=window.innerHeight;
	
	$('body').click(function(){	
		if(survol!=id_en_cours){
		$('#propo_'+id_en_cours).slideUp(100,function(){
			id_en_cours="";
		});	
		}
	});
	if(nom_page.substr(0,10)=="reference-"){
		$("html,body").animate({scrollTop: 455},500,'easeInSine');
	}
	$(window).scroll(function () { 
		//alert(document.documentElement.scrollTop);
		if(nom_page=="creation-site-internet.php"){
			if(document.documentElement.scrollTop>=645 && document.documentElement.scrollTop<1430){
				document.getElementById('sous_menu_creation').className='sous_menu_creation_fixed';
				document.getElementById('sous_menu_creation').style.marginTop="";
			}else if(document.documentElement.scrollTop>=1430){
				document.getElementById('sous_menu_creation').className='sous_menu_creation_float';
				document.getElementById('sous_menu_creation').style.marginTop=(document.getElementById('col2_accueil').offsetHeight-document.getElementById('sous_menu_creation').offsetHeight-50)+"px";
			}else{
				document.getElementById('sous_menu_creation').className='sous_menu_creation_float';
				document.getElementById('sous_menu_creation').style.marginTop="";
			}
		}
	});
	$(".lien_menu").hover(function(){
		//alert($(this).attr("rel"));
		$($(this).children()[0]).animate({marginTop: '0px', opacity:'1'}, 300);
		$($(this).children()[1]).animate({opacity:'0'}, 300);
		$($("#trait_"+$(this).attr("rel")).children()[0]).animate({width:'100%'}, 300);
	}, function(){
		$($(this).children()[0]).animate({marginTop: '-45px', opacity:'0'}, 300);
		$($(this).children()[1]).animate({opacity:'1'}, 300);
		$($("#trait_"+$(this).attr("rel")).children()[0]).animate({width:'0'}, 300);
	});
	$("a.box_photo").click(function(){
		
		function enleve_box(){
			$(img).fadeOut(100,function(){
				$('#box_photo').animate({width:"280px", height:"130px", marginLeft:"-150px", marginTop:"-75px"},300);
				$('#overlay').fadeOut(300);
				$('#box_photo').fadeOut(300,function(){
					$(img).remove();
					document.getElementById('loader_img').style.display='';
				});
			});
		}
		
		var url_photo_g=this;
		$('#overlay').fadeIn(200);
		$('#box_photo').fadeIn(300);
		var img = new Image();
		$(img)

		.load(function () {
		  $(this).hide();
		  if(img.width>largeur_ecran-150){
			  img.height=(img.height*(largeur_ecran-150))/img.width;
			  img.width=largeur_ecran-150
		  }
		  if(img.height>hauteur_ecran-150){
			  img.width=(img.width*(hauteur_ecran-150))/img.height;
			  img.height=hauteur_ecran-150
		  }
		  $('#box_photo').append(this);
		  document.getElementById('loader_img').style.display='none';
		  $('#box_photo').animate({width:(img.width)+"px", height:(img.height)+"px", marginLeft:"-"+((img.width+10)/2)+"px", marginTop:"-"+((img.height+10)/2)+"px"},300, function(){
			  $(img).fadeIn();
			  img.style.cursor='pointer';
			  $('#box_photo').click(function(){
				  enleve_box();
			  });
			  $('#overlay').click(function(){
				  enleve_box();
			  });
		  }); 
		})
		
		.error(function () {
		  // notify the user that the image could not be loaded
		})
		.attr('src', url_photo_g);
		return false;
	});
});

function enroule_deroule(id) {	

	if(id_en_cours!=id){
		anim=true;
		$('#propo_'+id).slideDown(150,function(){
			anim=false;
			id_en_cours=id;
		});	
	}else if(id_en_cours==id){
		anim=true;
		$('#propo_'+id).slideUp(150,function(){
			anim=false;
			id_en_cours="";
		});	
	}
	
}


function affiche_footer_contact(){
	if(document.getElementById('contenu_footer_contact').style.display=='none'){
		document.getElementById('overlay').style.zIndex='20';
		document.getElementById('bt_contact_footer').style.backgroundPosition='bottom';
		$('#overlay').fadeIn(500);
		$('#contenu_footer_contact').slideDown(500);
		$('#ombre_bt_footer').animate({marginBottom:"-12px"},500);
		$('#bt_contact_footer').animate({marginBottom:"386px"},500);
		$('#bt_facebook_footer').animate({marginBottom:"-65px"},500);
	}else{
		document.getElementById('overlay').style.zIndex='50';
		document.getElementById('bt_contact_footer').style.backgroundPosition='top';
		$('#overlay').fadeOut(500);
		$('#contenu_footer_contact').slideUp(500);
		$('#ombre_bt_footer').animate({marginBottom:"51px"},500);
		$('#bt_contact_footer').animate({marginBottom:"0px"},500);
		$('#bt_facebook_footer').animate({marginBottom:"0px"},500);
	}
}
function affiche_footer_facebook(){
	if(document.getElementById('facebook_footer').style.display=='none'){
		document.getElementById('overlay').style.zIndex='20';
		document.getElementById('bt_facebook_footer').style.backgroundPosition='bottom';
		$('#overlay').fadeIn(500);
		$('#facebook_footer').slideDown(500);
		$('#ombre_bt_footer').animate({marginBottom:"-12px"},500);
		$('#bt_contact_footer').animate({marginBottom:"-65px"},500);
		$('#bt_facebook_footer').animate({marginBottom:"495px"},500);
	}else{
		document.getElementById('overlay').style.zIndex='50';
		document.getElementById('bt_facebook_footer').style.backgroundPosition='top';
		$('#overlay').fadeOut(500);
		$('#facebook_footer').slideUp(500);
		$('#ombre_bt_footer').animate({marginBottom:"51px"},500);
		$('#bt_contact_footer').animate({marginBottom:"0px"},500);
		$('#bt_facebook_footer').animate({marginBottom:"0px"},500);
	}
}

function afficher_alert(message, focus_exit){
	document.getElementById('message_alert').innerHTML=message;
	if(document.getElementById('facebook_footer').style.display=='none' && document.getElementById('contenu_footer_contact').style.display=='none'){
		$('#overlay').fadeIn(200);
	}else{
		document.getElementById('overlay').style.zIndex='50';
	}
	$('#div_alert').fadeIn(300);
	if(focus_exit!=null){
		le_focus=focus_exit;
	}
}

function masque_alert(){
	document.getElementById('message_alert').innerHTML="";
	if(document.getElementById('facebook_footer').style.display=='none' && document.getElementById('contenu_footer_contact').style.display=='none'){
		$('#overlay').fadeOut(300);
	}else{
		document.getElementById('overlay').style.zIndex='20';
	}
	$('#div_alert').fadeOut(200);	
	if(le_focus!=""){
		le_focus.focus();
		le_focus="";
	}
}

function app_ref(){
	for(i=1;i<=nb_ref_en_cours;i++){
		var time_app=i*100;
		$('#ref_'+i).fadeIn(time_app);	
	}
}

