$(function(){
//CLUSTER
	var clusterWidth=0;
	$('.cluster li').each( function(){ clusterWidth += $(this).width() + 10; });
	$('.cluster').width( clusterWidth );
	var clusterVisibleWidth = $(".cluster-visible").width();
	var clusterVisibleLeft = 20;
	if (clusterWidth>clusterVisibleWidth) {
		$(".cluster-containment").css({
			"left": -(clusterWidth-clusterVisibleWidth),
			"width":clusterWidth+(clusterWidth-clusterVisibleWidth+clusterVisibleLeft)
		});
		$(".cluster-visible").css({"left": (clusterWidth-912+clusterVisibleLeft)});
		$("a.cluster-arrow").bind("click",function(e){
			console.log("click")
			e.preventDefault();
			var clusterContainmentLeft = parseInt($(".cluster-containment").css("left"));
			var clusterContainmentRight = parseInt($(".cluster-containment").css("left")) + $(".cluster-containment").width();
			var clusterLeft = parseInt($(".cluster").css("left"));
			var clusterRight = parseInt($(".cluster").css("left"))+$(".cluster").width();
			if ($(this).hasClass("arrow-left")) {
				if (clusterLeft-40>clusterContainmentLeft) {
					$(".cluster").css({
						"left":"-="+40	
					});
				}else{
					$(".cluster").css({
						"left":clusterContainmentLeft
					});
				}
		
			}else if($(this).hasClass("arrow-right")){
			
				if (clusterRight+40<clusterContainmentRight) {
					$(".cluster").css({
						"left":"+="+40	
					});
				}else{
					$(".cluster").css({
						"left":0
					});
				}
			}
		});
	
		//DRAGGABLE
		$(".cluster").draggable({ axis: "x",containment: ".cluster-containment"  });
	};
//WIDGET
	//VOLET
	//Tout fermer par défaut
	//$("div.content-left div.widget-wrap div.widget div.widget-inner").hide().removeClass("open");
	//$("div.dossier-similaire div.widget div.widget-inner").hide().removeClass("open");

	$("div.content-left div.widget-wrap div.widget h3 a, div.dossier-similaire div.widget h3 a").bind("click",function(e){
		e.preventDefault();
		var widgetInner = $(this).parents("h3").siblings("div.widget-inner");
		widgetInner.stop();
		if ($(this).hasClass("open")) {
			widgetInner.slideUp();
			$(this).removeClass("open");
		}else{
			widgetInner.slideDown();
			$(this).addClass("open");
		}
	});
	//AFFICHAGE
	$('.widget.affichage li a').bind('click',function(e){
		e.preventDefault();
		if ($(this).hasClass("treemap") && !$(this).hasClass("active")) {
			$('.widget.affichage li a.liste').removeClass("active");
			$(this).addClass('active');
		}else if($(this).hasClass("liste") && !$(this).hasClass("active")){
			$('.widget.affichage li a.treemap').removeClass("active");
			$(this).addClass('active');
		}
	});
	//DATE PICKER
	$(".dateBegin").datepicker({
		onSelect: function( selectedDate ) {
        	$( ".dateEnd" ).datepicker( "option", "minDate", selectedDate );
        }
	});
	$(".dateEnd").datepicker({
		onSelect: function( selectedDate ) {
        	$( ".dateBegin" ).datepicker( "option", "maxDate", selectedDate );
        }
	});
//VOLET DOCUMENTAIRE
	$("div.dossier-documentaire").hide();
	$("div.header a.dossier-button").bind("click",function(e){
		e.preventDefault();
		$("div.dossier-documentaire").stop()
		if($("div.dossier-documentaire").is(":visible")){
			$("div.dossier-documentaire").slideUp();
		}else{
			$("div.dossier-documentaire").slideDown();
		}
	});
//ARTICLES
	$(".article-visuel-wrap").each(function(){
		var contentHeight = $(this).parents(".article-content").height();
		//$(this).height(contentHeight);
	});
//FRISE
	//valeurs init du slider à définir
	var valSlider1 = 75;
	var valSlider2 = 300;
	var diffSlide = valSlider2-valSlider1;
	var widthFrise = $('.frise').width();

	$( "#slider-range" ).dragslider({
		range: true,
		rangeDrag: true,
		min: 0,
		max: widthFrise,
		values: [ valSlider1, valSlider2 ],
		create: function(event, ui){
			$(".voile-left").width(valSlider1);
			$(".voile-right").width(widthFrise-valSlider2); 
		},
		slide: function( event, ui ) {
			
			/*//bloquer les curseur
			if(ui.values[1]-ui.values[ 0 ]!= diffSlide){
				return false;
			}
			*/
			$(".voile-left").width(ui.values[ 0 ]);
			$(".voile-right").width(widthFrise-ui.values[ 1 ]);
		},
		change: function( event, ui ){
			//ici on récup les valeurs après un slide
			var value1 = ui.values[ 0 ];
			var value2 = ui.values[ 1 ];
		}
	});


	
});//jQuery
