$(document).ready( function() {
	
	// Contact form is ajax
	var formAttr = $('form').attr('action')+'?ajax=true';
	$('form').attr('action', formAttr).ajaxForm({
		success: function(resp) {
			$('.contact_text').html(resp);
		},
		beforeSubmit: function() {
			$('.contact_text').html('<p>Skickar...</p>');
		}
	});
	
	// Add class when JS loaded for accessible CSS selectors
	$('body').addClass('hasJs');

	// Hide all sections but the first one
	$('.section:gt(0)').hide();
	
	// Add interactivity to menu items
	$('.mainmenu a').click( function() {
		
		// Get the index of the clicked menu item
		var thisIndex = $('.mainmenu a').index(this);

		// Define arrow positions
		var arrowPos = [];
		arrowPos[0] = 105;
		arrowPos[1] = 215;
		arrowPos[2] = 305;
		arrowPos[3] = 383;
		arrowPos[4] = 464;
		
		// Animate arrow, with CSS3 animations if possible
		awesomeBrowser = true;
		
		if(awesomeBrowser==true) {
			$('.arrow').css({ left: arrowPos[thisIndex] });
		}
		else {
			$('.arrow').animate({ left: arrowPos[thisIndex] });
		}
		
		// Hide and show corresponding section
		$('.section').hide();
		$('.section:eq('+thisIndex+')').show();
		return false;
	});
	
	// Add the animated arrow to the menu
	$('.head').append('<div class="arrow"></div>');
	
});
