// JavaScript Document
//Settings
//gallery change photo interval(milliseconds)
var photoChangeInterval = 5000;
//gallery thyumb bar speed (miliseconds)
var thumbsSpeed = 5;
//----------------------------------------------------------------------------------------
//display swf object in specified parent div
function displayFlash(parentDiv,flashFile,imgFile,width,height)
{
	if(flashFile!="upload/banners/")
	{
		//display flash file
		var so = new SWFObject(flashFile, "", width, height, "8", "#000000");
		so.addParam("wmode","transparent");
		so.write(parentDiv);
		//if no flash installed display image file
		if(document.getElementById(parentDiv).innerHTML=="")
			document.getElementById(parentDiv).innerHTML = "<img src='"+imgFile+"' alt=''/>";
	}
	else
	{
		if(document.getElementById(parentDiv).innerHTML=="")
			document.getElementById(parentDiv).innerHTML = "<img src='"+imgFile+"' alt=''/>";
	}
}

//onclick banner - submit banner form
function bannerClick()
{
	document.getElementById('form_banner').submit();
}

//PHOTO GALLERY
//change big photo at given interval
var crtPhoto = 0;
function slideShow()
{
	if(document.getElementById("div_big_photo")!=null)
	{
		//if home page
		crtPhoto++;
		//reset if last photo is reached
		if(document.getElementById("hidden_photo"+crtPhoto)==null)
			crtPhoto=0;
		//get new photo from hidden
		newImage = document.getElementById("hidden_photo"+crtPhoto).value;
		//set new photo
		document.getElementById("div_big_photo").style.backgroundImage="url(upload/gallery/354x405/"+newImage+")";
		//go to next photo after given delay
		setTimeout('slideShow()',photoChangeInterval);
	}
}

//onclick thumb display big photo
function changePhoto(no)
{
	//get clicked photo
	newImage = document.getElementById("hidden_photo"+no).value;
	//set current photo to clicked photo for slideshow
	crtPhoto = no;
	//set new big photo
	document.getElementById("div_big_photo").style.backgroundImage="url(upload/gallery/354x405/"+newImage+")";
}

//initial values for gallery
var crtThumbPos = 0;
var crtTimeout;

//move thumbs bar left (dir=0) or right(dir=1) onmouseover
function moveThumbs(dir)
{
	if(document.getElementById("div_big_photo")!=null)
	{
		//home page
		movingThumbs = true;
		if(dir==0)
		{
			//left button
			if (crtThumbPos!=0) //test limit
			{
				//move right
				crtThumbPos++;
				newMg = crtThumbPos+"px";
				document.getElementById("div_move").style.marginLeft = newMg;
				crtTimeout = setTimeout('moveThumbs(0)',thumbsSpeed);
			}
		}
		else
		{
			//right button
			divWidth = document.getElementById("div_move").offsetWidth;
			limitR = divWidth-318;
			if(Math.abs(crtThumbPos)!=limitR) //test limit
			{
				//move left
				crtThumbPos--;
				newMg = crtThumbPos+"px";
				document.getElementById("div_move").style.marginLeft = newMg;
				crtTimeout = setTimeout('moveThumbs(1)',thumbsSpeed);
			}
		}
	}
}

//stop thumbs moving onmouseout
function stopThumbs()
{
	//stop moving
	clearTimeout(crtTimeout);
}
var crtOver = 0;
//mouse over function for menu
function menuMouseOver(no,page)	
{
	if(crtOver!=0)
	{
		document.getElementById("hidden_submenu"+crtOver).style.display = 'none';
		document.getElementById("img_menu"+crtOver).src = 'images/menu_'+crtOver+'.jpg';
		document.getElementById("hidden_submenu"+crtOver).style.visibility = 'hidden';
	}
	if(no!=page)
	{
		crtOver = no;
		document.getElementById("div_submenu").style.display = 'none';
		document.getElementById("hidden_submenu"+no).style.display = 'block';
		document.getElementById("img_menu"+no).src = 'images/menu_'+no+'_sel.jpg';
		document.getElementById("div_submenu").style.visibility = 'hidden';
		document.getElementById("hidden_submenu"+no).style.visibility = 'visible';
	}
	else
	{
		crtOver = 0;
		document.getElementById("div_submenu").style.display = 'block';
		document.getElementById("div_submenu").style.visibility = 'visible';
	}
}
function menuMouseOut()
{
//	document.getElementById("div_submenu").style.display = 'block';
//	document.getElementById("hidden_submenu"+crtOver).style.display = 'none';
}
function submenuMouseOver()
{
	if(crtOver!=0)
	{
		document.getElementById("div_submenu").style.display = 'none';
		document.getElementById("hidden_submenu"+crtOver).style.display = 'block';
		document.getElementById("img_menu"+crtOver).src = 'images/menu_'+crtOver+'_sel.jpg';
		document.getElementById("div_submenu").style.visibility = 'hidden';
		document.getElementById("hidden_submenu"+crtOver).style.visibility = 'visible';
	}	
}
function submenuMouseOut()
{
	document.getElementById("div_submenu").style.display = 'block';
	document.getElementById("div_submenu").style.visibility = 'visible';
	if(crtOver!=0)
	{
		document.getElementById("hidden_submenu"+crtOver).style.display = 'none';
		document.getElementById("img_menu"+crtOver).src = 'images/menu_'+crtOver+'.jpg';
		document.getElementById("hidden_submenu"+crtOver).style.visibility = 'visible';
	}
}
function genMouseOver()
{
	crtOver = 0;	
}
//validates an email address
function check_mail(str) 
{
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1)
	   return false
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
	   return false
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
		return false
	 if (str.indexOf(at,(lat+1))!=-1)
		return false
	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
		return false
	 if (str.indexOf(dot,(lat+2))==-1)
		return false
	 if (str.indexOf(" ")!=-1)
		return false
	 return true					
}
function validate_subscribe()
{
	var mail = document.getElementById("input_mail").value;
	var error = document.getElementById("div_error");
	if(mail=="")
	{
		error.style.display = "block";
		error.innerHTML = "Le champ E-mail est obligatoire!";
		return false;
	}
	if(check_mail(mail)==false)
	{
		error.style.display = "block";
		error.innerHTML = "Le champ E-mail n'est pas valide!";
		return false;
	}
	return true;
}
function submitSubscribe(act)
{
	if(validate_subscribe()==true)
	{
		document.getElementById('hidden_action').value = act;
		document.getElementById('form_subscribe').submit();
	}
}