$(document).ready(function(){
	var deg=0;
	var dif=0;
	var arr = $('.btn');
	var len = arr.length;
	var over=false;
	var centerX = ($('#stage').width() - $('.btn').width())/2;
	var centerY = ($('#stage').height() - $('.btn').height())/2 - 10;
	arr.css('position','absolute');
	setInterval(f2,40);

	function f1 (e){
		if(!this.leftOffset)
		{
			this.leftOffset = $(this).offset().left;
			this.width = $(this).width();
		}
		if(over) dif=0;
		else {dif = -5+(10*((e.pageX-this.leftOffset)/this.width));}
	}

	function f2(){
		deg+=dif;

		$.each(arr,function(i){
			var eSin = -Math.sin(((360/len)*i+deg)*Math.PI/180);
			var eCos = Math.cos(((360/len)*i+deg)*Math.PI/180);

			$(this).css({
				top: centerY + 50*eSin,
				left: centerX + 270*eCos,
				opacity: 0.8 + eSin*0.2,
				zIndex: Math.round(80 + eSin*20)
			});
		})
	}

	$("#rolling").mousemove(f1);
	$("#rolling").mouseout(function(e){dif=0;});
	$(".bcontent").hover(
		function(){over=true; dif=0;},
		function(){over=false;}
	);
});
