function onePageNav(navigation, header_offset) {
	$(navigation +' li, #mobilenavigation li').each(function(){
		$(this).removeClass('active');
	});
	$('li#l1').addClass('active');
	$(navigation +' li a , #mobilenavigation li a').click(function(e){
				if(!$('body.job').length && !$(this).hasClass('no_prevent')) e.preventDefault();//Disable href unless on job page
				$('body').removeClass('nav-open');// Close mobile menu if open

				/* ANIMATE SCROLL ON CLICK */
				var id = 'div#' + $(this).parent().attr('id');// Get id
				

				$('html, body').animate({scrollTop: $(id).offset().top - header_offset }, 1000);//Animate scroll
			});

	var ids = [];
	/* DETECT SCROLL */
	$(navigation +' li a').each(function(){
				var id = 'div#' + $(this).parent().attr('id');// Get id
				ids.push(id);
			});
	console.log('scroll = ' + $('div#l1').offset().top);
	$(window).scroll(function(){
		for(var i = ids.length -1; i >= 0; i--) {
			current_id = ids[i];

			var scroll_height = $(window).scrollTop();
			var inner_height =  $(current_id).innerHeight();
			var scroll_top = $(current_id).offset().top;

			if(scroll_height > scroll_top - header_offset - 300 && scroll_height < scroll_top + innerHeight - header_offset - 300) {
				current_id = current_id.replace('div','li');
				if(!$(current_id).hasClass('active')) {
					$(current_id).siblings().removeClass('active');
					$(current_id).addClass('active');
				}
				break;
			}
		}
	});
}

$(function(){

	var job_id = String(window.location.href).split('/').pop().toLowerCase();
	console.log(job_id);

	$('.job_documents').each(function(){
		
		if($(this).hasClass(job_id)) $(this).show();
	});
	
});



$(function(){
// CUSTOM FUNCTIONS
	// JOB CARDS
	html ='';
	toggleBar = ' <div id="toggle-bar"> <h1>Latest jobs</h1> <div class="job-card-toggle" id="table"></div> <div class="job-card-toggle active" id="tile"></div> </div>';
	$( ".jobTable .jobTitle a" ).each(function( index ) {
		
		var jobTitle = $( this ).html();
		var jobLink = $( this ).attr('href');
		var jobLocation = $( this ).parent().siblings('.jobLocation').html();

		html += '<a href="' + jobLink + '">';
		html += '<div class="job-card">';
		html += '<h1>' + jobTitle + '</h1>';
		html += '<h2>' + jobLocation + '</h2>';
		html += '<div class="applylinks">View</div>';
		html += '</div>';
		html += '</a>';
	});

	$(toggleBar + "<div id='job-cards'> " + html+"<div class='clear' /></div>").insertAfter('.jobTable');
	$('.jobTable').hide();

	$('body').on('click', '.job-card-toggle:not(.active)', function(event) {
		$(this).addClass('active').siblings('.job-card-toggle').removeClass('active');
		var  jobCardHeight = $('#job-cards').height();
		$('#job-cards').height(jobCardHeight);
		$('.job-card').fadeOut(300).delay(300).fadeIn(300);
		setTimeout(function() {
			$('.job-card').toggleClass('alt');
		}, 300);
	});

});


// START OF ALL INTERACTIVE FUNCTIONS
$(function(){
	//AUTOMATIC EXPLORE CARD TITLES, IMGS AND LINKS
	//Switch your your navigation
	$('#headernavigation li').not('.active').each(function(index, el) {

		var page_title = $('a', this).text(); 
		var page_link = $('a', this).attr('href'); 
		var slider_img = $('#inner-slideshow img').eq(index).attr('src'); 

		console.log(slider_img);
		console.log('index is = ' + index);

		$('.explore-card').eq(index).find('h1').html(page_title);
		$('.explore-card').eq(index).find('a').attr('href', page_link);
		$('.explore-card').eq(index).find('img').attr('src', slider_img);

		if (index > 1) {
			return false;
		}
	});


	$('#inner-slideshow > p').children().prependTo('#inner-slideshow');
	$('#inner-slideshow > p').remove();
	$('#outer-slideshow').flexslider({
		selector: "#inner-slideshow > img",
		initDelay: 0,
		animationSpeed: 1100, 
		slideshowSpeed: 4500,
		animation: "fade",
		start: function(slider){
		        // $('#inner-slideshow').removeClass('loading');
		    }
		});




		$(function(){
	//MOBILE NAV
	var mobile_nav = function(menu_container,mobile_nav) {

	//Insert neccesary html
	$(menu_container).append('<div id="rect1" /><div id="rect2" /><div id="rect3" />');
	$('<div id="mobile_back"></div>').insertBefore($(menu_container).parent());
	
	//Assign vatiables
	var animating = false,
	toCloseIcon = true,
	list_item = mobile_nav + ' li';
	back = '#mobile_back';

	//Click event
	$(menu_container + ', ' + back + ',' + mobile_nav).click(function(){
		console.log(animating);
		if (!$(mobile_nav).hasClass('nav-open') && !animating) {
			animating = true;
			$(menu_container).addClass('animate');
			var t_delay = 300;
			$(back).fadeIn();
			$(list_item).each(function(){
				$(this).delay(t_delay).fadeIn(500);
				t_delay += 50;
			});
			$('#topbar h5').fadeIn();
			$(list_item + ', ' + menu_container).promise().done(function(){
				animating = false;
			});
			$(mobile_nav).addClass('nav-open');
		} else if(!animating) {
			animating = true;
			$(menu_container).removeClass('animate');
			$(list_item).fadeOut();
			$(back).fadeOut();
			$(list_item +', ' + back + ', ' + menu_container).promise().done(function(){
				animating = false;
			});
			$(mobile_nav).removeClass('nav-open');
			$('#topbar h5').fadeOut();
		}
	});
	
}
mobile_nav('.Menu', 'ul#mobilenavigation');
});



	// TAB SYSTEM
	var tabNav = $('ul#tabnav'),
	tabNavButtons = $('ul#tabnav li'),
	tabContent = $('div#tabs > div');

	$(tabNavButtons[0]).attr('id','active');
	$(tabContent[0]).show();

	tabNav.on('click','li',function(e){
		e.preventDefault();
		curTab = $(this),
		target = curTab.children().attr('href');

		curTab.stop().attr('id','active')
		.siblings('li')
		.removeAttr('id');

		$('div#'+target).stop().show('slow')
		.siblings('div')
		.stop()
		.hide('slow');
	});

		// PROFILE BOX GRID
		$('.boxgrid.captionfull').hover(function(){
			$(".cover", this).stop().animate({
				bottom:'0px'
			},{queue:false,duration:160});

		}, function() {
			$(".cover", this).stop().animate({
				bottom:'-100%'
			},{queue:false,duration:160});
		});

		// FAQS ACCORDIAN
		var expander = $('.expand'),
		collapser = $('.collapse');

		expander.click(function(){
			$(this).next('.collapse').slideToggle(250)
			.siblings('.collapse')
			.slideUp(250);

			$(this).toggleClass('open')
			.siblings(expander)
			.removeClass('open');
		});
	});



document.getElementById("outer-footer").parentElement.style.display = "flex";

$(".moveIt").appendTo("#jobsGoesHere");

