// requires following variables :
// rubriques_ids | where apply the menu contextuel
// active_element | element which is opened
// index | of the color table

// settings
var speed = 400;
var colors = ['D1B400','F0B900', 'FFB500', 'FFA900', 'FF9D00', 'FF7B00', 'FF5800', 'FF5800', 'FF5800','FF8C00','FFA500','FFB400','F8B900','DCB300','CFB200','C2B100','DCB300','F8B900','FFB400','FFA500', 'FF5800', 'FF5800', 'FF5800','FF8C00','FF7B00'];
                       
function open_item(id)
{
	$(id).animate({width: '389px'}, speed, function()
	{
		$(id + " > ul").slideDown(100);
	});	
}

function close_item(id)
{
	$(id).stop(true,true);
	$(id + " > ul").slideUp(20);
	$(id + " > ul").css('display','none');
	$(id).animate({ width: '190px'}, speed / 2);	
}


function toggle_active(direction)
{
	if (direction) // true is open
		{ open_item(active_element); }
	else
		{ close_item(active_element); }
}

function open_active()
{
 open_item(active_element);
}

function add_nav()
{
  // add rubriques events
  $.each(rubriques_ids, function(i, l)
  {
    $(l).hover(
      function () // mouseon 
      {
        if (l != active_element)
       	  { toggle_active(false); }
    	  open_item(l);
      }, 
      function () // mouseout
      {
    
        if (l != active_element)
          { toggle_active(true); 
    	      close_item(l);}
      });
  });
  
  // add articles events
  $.each(articles_ids, function(i, l)
  {
    $(l).hover(function () {
  	$(this).addClass("article_on");
      }, function () {
  	$(this).removeClass("article_on");
      });
  });

  // this apply the color gradient to the nav menu.
  for(i = 0; i != $("#nav>ul>li").length; i++)
  {
    color_index = i + index;

  	$("#nav>ul>li:nth-child(" + (i + 1) + ")").css('background-color', "#" + colors[color_index] );
  	$("#nav>ul>li:nth-child(" + (i + 1) + ")>ul>li a").css('color', "#" + colors[color_index] );
  	$("#nav>ul>li:nth-child(" + (i + 1) + ")>ul>li a").hover( 
  																														function() { $(this).css('color', "blue") }, 
  																														function() { $(this).css( 'color', $(this).parent().parent().parent().css('background-color') ) }
  																													);
  	$("#nav>ul>li:nth-child(" + (i + 1) + ")>ul").css('border-color', "#" + colors[color_index] );
  }

  $("#contact").css({'background-color' : '#fff', 'border' : 'solid 2px #ff5800'});
}

function ie_piss_me_off() {
  // because IE gave me headache
  var browser = $.browser
  
  if (browser.msie && browser.version == "7.0")
  {
    $('#nav ul li>ul').css('position', 'relative');
    $('.bouton').css('height','65px'); 
    $('.boutonpro').css('height','65px');
    $('.bouton>a').css('padding',' 0 8px').css('display','block');
    $('.boutonpro>a').css('padding',' 0 8px').css('display','block'); 
    $('.bouton_login').css('height','110px');
  }
}

