jQuery(document).ready(function($) {

	//div fonctionne en a
	$("#menuprincipal ul li").click(function(){
	  //get the url from href attribute and launch the url
	  window.location=$(this).find("a").attr("href"); return false;
	});

	//focus menu principal
	if (page_univers)
		jQuery('#menuprincipal ul li.' + page_univers + ' a').addClass('active');

  //use the scriptbreaker.com multiple accordion menu
  $(".menu_sidebar").accordion({
      accordion:true,
      speed: 500,
      closedSign: '',
      openedSign: ''
  });

  //Colorbox
	$("a[rel='colorboxpopup']").colorbox({
			transition:"fade",
			maxWidth: '960px',
			maxHeight: '700px'
	});

	//Cycle
	$('.slider_container, .slider_container2')
		.before('<div id="nav"></div>')
		.cycle({
		    fx:     'scrollLeft',
		    speed:  1000,
		    timeout: 5000,
		    pager:  '#nav'
	});

	//ouverture automatique/page
	$.each($('.submenu a'), function(i, e){
	  if ($(e).attr('href') == document.location.pathname){
			$(e).parents('ul').show();
		}
	});

	// Suppresion des sous-menus vide
	$('.submenu').each(function() {
	  var $this = $(this);
	  if ($this.text().replace(/^\s+|\s+$/g,'') === '')
	    $this.remove();
	});

    i18n_ajax_change = function(lang){
        jQuery.get('/i18n?lang=' + lang, function(data){
           document.location.reload();
        });
    }

    jQuery('a[href*="#lang="]').click(function(ev){
        ev.preventDefault();
        i18n_ajax_change(this.hash.split('=')[1]);
    });

});
