$(document).ready(function(){

	splitted_url		=	window.location.href.split( "/" );
	server_url			=	splitted_url[0]+"/"+splitted_url[1]+"/"+splitted_url[2];
	page_with_ext		=	splitted_url[ ( splitted_url.length - 1 ) ];
	current_ext			=	page_with_ext.substr( page_with_ext.indexOf(".") ).toLowerCase(); 
	current_page		=	page_with_ext.substr( 0, page_with_ext.indexOf(".") );
	special_page		=	window.location.href.substr( window.location.href.indexOf("#")+1 );

	$(".accordeon").accordion({
		header: ".click_accordeon,.fermer",
		active: true,
		alwaysOpen: true,
		autoheight: false
	});

	$(".click_accordeon").click( function(){
	
		$(".click_accordeon").show();
		
		if( $(this).html().search( /LIRE\ LA\ SUITE/ ) != -1 ) {

			$(".accordeon").accordion({
				header: ".click_accordeon,.fermer",
				active: true,
				alwaysOpen: true,
				autoheight: false
			});

			$(this).css({
				"background-image"			:	$(this).css("background-image").replace(".gif\")", "") + "_ouvert.gif\")"
			});

			$(this).hide();
		}
	});

	$(".fermer").click( function(){
		$(this).parent().parent().children(".click_accordeon").show();
		//$(this).parent().parent().children(".click_accordeon").click();
		$(this).parent().parent().children(".titre_accordeon_ouvert.click_accordeon").attr("class","titre_accordeon click_accordeon");
	});

	if( current_page != "acteurs" || special_page != "devenir_benevole" )
	{
		$(".click_accordeon.first").click();
	}

	$(".lienMenu").mouseover( function(){
		// $(this).parent().css({
			// background:$(this).css("color")
		// });
		$(".sousmenu").hide();
		$(this).parent().children("div").show();
	});
	$(".lienMenu").mouseout( function(){
		$(".sousmenu").hide();
	});

	$(".sousmenu").mouseover( function(){
		$(this).show();
		$(this).parent().children("a").addClass( "active" );
	});

	$(".sousmenu").mouseout( function(){
		$(this).hide();
		if( $(this).parent().children("a").attr( "class" ).search( /baseActive/ ) == -1 )
		{
			$(this).parent().children("a").removeClass( "active" );
		}
	});
	
	$(".ouvertAccordion").click( function() {
		
		if ( $(this).next("div").css("display") == "block" ) {
			$(this).attr("class","titre_accordeon click_accordeon first");
		} else {
			$(this).attr("class","titre_accordeon_ouvert click_accordeon first");
		}
	});

	switch( current_page )
	{
		 case "publications":
			redimensionner();
			break;
		 case "historique":
			$(".periodes").hide();
			$(".lire_suite").click( function(){
				lastNr			=	$(this).parent().attr( "id" ).substr( -1, 1 );
				nextNr			=	parseInt( lastNr ) + 1;
				if( $("#Period"+nextNr).html() != undefined )
				{
					$("#Period"+nextNr).click();
				}else{
					$("#Period1").click();
				}
				return false;
			});
			$(".btn_frise").click( function(){
				$(".btn_frise").map(function(){
					$(this).children("img").attr( "src", $(this).children("img").attr( "src" ).replace( "_hover", "" ) );
				});
				$(this).children("img").attr( "src", $(this).children("img").attr( "src" ).replace( ".jpg", "" )+"_hover.jpg" );
				$(".periodes").hide();
				$("#p"+$(this).attr("id")).show();
				$(this).blur();
				return false;
			});
			$("#Period1").click();
			break;
		case "acteurs":
			if( special_page == "devenir_benevole" )
			{
				$("h3.first").removeClass( "first" );
				$("h3.benevoles").click();
			}
			break;
		case "partenaires":
			redimensionner();
			break;
		case "don_en_nature":
			redimensionner();
			break;
		case "adherer":
			redimensionner();
			break;
	}
	if( splitted_url[3] == "centres" )
	{
		redimensionner();
	}
	$("input[type=text]").map( function(){
		if( !$(this).attr( "readonly" ) && !$(this).attr( "disabled" ) && $(this).attr( "class" ).search( /generated/ ) == -1 )
		{
			$(this).attr( "label", $(this).val() );
			$(this).click( function(){
				if( $(this).val() == $(this).attr( "label" ) )
				{
					$(this).val( "" );
				}
			});
			$(this).blur( function(){
				if( $(this).val().trim() == "" )
				{
					$(this).val( $(this).attr( "label" ) );
				}
			});
		}
	});

	if( $.browser.msie && $.browser.version == "6.0" )
	{
		ie6_fix();
	}
});

function redimensionner()
{

	if( $("#contenu").height() < $("#colone_gauche").height() )
	{
		$("#contenu").height( parseInt( $("#colone_gauche").height() ) + 5 + "px" );
	}else{
		$("#colone_gauche").height( parseInt( $("#contenu").height() ) - 5 + "px" );
	}

}