// variables
var animtime=1000;
var animtimefast=200;
var projetactup=2;
var projetact=1;
var menuact=0;
//chargement images hover
i1 = new Image;
i1.src = "images/flechehaut2.gif";
i2 = new Image;
i2.src = "images/flechebas2.gif";
// changements de pages
function clickMenu(rubrique, id){
    $("div#accueil").animate({marginTop:"-"+(470*id)+"px"}, animtime);
	$("img#menu"+id).animate({opacity:1}, animtime);
	for(var i=0; i<4; i++){
		if(i!=id){
			$("img#menu"+i).animate({opacity:0.6}, animtime);
		}
	}
	menuact=id;
	window.location.hash='page='+rubrique;
}
function overMenu(id){
	if(id!=menuact){
		$("img#menu"+id).animate({opacity:0.8}, animtimefast);
	}
}
function outMenu(id){
	if(id!=menuact){
		$("img#menu"+id).animate({opacity:0.6}, animtimefast);
	}
}
function placePage(){
	var pagetemp=window.location.hash;
	window.location.hash="#accueil";
	if(pagetemp.substring(0, 5)=="#page")
		var pagearrivee=pagetemp.substring(6);
	else
		var pagearrivee=pagetemp.substring(1);
	var pagearriveesecondaire="";
	var indexofand=pagearrivee.indexOf('&', 0);
	if(indexofand!=-1){
		pagearrivee=pagearrivee.substring(0, pagearrivee.indexOf('&', 0));
	}
	if(pagearrivee==""){
		pagearrivee="accueil";
	}
	var idpagearrivee=0;
	if(pagearrivee=='services')
		idpagearrivee=1;
	if(pagearrivee=='portfolio')
		idpagearrivee=2;
	if(pagearrivee=='contact')
		idpagearrivee=3;
	if(pagearrivee=='mentions')
		idpagearrivee=4;
	if(pagearrivee=='merci')
		idpagearrivee=5;
	window.location.hash='page=accueil';
	clickMenu(pagearrivee, idpagearrivee);
}

//accueil
function overNews(id){
	$('img#imagenews'+id).animate({opacity:0.2}, animtimefast);
	$('div#contenunews'+id).animate({opacity:1}, animtimefast);
}

function outNews(id){
	$('div#contenunews'+id).animate({opacity:0}, animtimefast);
	$('img#imagenews'+id).animate({opacity:1}, animtimefast);
}

//services
function clickVousEtes(id){
	if(id==2){
		$("div#vousetes1").animate({marginTop:"-470px"}, animtime);
	}
	else {
		$("div#vousetes1").animate({marginTop:"-940px"}, animtime);
	}
}

//portfolio
function clickProjet(projet, id){
	$("div#grandProjet1").animate({marginTop:"-"+(470*(id-1))+"px"}, animtime);
	if(id!=projetact){
		document.getElementById('imgpetitProjet'+projetact).style.borderColor='#ffffff';
	}
	projetact=id;
	window.location.hash='page=portfolio&projet='+projet;
}

function overProjet(id){
	document.getElementById('imgpetitProjet'+id).style.borderColor='#000000';
}

function outProjet(id){
	if(id!=projetact){
		document.getElementById('imgpetitProjet'+id).style.borderColor='#ffffff';
	}
}

function monter(){
	if(projetactup>1){
		projetactup--;
		$("div#petitProjet1").animate({marginTop:"-"+((projetactup-1)*112)+"px"}, animtimefast);
		if(projetactup==1){
			$("img#flechehaut").animate({opacity:0}, animtimefast);
		}
		else{
			$("img#flechebas").animate({opacity:1}, animtimefast);
		}
	}
}

function descendre(maximum){
	if(projetactup+4<=maximum){
		$("div#petitProjet1").animate({marginTop:"-"+(projetactup*112)+"px"}, animtimefast);
		projetactup++;
		if(projetactup+3==maximum){
			$("img#flechebas").animate({opacity:0}, animtimefast);
		}
		else{
			$("img#flechehaut").animate({opacity:1}, animtimefast);
		}
	}
}

function overflechehaut(){
	document.getElementById('flechehaut').src="images/flechehaut2.gif";
}

function outflechehaut(){
	document.getElementById('flechehaut').src="images/flechehaut1.gif";
}

function overflechebas(){
	document.getElementById('flechebas').src="images/flechebas2.gif";
}

function outflechebas(){
	document.getElementById('flechebas').src="images/flechebas1.gif";
}

//contact
function ecrireadresse(){
	var name = "kevin" ;
	var domain = "bougetonweb.com" ;
	document.getElementById('adressemail').innerHTML='<a href="mailto:'+name+'@'+ domain+'">'+name+'@'+ domain+'</a>';
}

function verifInput(nom){
	var argact=document.getElementById(nom);
	if(argact.value=='Champ obligatoire'){
		argact.value='';
		argact.style.backgroundColor="#666666";
	}
	return false;
}

function validerContact()
{
	var form = document.formContact;
	var valid = 1;
	var message = '';
	for(var i=0; i<arguments.length; i++){
		var argact=document.getElementById(arguments[i]);
		if(argact.value == '' || argact.value == 'Champ obligatoire')
		{
			argact.style.backgroundColor="#000000";
			argact.value="Champ obligatoire";
			valid = 0;
		}
	}
	
	if(valid==1){
		return true;
	}
	else {
		return false;
	}
}

//facebook
function overFacebook(){
	$("img#facebookbulle").animate({top:"-50px", opacity:1}, animtimefast);
}

function outFacebook(){
	$("img#facebookbulle").animate({top:"-43px", opacity:0}, animtimefast);
}


//chargement page
$(document).ready(function(){
	outFacebook();
	outNews(1);
	outNews(2);
	outNews(3);
	monter();
	overProjet(1);
	placePage();
	ecrireadresse();
});
