$(function () {

	$('body > nav a[href="'+window.location.pathname+'"]').addClass('current');

	var current = 0;
	$('body > nav > ul > li').each(function (index,element) {
		current = (new RegExp($(element).attr('data-regex'))).test(window.location.pathname) ? index : current;
	});
	showTab(current);

	$('body > span.navigation').click(function (event) {
		$('body > nav')
			.slideDown(500);
		$(event.target).fadeOut(500);
		return false;
	});
	
	$('body > nav > ul li').click(function (event) {
		var index = $(event.target).attr('data-index');
		showTab(index);
	});
	
	$('body > nav > span').click(function () {
		$('body > nav').slideUp(500);
		$('body > span.navigation').fadeIn(500);	
	});
	
	if ( $('body > table').length > 0 ) {
		
		$(window).resize(function () {
			$('body > span.navigation').each(controlVisibility);
		});
		
		controlVisibility(0,$('body > span.navigation'));
		
	}

	
	function controlVisibility (index,element) {
		if ( $(window).width() < 1003 ) {
			$(element).hide();
		}
		else {
			$(element).show();
		}
	}
	
	function showTab (index) {
		$('body > nav > ul li')
			.removeClass('active')
			.filter(':eq('+index+')').addClass('active');
		$('body > nav > section')
			.removeClass('active')
			.filter(':eq('+index+')').addClass('active');
	}
	
});
