function getImage(onglet) {
	if ( onglet == 'Onglet0' ) {
		return 'bt_materiau';
	}else if ( onglet == 'Onglet1' ) {
		return 'bt_produits';
	}else if ( onglet == 'Onglet2' ) {
		return 'bt_organisation';
	}
}

$(window).load(function() {

	if ( $('#contentNews').length ) {
		$('#contentNews').jScrollPane({scrollbarWidth:10, scrollbarMargin:0, showArrows :true, arrowSize :9});
	}
	if ( $('#contentAgenda').length ) {
		$('#contentAgenda').jScrollPane({scrollbarWidth:10, scrollbarMargin:0, showArrows :true, arrowSize :9});
	}
	
	$(".ongletsNews a").click(function(){
		$(this).parents("ul:first").children("li.actif").removeClass("actif");
		$(this).parents("li:first").addClass("actif");

		if($(this).parents("li:first").attr("id") == "ongletNews"){
			$("#contentNews").parents("div.zoneNews").show();
			$("#contentAgenda").parents("div.zoneAgenda").hide();
		}else{
			$("#contentNews").parents("div.zoneNews").hide();
			$("#contentAgenda").parents("div.zoneAgenda").show();
		}
		return false;
	});
	
	$("#contentNews").parents("div.zoneNews").show();
	$("#contentAgenda").parents("div.zoneAgenda").hide();

	if ( $('#autresInfos').length ) {
		$('#autresInfos').jScrollPane({scrollbarWidth:10, scrollbarMargin:0, showArrows :true, arrowSize :9});
	}
	
	if ($('#slideBoutique').length) {
		
		var slider 			= $('#contentSlider');
		var sliderContentL 	= $('.sliderContent', slider).length;
		var firstChild 		= $('.sliderContent:first-child', slider).clone();
		var lastChild 		= $('.sliderContent:last-child', slider).clone();
		
		firstChild.insertAfter( $('.sliderContent:last-child', slider) );
		lastChild.insertBefore( $('.sliderContent:first-child', slider) );
		
		slider.css('left', '-237px');
		
		$('#slideBoutique .btnSlide a:first-child').click( function() {
			
			var posXSlider = parseInt(slider.css('left'));

				slider.animate({
					left:posXSlider+237
				}, function() {
					var posXSlider = parseInt(slider.css('left'));
					if( posXSlider == 0 ) {
						slider.css('left', (sliderContentL * 237) * -1);
					}
				});
				
				return false;
			
		});
		
		$('#slideBoutique .btnSlide a+a').click( function() { 

			var posXSlider = parseInt(slider.css('left'));

			slider.animate({
				left:posXSlider-237
			}, function() {
				if (posXSlider ==  (sliderContentL * 237) * -1 ) {
					slider.css('left', '-237px');
				}
			});

			return false;	
			
		});
		
	}
	
	if ($('.logoPartenaires img').length > 0) {
		$('.logoPartenaires').fade({
			delay: 2000,
			timeout: 5000
		});
	} else {
		$('.logoPartenaires img').show();
	}
	
	if( $('#btnOuvrir').length ) {
		$('#btnOuvrir').click( function() {
			
			var config = $('#configurateurEspace');
			
			if ( config.hasClass('open') ) {
				var leftPos = '-638px';
				var classToAdd = 'closed';
				var funcTitre = $('#titreCliquez').fadeIn();
			}else{
				var leftPos = '0';
				var classToAdd = 'open';
				var funcTitre = $('#titreCliquez').fadeOut();
			}
			
			funcTitre;
			
			config.animate({
				left:leftPos
			}, function(){
				$(this).attr('class', classToAdd)
			})
			
			return false;
		});
	}
	
	if( $('#timeline').length ) {
	
		$('#historique .divHistorique:first-child').css('display', 'block');
	
		var wrapperWidth = 610;
		var context		 = $('#contentTimeline');
		var contentWidth = $('ul', context).width();
		var elWidth 	 = $('ul li', context).width();
		
		var borneGauche	 = wrapperWidth - contentWidth;
		borneGauche = borneGauche > elWidth ? 0 : borneGauche;

		$('#TimelineMoins, #TimelinePlus').click( function() { return false });
		
		$('#TimelinePlus').hover( function() {
				context.animate({ 'left' : borneGauche }, 3000);
			}, 
			function() {
				context.stop();
			}
		);
		
		$('#TimelineMoins').hover( function() {
				context.animate({ 'left' : 0 }, 3000);
			}, 
			function() {
				context.stop();
			}
		);
		
		$('a', context).click( function(e) {
		
			if ($(this).parent().hasClass('selected')) { return false }

			var divToHide = $('#historique .divHistorique:visible');
			var divToShow = $('#'+$(this).attr('rel'));

			$('li', context).removeAttr('class');
			$(this).parent().attr('class', 'selected');
			
			$(divToHide).fadeOut(500);
			$(divToShow).fadeIn(500);
			
			return false;
		});
		
	}

	if( $('#galeryLogiciel').length ) {
		$('#mainImage').simpleGalery({ thumbnails : '#galeryLogiciel dd' });
	}

});

$(document).ready(function(){

	$(".ongletsSupportLibrairie a").click(function(){
		$(this).parents("ul").children("li.selected").removeClass("selected");
		$(this).parents("li:first").addClass("selected");
		if($(this).parents("li:first").attr("id") == "Onglet0"){
			$("#OngletDiv0").show();
			$("#OngletDiv1").hide();
			$("#OngletDiv2").hide();
		}else if($(this).parents("li:last").attr("id") == "Onglet2"){
			$("#OngletDiv0").hide();
			$("#OngletDiv1").hide();
			$("#OngletDiv2").show();
		}else{
			$("#OngletDiv0").hide();
			$("#OngletDiv1").show();
			$("#OngletDiv2").hide();
		}
		return false;
	});
		
	$("#menuPrestation a").click(function()	{
		divid = $(this).attr('id');

		divoff = $('#CataloguePresta>div.apparition:visible').not("#pretaDiv_"+divid);
		$(divoff).hide();
		$('#prestaDiv_'+divid).show();

		return false;
	});
	
	$("#menuPresta li:first").addClass("clic");
	$("#menuPresta a").click(function() {
			divid = $(this).attr('id');
			divoff = $('#blocPresta>div.apparition:visible').not('#prestaDiv_'+divid);
			var onglet = $(this).parents("ul").children("li.clic").attr('id');
			var btImg = getImage(onglet);
			$(this).parents("ul").children("li.clic").removeClass("clic").find('img').attr('src', racine+btImg+'_off'+'.jpg');
			var onglet = $(this).parents("li").attr('id');
			var btImg = getImage(onglet);
			$(this).parents("li").addClass("clic").find('img').attr('src', racine+btImg+'_on'+'.jpg');
			$('#prestaDiv_'+divid).show();
			$(divoff).hide();
			return false;
	});

	$("#menuImplantation a").click(function()	{
		divid = $(this).attr('id');
		divoff = $('#implantation>div:visible').not('#implantation_0');

		$('#implantation_'+divid).show();
		$(divoff).hide();

		return false;
	});
	$(".ongletsRessourcesLibres a").click(function(){
		$(this).parents("ul").children("li.selected").removeClass("selected");
		$(this).parents("li:first").addClass("selected");
		
		if($(this).parents("li").attr("id") == "Onglet_ressource_libre_telechargement"){
			$("#Div_ressource_libre_telechargement").show();
			$("#Div_ressource_libre_video").hide();
			$("#Div_ressource_libre_lienutile").hide();
			$("#Div_ressource_libre_geolocalisation").hide();
			$("#Div_ressource_libre_reconnaissance").hide();
		}else if($(this).parents("li").attr("id") == "Onglet_ressource_libre_video"){
			$("#Div_ressource_libre_telechargement").hide();
			$("#Div_ressource_libre_video").show();
			$("#Div_ressource_libre_lienutile").hide();
			$("#Div_ressource_libre_geolocalisation").hide();
			$("#Div_ressource_libre_reconnaissance").hide();
		}else if($(this).parents("li").attr("id") == "Onglet_ressource_libre_lienutile"){
			$("#Div_ressource_libre_telechargement").hide();
			$("#Div_ressource_libre_video").hide();
			$("#Div_ressource_libre_lienutile").show();
			$("#Div_ressource_libre_geolocalisation").hide();
			$("#Div_ressource_libre_reconnaissance").hide();
		}else if($(this).parents("li").attr("id") == "Onglet_ressource_libre_geolocalisation"){
			$("#Div_ressource_libre_telechargement").hide();
			$("#Div_ressource_libre_video").hide();
			$("#Div_ressource_libre_lienutile").hide();
			$("#Div_ressource_libre_geolocalisation").show();
			$("#Div_ressource_libre_reconnaissance").hide();
		}else if($(this).parents("li").attr("id") == "Onglet_ressource_libre_reconnaissance"){
			$("#Div_ressource_libre_telechargement").hide();
			$("#Div_ressource_libre_video").hide();
			$("#Div_ressource_libre_lienutile").hide();
			$("#Div_ressource_libre_geolocalisation").hide();
			$("#Div_ressource_libre_reconnaissance").show();
		}
		return false;
	});

	if( $('.articleOptions').length ) {
		var zone = $('.xmlzone');
		$('.articleOptions li:first-child a').click( function() {
		   var fontSize = parseInt(zone.css('font-size'))+1;
		   var lineHeight = parseInt(zone.css('line-height'))+2;
		   zone.css({
			   'font-size'          : fontSize+'px',
			   'line-height'        : lineHeight+'px'
			   });
		   return false;
		});

		$('.articleOptions li:first-child + li > a').click( function() {
		   var fontSize = parseInt(zone.css('font-size'));
		   if( fontSize === 11 ) { return false };
		   fontSize = --fontSize;
		   var lineHeight = parseInt(zone.css('line-height'))-2;
		   zone.css({
			   'font-size'          : fontSize+'px',
			   'line-height'        : lineHeight+'px'
		   });
		   return false;
		});
	}
});