/* Navigation */
function initNavigation()
{

	clearNavigation();
	
	var currentRubrique = $("#currentRubrique")[0].innerHTML;
	var currentSection = $("#currentSection")[0].innerHTML;


	//$("#menudt"+currentRubrique+"dd li#li_navs_"+currentSection).addClass("selected");
	//$( "#accordion .ui-accordion-header" )

	if(currentRubrique !="0")
	{
	
	$("#menudt"+currentRubrique).addClass("ui-state-active");
	$("#menudt"+currentRubrique+"dd").show();
	$("#menudt"+currentRubrique+"dd").addClass("ui-accordion-content");
	
  //  var index =  $("#menudt"+currentRubrique+" span.index").html();
	//$("#accordion").accordion({ active: index,autoHeight: false,collapsible: false});

     }
     else if(document.location.toString().indexOf("phototheque")>-1)
     {
     
     $("#menudt54").addClass("ui-state-active");
	 $("#menudt54dd").show();
	 $("#menudt54dd").addClass("ui-accordion-content");
      $("#menudt54dd li#li_navs_268 a").addClass("currentSection");

     }
 
}
function clearNavigation()
{
    $("#accordion h3").attr("class","");
    $("#accordion div").attr("class","");
	$("#accordion div").hide();
}
/* Fin Navigation */
// Changer ces couleurs en style
function initHomeNews()
{
	$(".news_home").hover(
		function(){this.style.backgroundColor = '#e5e5e5';},
		function(){this.style.backgroundColor = '#ffffff';});
}
function initSection()
{
	$(".tableItem").hover(
		function(){this.style.backgroundColor = '#e5e5e5';},
		function(){this.style.backgroundColor = '#ffffff';});
	$(".bloc_news").click(
		function(){document.location = this.title});
	if($(".bloc_news").length > 0)
		$(".bloc_news")[0].className = "bloc_news first_bloc_news";
}
function initNewsAssoc()
{
	$(".bloc_news_assoc").click(
		function(){document.location = this.title});
}
/* Debut Diaporama */
function initDiaporama(moduleID, pageSize)
{
	$("#"+moduleID+"_module_diaporama a").click(
		function()
		{
			var nextIndex = this.title;
			if(nextIndex == "P")
			{	
				nextIndex = parseInt($("#"+moduleID+"_module_diaporama .currentIndex")[0].innerHTML);
				nextIndex--;
			}
			else if (nextIndex == "N")
			{
				nextIndex = parseInt($("#"+moduleID+"_module_diaporama .currentIndex")[0].innerHTML);
				nextIndex++;
			}
			
			$("#"+moduleID+"_module_diaporama .currentIndex")[0].innerHTML = nextIndex;
			$("#"+moduleID+"_module_diaporama .img_mediatheque")[0].src = $("#"+moduleID+"_module_diaporama .p_media_"+nextIndex)[0].innerHTML;	
			initPager(moduleID, pageSize);
		});
		
	var firstIndex = 0;
	$("#"+moduleID+"_module_diaporama .currentIndex")[0].innerHTML = firstIndex;
	$("#"+moduleID+"_module_diaporama .img_mediatheque")[0].src = $("#"+moduleID+"_module_diaporama .p_media_"+firstIndex)[0].innerHTML;
	initPager(moduleID, pageSize);	
}
function initPager(moduleID, pageSize)
{
	var currentIndex = parseInt($("#"+moduleID+"_module_diaporama .currentIndex")[0].innerHTML);
	var tabLien = $("#"+moduleID+"_module_diaporama a.Nombre");
	var maxID = 0;
	for(var i = 0 ; i < tabLien.length ; i++)
	{
		tabLien[i].className = "Nombre";
		if(tabLien[i].title == currentIndex)
			tabLien[i].className = "Nombre Selected";
			
		maxID = parseInt(tabLien[i].title);
		var title = parseInt(tabLien[i].title);
		if(title >= (currentIndex - currentIndex%pageSize) && title < ((currentIndex + pageSize - currentIndex%pageSize)))
			tabLien[i].style.display = "inline";
		else
			tabLien[i].style.display = "none";
	}
	
	if(currentIndex == 0)
		$("#"+moduleID+"_module_diaporama .PageP")[0].style.display = "none";
	else
		$("#"+moduleID+"_module_diaporama .PageP")[0].style.display = "inline";
		
	if(currentIndex == maxID)
		$("#"+moduleID+"_module_diaporama .PageN")[0].style.display = "none";
	else
		$("#"+moduleID+"_module_diaporama .PageN")[0].style.display = "inline";	
}
/* Fin Diaporama */
$(document).ready(function() 
{
$("#accordion h3").click(function()
{
clearNavigation();
if($(this).attr("class") != "ui-state-active")
{
	
	$(this).addClass("ui-state-active");
	$(this).next().show();
	$(this).next().addClass("ui-accordion-content");
}
});
	initNavigation();
	initHomeNews();
	initSection();
	initNewsAssoc();
	$(".colorbox").colorbox({maxWidth:"85%", maxHeight:"85%", 
		onOpen:function(){$("#module").toggleClass("invis")},onClosed:function(){$("#module").toggleClass("invis")}});
	initPhototheque();
});

// Gestion Phototheque
var Phototheque_PageLine = 3;
var Phototheque_currentPage = 0;
var Phototheque_line_height = 214;

function initPhototheque()
{
	$("a[rel='dossier']").colorbox({opacity:0.5,slideshow:true,slideshowSpeed:5000});
	var nb_photos = $('.photo_item_photo').length;
	var hauteur = (Phototheque_PageLine * Phototheque_line_height) + "px";
	$("#div_overflow_totheque").css("height",hauteur);
		var nb_pages = 0;
	if((nb_photos%(Phototheque_PageLine * 3)) != 0)
		nb_pages = (nb_photos - (nb_photos%(Phototheque_PageLine * 3))) / (Phototheque_PageLine * 3)+1;
	else
		nb_pages = (nb_photos - (nb_photos%(Phototheque_PageLine * 3))) / (Phototheque_PageLine * 3);
	$("#div_overflow_totheque_container").css("height",(nb_pages*Phototheque_PageLine*Phototheque_line_height)+"px");
	for(var i = 0 ; i < nb_pages ; i++)
		$("#div_pager").append("<a href='#photo_total'>"+(i+1)+"</a>");
	
	$("#div_pager a").attr("class","other");
	if ($("#div_pager a").length > 0)
		$("#div_pager a")[0].className = "current";

	$("#div_pager a").click(function(){
		$("#div_pager a").attr("class","other");
		$(this).attr("class","current");
		var page = parseInt($(this).html()) - 1;
		$("#div_overflow_totheque").animate({opacity:0},400, function(){
				$("#div_overflow_totheque").scrollTop(page*Phototheque_line_height*Phototheque_PageLine);
				$("#div_overflow_totheque").animate({opacity:1},700);
			});
		
		//$("#div_overflow_totheque").animate({scrollTop:page*Phototheque_line_height*Phototheque_PageLine},500);
	});
}