var i_numNav=0;
var item;
var outil;

// Outil sélection 
function outilShow(numOutil){

	if (outil){
		$(outil).fadeOut(0);
	}
	

	if (outil = document.getElementById("outil_" + numOutil)){		
		uncommentImg(outil);
		outil.style.display = "block";
		//outil.style.opacity = 1;
		$(outil).hide();
		
		$(outil).fadeIn(500);
	}
}

// SlideShowArrow Click
function slideNav(navTo){
	if (document.getElementById("slideshow_item" + (i_numNav+navTo) )){	
		document.getElementById("slideshow_nav"+ i_numNav).style.display = "none";
		i_numNav+=navTo;
		nav = document.getElementById("slideshow_nav"+ i_numNav);
		uncommentImg(nav);
		$("#slideshow_nav" + i_numNav).hide().fadeIn(1500);
	}

}

// SlideShowClick

function slideShow(num){			
	if (item){		
		item.style.display = "none";		
	}
	
	if (item = document.getElementById("slideshow_item" + num)){
		uncommentImg(item);
		item.style.display = "block";
		$("#slideshow_item" + num).hide().fadeIn(300);
	//	item.style.opacity = 0;
	//	new Effect.Opacity(item, { from: 0, to: 1 });
	}
}
function uncommentImg(pItem){
var tempText = pItem.innerHTML;
var reg=/(<!--)/g;
tempText = tempText.replace(reg,"");
reg = /(-->)/g;
tempText = tempText.replace(reg,"");
pItem.innerHTML = tempText;
}

function mainStart(){
	
//	$("#mainpage").fadeIn(1000);
	
	
	document.getElementById("mainpage").style.display = "block";
	document.getElementById("loading").style.display = "none";	
	
	// Affiche le premier slide
	slideShow(0);
	// Affiche la première barre de navigation
	if (document.getElementById("slideshow_nav"+ 0))
	document.getElementById("slideshow_nav"+ 0).style.display = "block";
	
	//outils
	outilShow(1);
	
	$("html").scrollTo($("#bloc_news"));
	setNews();

	setTimeout("hlarrow()",500);

}
function hlarrow(){
	$(".arrow").effect("pulsate", { times:5 }, 300);
}


// Menu 
function unsetMenu(){
	$("ul.main_menu a").css('background','');	
}
function setAgence (){
	unsetMenu();
	$("#bloc_agence .menu_agence a").css('background','url(images/menu/menu_bck.png) center top no-repeat');	
}
function setNews (){
	unsetMenu();
	$("#bloc_news .menu_news a").css('background','url(images/menu/menu_bck.png) center top no-repeat');	
}
function setMetier (){
	unsetMenu();
	$("#bloc_metier .menu_metier a").css('background','url(images/menu/menu_bck.png) center top no-repeat');	
}
function setOutils (){
	unsetMenu();
	$("#bloc_outils .menu_outils a").css('background','url(images/menu/menu_bck.png) center top no-repeat');	
}


function ini(){
	document.getElementById("mainpage").style.display = "none";
	document.getElementById("loading").style.display = "block";
	window.onload = new Function("mainStart()");
	
}

// __ Main code 


$(function(){

	$(".menu_agence").click(function() { 	
		$("html").scrollTo($("#bloc_agence"),800,{onAfter:setAgence});
	});	
	$(".menu_news").click(function() { 	
		$("html").scrollTo($("#bloc_news"),800,{onAfter:setNews});
	});	
	$(".menu_metier").click(function() { 	
		$("html").scrollTo($("#bloc_metier"),800,{onAfter:setMetier});
	});	
	$(".menu_outils").click(function() { 	
		$("html").scrollTo($("#bloc_outils"),800,{onAfter:setOutils});
	});		
	$(".arrow").mouseover(function() { 	
		$(this).effect("pulsate", { times:3 }, 300);
	});	
	//ini();
	$(document).ready(function() {
	  mainStart();
	});	
});
