$(document).ready
(
    function()
    {
	/*
	    Gestion de la navigation
	*/

	$("#view-secteurs-header ul.secteurs li.secteur a").
	each
	(
	    function()
	    {
		var $a	    = $(this);
		var pos	    = $a.backgroundPosition().split(/\s+/);

		$a.hover
		(
		    function()
		    { 
			$a.stop().animate
			(
			    {backgroundPosition : "(" + pos[0] + " 21px)"}, 
			    {duration : 100}
			);
		    },

		    function()
		    {
			$a.stop().animate
			(
			    {backgroundPosition : "(" + pos[0] + " " + pos[1] + ")"}, 
			    {duration : 200}
			);
		    }
		);
	    }
	);

	/*
	   Taille de l'introduction
	*/

	var intro	= $("#titleContainer div.view.introduction p").wrapAll("<div class=\"intro\"></div>").parent("div.intro");
	var iHeight	= intro.height();
	var paragraphs	= intro.find("> p");

	if ( paragraphs.length > 1 )
	{
	    var p = paragraphs.eq(0);
	    iHeight += p.outerHeight(true) - p.outerHeight();
	}

	var pHeight = intro.find("p").eq(0).outerHeight(true);
	var oHeight = parseInt(intro.css("font-size")) * 4.5;
	var height  = Math.min(pHeight, oHeight);

	if ( iHeight > height )
	{
	    intro.height(height).css("overflow", "hidden");

	    $("<a href=\"#\"></a>").addClass("more").text("en savoir plus").insertAfter(intro).click
	    (
		function(e)
		{
		    e.preventDefault();

		    if ( intro.is(".opened") )
		    {
			intro.toggleClass("opened", false).stop(true).animate({height:height});
			$(this).text("en savoir plus");
		    }
		    else
		    {
			intro.toggleClass("opened", true).stop(true).animate({height:iHeight});
			$(this).text("fermer");
		    }

		}
	    );
	}

	/*
	    Taille du footer
	*/

	var $footer = $("#footerContainer");
	$(window).resize
	(
	    function()
	    {
		var top		    = $footer.offset().top;
		var footerHeight    = $footer.find("#footer").height();
		var bodyHeight	    = Math.max($(window).height(), $("body").get(0).scrollHeight);

		if ( bodyHeight - top > footerHeight )
		{
		    $footer.height(bodyHeight - top);
		}
		else
		{
		    $footer.height("auto");
		}
	    }
	)
	.resize();
    }
);

