$(document).ready(function(){
	
	//Parallax
	
	$('#nav').localScroll(800);
	
	RepositionNav();
	
	$(window).resize(function(){
		RepositionNav();
	});	
	
	//.parallax(xPosition, adjuster, inertia, outerHeight) options:
	//xPosition - Horizontal position of the element
	//adjuster - y position to start from
	//inertia - speed to move relative to vertical scroll. Example: 0.1 is one tenth the speed of scrolling, 2 is twice the speed of scrolling
	//outerHeight (true/false) - Whether or not jQuery should use it's outerHeight option to determine when a section is in the viewport
	$('#intro').parallax("50%", 0, 0.1, true);
	$('#work').parallax("50%", 0, 0.1, true);
	$('#cliff').parallax("50%", 0, 0.1, true);
	$('.cliff-asset-1').parallax("50%", 2500, 0.3, true);
	$('.cliff-asset-2').parallax("50%", 2500, -0.1, true);
	$('.cliff-asset-3').parallax("50%", 2500, 0.0, true);
	$('#spartdan').parallax("50%", 0, 0.1, true);
	$('.spartdan-asset-1').parallax("50%", 2500, 0.3, true);
	
	
	//Open external links in new window
	
	$("a").filter(function() {
		return this.hostname && this.hostname !== location.hostname;
	}).attr('target', '_blank');
	
	
	//Randomise folio
	
	(function($) {
		// Get the list items and hide them
		var items = $("#folio > a.folio-block");
		var pos = 1;
		while(pos < 5)
		{
			var randelem = Math.floor(Math.random()*items.length)
			if(!$(items[randelem]).hasClass("active"))
				{
					$(items[randelem]).addClass("active");
					$(items[randelem]).addClass("pos-"+pos);
					pos++;
				}
		}	
	});
		
	$(function() {

		window.setInterval(function(){
			$("#folio").randomize(".folio-block");
		}, 5000);

	});

	(function($) {
		$.fn.randomize = function(childElem) {		
			var elems = $(this).children(childElem);
			var check = 0;
			var randelem =0;
			while(check==0)
			{
				randelem = Math.floor(Math.random()*elems.length);
				if(!$(elems[randelem]).hasClass("active"))
				{
					check=1;
				}
			}
			var randshown = Math.floor(Math.random()*4)+1;
			$(".pos-"+randshown).removeClass("active");
			$(".pos-"+randshown).removeClass("pos-"+randshown);
			$(elems[randelem]).addClass("active");
			$(elems[randelem]).addClass("pos-"+randshown);

		}
	})(jQuery);
	
});
