var sections = [];
		var endHomeY = 200;
		var currentSection;
		var currentSectionTitle;
		
		function navPosition ()
		{
			if($(window).width() >= 1290) {
			  $('nav').addClass('fixed');
			} else {
			    $('nav.fixed').removeClass('fixed');
			}
		}
		
		//top header changing on hover nav
		function previewSection(id, t, d)
		{
			if(d == undefined) duration = 800;
			
			$('div', '#nav-section-title').hide();
			$('.illustration-'+id,'#nav-section-title').stop(false, true).fadeIn(d);
			$('h2', '#nav-section-title').stop(false, true).hide().html(t).fadeIn((d/2));
		}
		
		function setNavigationState ()
		{

			var stageY = $(window).scrollTop();
			//case home
			if (stageY >= (endHomeY-200) && stageY <= endHomeY) {
				$('.main-nav').css('opacity', 1 -(stageY/200));
				activeNav();
			} else if (stageY >= endHomeY + 100) {
				$('.main-nav').css('opacity', 0.5);
			}
			
			var i=0;
			while(i < sections.length) {
				if(stageY >= sections[i][1]-201 && stageY <= sections[i][1] + 201) {
					if(stageY >= sections[i][1]-201 && stageY <= sections[i][1] - 50) {
						var alpha = 1+(stageY - sections[i][1])/400;
					} else if (stageY >= sections[i][1] + 50 && stageY <= sections[i][1] + 201) {
						var alpha = 1+(sections[i][1] - stageY)/400;
					} else {
						var alpha = 1;
					}
					$('.main-nav').css('opacity', alpha);
					activeNav(sections[i][0], sections[i][2]);
					break;
				}
				i++;
			}
			
			if(stageY > endHomeY)
			{
				$('.main-nav').addClass('floating');
			} else {
				$('.main-nav.floating').removeClass('floating');
			}
			//console.log(stageY)
		}
		
		function activeNav (rub, title)
		{
			$('a.active', '.main-navigation').removeClass('active');
			if(rub != undefined) {
				$('a[href='+rub+']', '.main-navigation').addClass('active');
				currentSection = rub;
				currentSectionTitle = title;
			} else {
				currentSection = "#home";
				currentSectionTitle = "UN GROUPE: des compétences multiples&nbsp;!";
			}
			
			$('h2', '#nav-section-title').html(currentSectionTitle);
		}
		
		$(document).ready(function() {
			
			$('.slider').ism_carousel({
			    item: ".item", //optional item to carousel
			    caption: false,
			    margin: 6,
			    crop: 1,
			    startAtItem : 0,
			    arrows: true,
			    width: 'auto',
			    height: 'auto',
			    nextText: "suiv.",
			    prevText: "prec.",
			    easing :'easeOutQuart', //easeOutQuart, easeOutBack, easeOutElastic, linear
			    autoPlay: true,
			    duration: 5000,
			    speed: 1000,
			    fx: 'slide',
			    direction: 'vertical',
			    dots: false
			})
			
			//pushing navigation sections positions
			$('a', '.main-navigation').each(function() {
				var id = $(this).attr('href');
				var y = $("a"+id).offset().top;
				var t = $(this).attr('title');
				sections.push([id, y, t]);
			});
			
			activeNav();
		    navPosition();
		    
		    //positionnement de la nav
		    $(window).resize(function() {
		    	navPosition()
		    });
		    $(window).scroll(function() {
				setNavigationState();
		    });
		    
		    //top header changing on hover nav
		    $('a', '.main-navigation').hover(function () {
		    	var t = $(this).attr('title');
		    	var id = $(this).attr('class');
		    	previewSection(id, t);
		    }, function () {
		    	if(currentSection != "#home") {
			    	previewSection(currentSection, currentSectionTitle);
			    }
		    });
		    
		    //scrollNavigation
		    $.localScroll({
		    	easing:'easeInOutQuint',
		    	duration: 1600,
		    	hash:true
		    });
		    
		    //colorbox init
		    $("a[rel=colorbox]").colorbox({iframe:true, innerWidth:860, innerHeight:430});
		});
