// CONTENTS ====================================================================
/*
- 
*/

// ======================================================================
function InitNav(){
	// add span to act as indicator and spac to cover it
	$("#navigation li").each(function(){
		$(this).append("<span class='ind'></span><span class='cover'></span>");	
	})
	
	// set behaviours on nav links
	$('#navigation a')
	.mouseover(function(){
		if( !$(this).parent().hasClass("selected") ){
			
			$(this).siblings(".ind").stop().animate(
				{bottom:-10},
				{duration: 150}
			)
			
		}
	})
	.mouseout(function(){
		if( !$(this).parent().hasClass("selected") ){
			
			$(this).siblings(".ind").stop().animate(
				{bottom:0},
				{duration: 150}
			)
			
		}
	})
	
	// remove divider from li preceeding selected
	$("#navigation li.selected").prev().css("background", "none");
	
}

function HomeHeroAnim(){
	
	$("#home-positioning-statement").css("right", "-380px")
	.animate(
		{opacity: 1.0}, 
		{duration: 2000}
	)
	.animate(
		{right: 0},
		{duration: 1000}
	)
	
}

function InitPortfolio(){
	$(".portfolio-list a").append( "<img src='/images/Detail/overlay-portfolio-thumb.png' class='overlay' width='60' height='60' alt='Overlay' />" );
	$(".portfolio-list a").colorbox();

	$('.content-image a').colorbox();
}

function InitGrid(){
	
	// create a duplicate to keep for rollover
	$(".grid-list li a img").each(function(){
		$(this).attr("class", "desaturated");
		$(this).clone().appendTo( $(this).parent() ).attr("class", "saturated");
	})
	
	// desaturate originals via pixastic (http://www.pixastic.com/lib/docs/)
	$(".grid-list li a img.desaturated").pixastic("desaturate");
	$(".grid-list li a canvas").width(118);
	$(".grid-list li a canvas").height(118);
	
	// fade em off
	$(".saturated").animate(
		{opacity: 0},
		{duration: 1}
	)
	
	// mouse actions

	$(".grid-list li a").mouseover(function() {
		$(this).children(".saturated").stop().animate(
		{ opacity: 1 },
		{ duration: 500 }
	);
	})
	.mouseout(function() {
		$(this).children(".saturated").stop().animate(
			{ opacity: 0 },
			{ duration: 500 }
		);
	});
}

function RandomiseLists() {
	
	RandomiseElements('#sidebar-menu li');
	RandomiseElements('.grid-list li');
}

function RandomiseElements(elmSelector) {
	
	var parent = $(elmSelector).parent();

	var newListArray = $(elmSelector);
	var counter = 0;
	var maxLength = $(elmSelector).length;

	while ($(elmSelector).length > 0 && counter < maxLength) {
		var randomEl = $(elmSelector).eq(Math.round(Math.random() * $(elmSelector).length));
		newListArray[counter] = randomEl;
		counter++;
		randomEl.remove();
	}
	
	var timeCounter = 0;
	
	//instant show
	for (timeCounter = 0; timeCounter < newListArray.length; timeCounter++) {
		if (newListArray[timeCounter] != 'null' && newListArray[timeCounter] != null && newListArray[timeCounter] != 'undefined') {
			parent.append(newListArray[timeCounter]);
		}

		if (elmSelector != '#sidebar-menu li') {
			$(elmSelector).eq(timeCounter).removeClass('row-end');
			if ((timeCounter + 1) % 5 == 0) $(elmSelector).eq(timeCounter).addClass('row-end');
		}
	}
	
	//timed show fadein
	/*
	var TimedFadeIn = self.setInterval(
		function() {

			if (newListArray[timeCounter] != 'null' && newListArray[timeCounter] != null && newListArray[timeCounter] != 'undefined') {
				parent.append(newListArray[timeCounter]);
			}

			$(elmSelector).eq(timeCounter).removeClass('row-end').fadeIn(400);
			if ((timeCounter + 1) % 5 == 0) $(elmSelector).eq(timeCounter).addClass('row-end');

			timeCounter++;

			if (timeCounter >= newListArray.length) {
				TimedFadeIn = window.clearInterval(TimedFadeIn);
				Equalise(elmSelector);
				
			}

			console.log(timeCounter + ' timeCounter ' + newListArray.length + ' total items');

		},
		150
	);
	*/
}