/* hello moonbabies! */

limit=0;
t=0;

points = [[100,100],[500,500],[1000,300],[500,60],[100,100]];
point = 0;

$(document).ready(function(){
	if($(window).width()<480)
	{
		//mobile browser so do nothing
	}
	else
	{
		faerieNext();//set faerie moving
		faerieDust();//start dust dusting
		$('#faerie').css('display','block').mouseover(function(){point+=6;});
	}
});

fillPoints = function(points,resolution)
{ //interpolates two points with n=resolution points, in a quarter-sine/cos wave fashion
	out=new Array();
	for(i=0;i<points.length-1;i++)
	{
		for (j=0;j<resolution;j++)
		{
			out.push(new Array(
				points[i][0]+Math.sin(j/resolution*Math.PI/2)*(points[i+1][0]-points[i][0]),
				points[i][1]+(1-Math.cos(j/resolution*Math.PI/2))*(points[i+1][1]-points[i][1]))
			);
		}
	}
	return out;
}

points = fillPoints(points,15);

function createDust(x,y)
{	//create dust at a point
	fadetime = 800; //this is the time in milliseconds that the stars take to fade
	varience = 20;	//this is the distance in pixels that the stars' start position is allowed to vary by
	
	$i=$('<img/>');
	$i.attr('src','images/dust_b.gif');
	$('body').append($i);
	x = x+Math.floor((Math.random()*varience))-(varience/2)+20;
	y = y+Math.floor((Math.random()*varience))-(varience/2)+20;
	$i.css('position','absolute').css('left',x+'px').css('top',y+'px').css('z-index',1);
	$i.animate({opacity:0},fadetime,function(){$(this).remove();})
}

function faerieDust()
{	//find faerie and add dust by it
	x=$('#faerie').offset().left;
	y=$('#faerie').offset().top;
	createDust(x,y);
	setTimeout(faerieDust,40);
}

faerieNext = function()
{	//get faerie to move to next point
	point=(point+1)%points.length;
	x=points[point][0];
	y=points[point][1];
	$('#faerie').animate({'left':x+'px','top':y+'px'},200,faerieNext);
}
