function initOnLoad()
{
	//initCountdown();
	initMenuInteraction();
	searchBlankLinks();
}

function initMenuInteraction()
{
	var isSubMenuInterventionsDeployed;
	var isSubMenuEn2007Deployed;
	var isSubMenuEn2008Deployed;
	var isSubMenuEn2009Deployed;
	var isSubMenuEn2010Deployed;
	
	switch(rub)
	{
		case "accueil" :
			isSubMenuInterventionsDeployed = false;
			isSubMenuEn2007Deployed = false;
			isSubMenuEn2008Deployed = false;
			isSubMenuEn2009Deployed = false;
			isSubMenuEn2010Deployed = false;			
		break;
		case "interventions" :
			isSubMenuInterventionsDeployed = true;
			isSubMenuEn2007Deployed = false;
			isSubMenuEn2008Deployed = false;
			isSubMenuEn2009Deployed = false;
			isSubMenuEn2010Deployed = false;
		break;
		case "en2007" :
		    isSubMenuInterventionsDeployed = false;
		    isSubMenuEn2007Deployed = true;
		    isSubMenuEn2008Deployed = false;
		    isSubMenuEn2009Deployed = false;
			isSubMenuEn2010Deployed = false;
		break;
		case "en2008" :
		    isSubMenuInterventionsDeployed = false;
		    isSubMenuEn2007Deployed = false;
		    isSubMenuEn2008Deployed = true;
		    isSubMenuEn2009Deployed = false;
			isSubMenuEn2010Deployed = false;
		break;
		case "en2009" :
		    isSubMenuInterventionsDeployed = false;
		    isSubMenuEn2007Deployed = false;
		    isSubMenuEn2008Deployed = false;
		    isSubMenuEn2009Deployed = true;
			isSubMenuEn2010Deployed = false;
		break;	
		case "en2010" :
		    isSubMenuInterventionsDeployed = false;
		    isSubMenuEn2007Deployed = false;
		    isSubMenuEn2008Deployed = false;
		    isSubMenuEn2009Deployed = false;
			isSubMenuEn2010Deployed = true;
		break;			
	}
	menuAnimationAction(rub, isSubMenuInterventionsDeployed);
	menuAnimationAction2(rub, isSubMenuEn2007Deployed);
	menuAnimationAction3(rub, isSubMenuEn2008Deployed);
	menuAnimationAction4(rub, isSubMenuEn2009Deployed);
	menuAnimationAction5(rub, isSubMenuEn2010Deployed);
}

function menuAnimationAction(rub, isSubMenuInterventionsDeployed)
{
	var interventionsTitle = this.document.getElementById('interventionsTitle');
	
	if(isSubMenuInterventionsDeployed)
	{
		interventionsTitle.deployed = true;
	} else
	{
		interventionsTitle.deployed = false;
	}
	
	interventionsTitle.onclick = function()
	{
		if(!this.deployed)
		{
			this.deployed = true;
			new Effect.SlideDown('submenu-interventions');
		} else
		{
			this.deployed = false;
			new Effect.SlideUp('submenu-interventions');
		}
		
		return false;
	}
	
	if(!isSubMenuInterventionsDeployed)
	{
		Element.hide('submenu-interventions');
	}	
}


function menuAnimationAction2(rub, isSubMenuEn2007Deployed)
{
	var en2007Title = this.document.getElementById('en2007Title');
	
	if(isSubMenuEn2007Deployed)
	{
		en2007Title.deployed = true;
	} else
	{
		en2007Title.deployed = false;
	}
	
	en2007Title.onclick = function()
	{
		if(!this.deployed)
		{
			this.deployed = true;
			new Effect.SlideDown('submenu-en2007');
		} else
		{
			this.deployed = false;
			new Effect.SlideUp('submenu-en2007');
		}
		
		return false;
	}
	
	if(!isSubMenuEn2007Deployed)
	{
		Element.hide('submenu-en2007');
	}
	
}

function menuAnimationAction3(rub, isSubMenuEn2008Deployed)
{
	var en2008Title = this.document.getElementById('en2008Title');
	
	if(isSubMenuEn2008Deployed)
	{
		en2008Title.deployed = true;
	} else
	{
		en2008Title.deployed = false;
	}
	
	en2008Title.onclick = function()
	{
		if(!this.deployed)
		{
			this.deployed = true;
			new Effect.SlideDown('submenu-en2008');
		} else
		{
			this.deployed = false;
			new Effect.SlideUp('submenu-en2008');
		}
		
		return false;
	}
	
	if(!isSubMenuEn2008Deployed)
	{
		Element.hide('submenu-en2008');
	}
	
}


function menuAnimationAction4(rub, isSubMenuEn2009Deployed)
{
	var en2009Title = this.document.getElementById('en2009Title');
	
	if(isSubMenuEn2009Deployed)
	{
		en2009Title.deployed = true;
	} else
	{
		en2009Title.deployed = false;
	}
	
	en2009Title.onclick = function()
	{
		if(!this.deployed)
		{
			this.deployed = true;
			new Effect.SlideDown('submenu-en2009');
		} else
		{
			this.deployed = false;
			new Effect.SlideUp('submenu-en2009');
		}
		
		return false;
	}
	
	if(!isSubMenuEn2009Deployed)
	{
		Element.hide('submenu-en2009');
	}
	
}

function menuAnimationAction5(rub, isSubMenuEn2010Deployed)
{
	var en2010Title = this.document.getElementById('en2010Title');
	
	if(isSubMenuEn2010Deployed)
	{
		en2010Title.deployed = true;
	} else
	{
		en2010Title.deployed = false;
	}
	
	en2010Title.onclick = function()
	{
		if(!this.deployed)
		{
			this.deployed = true;
			new Effect.SlideDown('submenu-en2010');
		} else
		{
			this.deployed = false;
			new Effect.SlideUp('submenu-en2010');
		}
		
		return false;
	}
	
	if(!isSubMenuEn2010Deployed)
	{
		Element.hide('submenu-en2010');
	}
	
}

function searchBlankLinks()
{
	var a = this.document.getElementsByTagName("a");
	
	for(var i = 0; i < a.length; i++)
	{
		if(a[i].className == "blank")
		{
			var linkTarget = a[i];
			linkTarget.target = "_blank";
		}
	}
}

function cdtime(container, targetdate){
	if (!document.getElementById || !document.getElementById(container)) return
	this.container=document.getElementById(container)
	this.currentTime=new Date()
	this.targetdate=new Date(targetdate)
	this.timesup=false
	this.updateTime()
}

cdtime.prototype.updateTime=function(){
	var thisobj=this
	this.currentTime.setSeconds(this.currentTime.getSeconds()+1)
	setTimeout(function(){thisobj.updateTime()}, 1000) //update time every second
}

cdtime.prototype.displaycountdown=function(baseunit, functionref){
	this.baseunit=baseunit
	this.formatresults=functionref
	this.showresults();
}

cdtime.prototype.showresults=function(){
	var thisobj=this
	
	var dayfield;
	
	var timediff=(this.targetdate-this.currentTime)/1000 //difference btw target date and current date, in seconds
	if (timediff<0){ //if time is up
	this.timesup=true
	this.container.innerHTML=this.formatresults()
	return
}

var oneMinute=60 //minute unit in seconds
var oneHour=60*60 //hour unit in seconds
var oneDay=60*60*24 //day unit in seconds
var dayfield=Math.floor(timediff/oneDay)
var hourfield=Math.floor((timediff-dayfield*oneDay)/oneHour)
var minutefield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour)/oneMinute)
var secondfield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour-minutefield*oneMinute))

if (this.baseunit=="hours"){ //if base unit is hours, set "hourfield" to be topmost level
	hourfield=dayfield*24+hourfield
	dayfield="n/a"
}

else if (this.baseunit=="minutes"){ //if base unit is minutes, set "minutefield" to be topmost level
	minutefield=dayfield*24*60+hourfield*60+minutefield
	dayfield=hourfield="n/a"
}

else if (this.baseunit=="seconds"){ //if base unit is seconds, set "secondfield" to be topmost level
	var secondfield=timediff
	dayfield=hourfield=minutefield="n/a"
}

window.document.getElementById("countdownImg").src = "layout/img/misc/countdown/" + this.formatresults(dayfield) + ".gif";
}

function formatresults()
{

	return arguments[0]
}

window.onload = initOnLoad;
