// Start functioning when DOM is ready
$( function() 
{
	// Get the parameters
	var params = getParams();
	
	// Check if a Permalink isset
	var pl = params.pl || null;
	
	// Check if the Permalink was set
	if ( pl )
	{
		// Set lock to true
		lock = true;
		
		// Get the targeted element
		var trgt = $('#preview-panel > li > div[rel="project_'+pl+'"]');
		
		// Set effect counter
		fxc = 0;
		
		// Get index of the clicked preview
		fxi = $('#preview-panel > li').index( trgt.parent() );
		
		// Get the related project
		var p = 'project_'+pl;
		
		// Get the active project
		var ap = $('.current-slide').attr( 'id' );
		
		// Stop further functioning if the project
		// is the same as the active project
		if ( p == ap ) { lock=false; return; }
		
		// Get the corresponding project index of
		// the clicked preview
		var pi = $('#slides > li').index( $('#'+p) );
		
		// Height of a slide
		var sh = -365;
		
		// Fix IE bug
		if ( /MSIE/.test(navigator.userAgent) ) sh -= 5;
		
		// Math the offset top
		var t = (pi * sh);
		
		// deselect current-(sub)slides
		$('.current-slide').removeClass( 'current-slide' );
		$('.current-subslide').removeClass( 'current-subslide' );
		
		// Set the correct project to current
		$('#'+p).addClass( 'current-slide' );
		
		// Scroll to the correct project
		$('#slides').animate( {top: t+'px'}, 800, 'easeOutQuint', function() {
			// Set lock to false
			lock = false;
		});
		
		// Get project data
		var html = $('#'+p+' .project_data').html();
		
		// Empty old project data and set new data
		$('#viewmore')
			.empty()
			.html( html );
		
		// Update the preview panel
		moveUp( repeater2 );
	}
});

// Set function to repeat the move
var repeater2 = function()
{
	// Check if the counter hasn't reached the same
	// value as the effect max
	if ( fxc < fxi ) moveUp( repeater2 );
	
	// Increment fxc
	fxc++;
}

/**
 * Function to get the parameters from the URI
 * @return	Array
 */
var getParams=function(){var a=window.location.href;var b=new Array();var c=a.split('?');if(typeof c[1]=='undefined')return false;var d=c[1].split('&');for(p in d){var e=d[p].split('=')[0];var f=d[p].split('=')[1];b[e]=f}return b};