var circleA, circleB;
var navCoordinates = new Array();

window.addEvent('domready', function() {
	circleA = $$('header .circle-a')[0];
	circleB = $$('header .circle-b')[0];
	
	if (circleA) circleA.mFx = new Fx.Morph(circleA, {duration: 500, transition: Fx.Transitions.Quart.easeInOut}).set({'top': '-24px', 'left': '-100px'});
	if (circleB) circleB.mFx = new Fx.Morph(circleB, {duration: 500, transition: Fx.Transitions.Quart.easeInOut}).set({'top': '-24px', 'left': '-100px'});
	
	$('headerLogo').addEvent('mouseenter', function() {
		if (circleA) circleA.mFx.pause();
		if (circleB) circleB.mFx.pause();
		if (circleA) circleA.mFx.start({'top': '-24px', 'left': '-70px'});
		if (circleB) circleB.mFx.start({'top': '-54px', 'left': '-90px'});
	});
	
	$('headerLogo').addEvent('mouseleave', function() {
		if (circleA) circleA.mFx.pause();
		if (circleB) circleB.mFx.pause();
		if (circleA) circleA.mFx.start({'top': '-24px', 'left': '-100px'});
		if (circleB) circleB.mFx.start({'top': '-24px', 'left': '-100px'});
	});
	
	navCoordinates[0] = {'a': {'top': -29, 'left': -70}, 'b': {'top': -54, 'left': -90} };
	navCoordinates[1] = {'a': {'top': -34, 'left': -110}, 'b': {'top': -44, 'left': -70} };
	navCoordinates[2] = {'a': {'top': -29, 'left': -120}, 'b': {'top': -54, 'left': -60} };
	navCoordinates[3] = {'a': {'top': -54, 'left': -140}, 'b': {'top': -34, 'left': -50} };
	
	$('nav').getElements('a').each(function(el, it) {
		el.addEvent('mouseenter', function() {
			if (circleA) circleA.mFx.pause();
			if (circleB) circleB.mFx.pause();
			if (circleA) circleA.mFx.start({'top': navCoordinates[it].a.top + (Math.floor(Math.random()*11) - 5) + 'px', 'left': navCoordinates[it].a.left + (Math.floor(Math.random()*11) - 5) + 'px'});
			if (circleB) circleB.mFx.start({'top': navCoordinates[it].b.top + (Math.floor(Math.random()*11) - 5) + 'px', 'left': navCoordinates[it].b.left + (Math.floor(Math.random()*11) - 5) + 'px'});
		});
		el.addEvent('mouseleave', function() {
			if (circleA) circleA.mFx.pause();
			if (circleB) circleB.mFx.pause();
			if (circleA) circleA.mFx.start({'top': '-24px', 'left': '-100px'});
			if (circleB) circleB.mFx.start({'top': '-24px', 'left': '-100px'});
		});
	});

});
