// Lavalamp

var query = new Object();
window.location.search.replace(
new RegExp( "([^?=&]+)(=([^&]*))?", 'g' ),
	function( $0, $1, $2, $3 ){
		query[ $1 ] = $3;
	}
);
easing = query['e'] || 'Expo';

function loadEasing(e) {
	location.href = location.pathname+'?e='+e;
}

function setEasing(e) {
	loadLamps(e);
}

// for dynamic easing changes		
function loadLamps(easing) {
	$('#menuHome').lavaLamp({
		fx: 'easeIn'+easing,
		speed: 200,
		startItem:0,
					returnHome:true,
homeLeft: 10,
homeTop: 5,
homeWidth:59,
homeHeight:30
	});

	$('#menuPortfolio').lavaLamp({
		fx: 'easeIn'+easing,
		speed: 200,
		startItem:1,
					returnHome: true,
homeLeft: 69,
homeTop: 5,
homeWidth:96,
homeHeight:30
	});

	$('#menuServices').lavaLamp({
		fx: 'easeIn'+easing,
		speed: 200,
		startItem:2,
					returnHome: true,
homeLeft: 165,
homeTop: 5,
homeWidth:91,
homeHeight:30
	});

	$('#menuClients').lavaLamp({
		fx: 'easeIn'+easing,
		speed: 200,
		startItem:3,
					returnHome: true,
homeLeft: 256,
homeTop: 5,
homeWidth:84,
homeHeight:30
	});

	$('#menuPartners').lavaLamp({
		fx: 'easeIn'+easing,
		speed: 200,
		startItem:4,
					returnHome: true,
homeLeft: 340,
homeTop: 5,
homeWidth:94,
homeHeight:30
	});

	$('#menuContact').lavaLamp({
		fx: 'easeIn'+easing,
		speed: 200,
		startItem:5,
					returnHome: true,
homeLeft: 434,
homeTop: 5,
homeWidth:89,
homeHeight:30
	});

}
//console.log();

jQuery(function( $ ){

	// Lavalamp

	$('#menu').lavaLamp({fx: 'swing', speed: 333});
	loadLamps(easing);
	
	$('select#easing option[value='+easing+']').attr('selected','selected');
	$('.easingLabel').text(easing);
	
	// ScrollTo

	/**
	 * Demo binding and preparation, no need to read this part
	 */
	//borrowed from jQuery easing plugin
	//http://gsgd.co.uk/sandbox/jquery.easing.php
	$.easing.elasout = function(x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	};

	// Reset the screen to (0,0)
	$.scrollTo( 0 );
	
	// TOC, shows how to scroll the whole window
	$('.menuBar a').click(function(){//$.scrollTo works EXACTLY the same way, but scrolls the whole screen
		$.scrollTo( this.hash, 750, { easing:'elasout' });
		$(this.hash).find('span.message').text( this.title );
		return false;
	});
	
});