// JavaScript Document
var d = document;
function h_b(sens)
{
d.getElementById('cadre').scrollTop = d.getElementById('cadre').scrollTop+(parseInt(sens));
}
function defilement()
{
d.getElementById('btn_haut').onmouseover = function(){ delai = setInterval('h_b("-20")',100); this.src = 'img/flecheh_on.png'; }
d.getElementById('btn_haut').onmouseout  = function(){ clearInterval(delai); this.src = 'img/flecheh_off.png'; }
d.getElementById('btn_bas').onmouseover  = function(){ delai2 = setInterval('h_b("20")',100); this.src = 'img/flecheb_on.png'; }
d.getElementById('btn_bas').onmouseout   = function(){ clearInterval(delai2); this.src = 'img/flecheb_off.png'; }
}
function prechargementImages()
{
var tab = Array('chargement.gif','btn_accueil_on.png','btn_biographie_on.png','btn_actualites_on.png','btn_peintures_on.png','btn_dessins_on.png','btn_expos_on.png','btn_contact_on.png','btn_envoyer_on.png','flecheh_on.png','flecheb_on.png');
	
for(i = 0; i<tab.length; i++)
	{
	var img = new Image;
	img.src = 'img/'+tab[i];
	}
}
function rolloverMenu()
{
var menu = d.getElementById('menu').getElementsByTagName('img');

for(i = 0; i<menu.length; i++)
	{
	menu[i].onmouseover = function(){ this.src = 'img/'+this.id+'_on.png'; }
	menu[i].onmouseout  = function(){ this.src = 'img/'+this.id+'_off.png'; }
	}
}
function VerificationEmail(elm)
{
if (elm.value.indexOf("@") != "-1" &&
    elm.value.indexOf(".") != "-1" &&
    elm.value != "")
    return true;
else return false;
}
function espacesVides(champ)
{
obj        = d.getElementById(champ);
chaine     = obj.value;
lg         = chaine.length;
newChaine  = '';

for(i=0; i<lg; i++)
	{
	newChaine += chaine.substr(i,1).replace(' ','');
	}
			
	if(newChaine ==''){
		return false;
	}
}
function verifFormulaire()
{
if(d.getElementById('formcontact'))
	{
	d.getElementById('formcontact').onsubmit = function() { 
	
	if(espacesVides('nom')==false)  {
   alert("Veuillez entrer un nom.");
   d.forms[0].nom.focus();
   return false;
 }
if(espacesVides('prenom')==false)  {
   alert("Veuillez entrer un prénom.");
   d.forms[0].prenom.focus();
   return false;
 }
if (!VerificationEmail(document.forms[0].email)){
	alert("Veuillez entrer un email valide.");
	d.forms[0].email.focus();
	return false;
  	}
if(espacesVides('chiffres')==false)  {
   alert("Veuillez entrer les 5 chiffres.");
   d.forms[0].chiffres.focus();
   return false;
 	}
 if(espacesVides('message')==false)  {
   alert("Veuillez écrire un message.");
   d.forms[0].message.focus();
   return false;
 	}
		}
	}
}
function changementCouleurChamp()
{
if(d.getElementById('formcontact'))
	{
	var tab_champs = Array('nom','prenom','email','chiffres','message');

	for(i = 0; i < 5; i++)
		{
		d.getElementById(tab_champs[i]).onfocus = function(){ this.style.backgroundColor = '#CCCCCC'; }
		d.getElementById(tab_champs[i]).onblur  = function(){ this.style.backgroundColor = '#F2F2F2'; }
		}
	}
}
function opaciteImages()
{
	if(d.getElementById('tableau_photos'))
	{
	var tab = d.getElementById('tableau_photos').getElementsByTagName('img');
	for(i=0; i<tab.length; i++)
		{
		tab[i].onmouseover = function(){ this.className = 'opacite'; }
		tab[i].onmouseout  = function(){ this.className = ''; }
		}
	}
}
function popup()
{ 
if(d.getElementById('detail_oeuvre'))
	{ 
	var lien = d.getElementById('detail_oeuvre').getElementsByTagName('a'); 
	lien[0].onclick = function(){ this.target = '_blank'; }
	}
}
function portrait()
{
if(d.getElementById('portrait'))
	{
		var portrait = d.getElementById('portrait')
		var h = (screen.height/2)-218;
		var l = (screen.width/2)-150;
	portrait.onclick = function()
		{
		window.open('portrait.html');
		}
	}
}
function rolloverBoutonEnvoyer()
{
	if(d.getElementById('bouton_envoyer'))
		{
		d.getElementById('bouton_envoyer').onmouseover = function() { this.src = 'img/btn_envoyer_on.png';  }
		d.getElementById('bouton_envoyer').onmouseout  = function() { this.src = 'img/btn_envoyer_off.png'; }
		}
}
function centrageOeuvre()
{
	if(d.getElementById('tableau_detail'))
	{
	var hauteur = d.getElementById('tableau_detail').offsetHeight;
	var difference = 430-hauteur; 

	d.getElementById('tableau_detail').style.marginTop = (Math.ceil(difference/2))+'px';
	}
}
function visible()
{
d.getElementById('tableau_photos').style.visibility = 'visible';
}
function chargement()
{
if(d.getElementById('tableau_photos'))
	{
	setTimeout('visible()',1000);
	}
}
function retour_galerie()
{
	if(d.getElementById('detail_oeuvre'))
		{
		switch(d.referrer)
			{
			case 'http://www.ericancey.com/peintures/' : btn = d.getElementById('menu').getElementsByTagName('a')[2]; break;
			case 'http://www.ericancey.com/dessins/'   : btn = d.getElementById('menu').getElementsByTagName('a')[3]; break;
			}
			btn.onclick = function()
				{
				var id = d.getElementById('detail_oeuvre').getElementsByTagName('img')[0].id;
				var pos = d.location.href.split('#');
				this.href = d.referrer+'#'+pos[1];
				}
		}		
}
function ajustement_defilement()
{
	if(d.location.href.search('#')> -1)
		{
		var idt = d.location.href.split('#');
		d.getElementById('cadre').scrollTop = idt[1];
		}
}
function passage_position_scroll()
{
	if(d.getElementById('tableau_photos'))
		{
		var liens = d.getElementById('tableau_photos').getElementsByTagName('a');
		for(i = 0; i < liens.length; i++)
			{
			liens[i].onclick = function()
				{
				this.href = this.href+'#'+d.getElementById('cadre').scrollTop;
				}
			}
		}
}
function init()
{
	//chargement();
	passage_position_scroll();
	changementCouleurChamp();
	centrageOeuvre();
	prechargementImages();
	popup();
	opaciteImages();
	rolloverMenu();
	retour_galerie();
	ajustement_defilement();
	defilement();
	verifFormulaire();
	rolloverBoutonEnvoyer();
	portrait();
	
}