document.observe('dom:loaded', InitMenu);

Event.observe(window, 'load', function(){
	if ($('accordion'))
		$('accordion').setStyle({ display: 'block' });
});

Effect.Accordion = function(contentId) {
    var slideDown = 0.5; /* The speed the contents should slide down */
    var slideUp = 0.15; /* The speed the contents should slide up */

    contentId = $(contentId); /* Get the object associated with the passed contentId */
    /* Is the passed object already visible? */
    if (contentId.visible(contentId))
        new Effect.SlideUp(contentId, {duration: slideUp});
    else
        new Effect.SlideDown(contentId, {duration: slideDown});
};
			
var currentPage = '';
			
function InitMenu() {
	new Pinwheel('menu', {
		firstChoiceAngle: 'right',
		distance: 125,
		chosenClassName: 'chosen',
		durationOpen: 0.75,
		durationClose: 0.5,
		mouseover: [ Pinwheel.Mouse.Over.raise, function(choice) { new Effect.Opacity(choice, { duration: 0.25, to: 1.0 }); } ],
		mouseout: [ function(choice) { new Effect.Opacity(choice, { duration: 0.25, to: 0.5 }); } ],
		beforeOpen: function() { currentPage = $F('menu'); new Effect.Opacity(this.currentChoice, { duration: 0.75, to: 0.5 });  },
		openEffects: { spiral: {direction: 'clockwise' }, opacity: { chosen: false, from: 0, to: 0.5 } },
		beforeClose: function() { new Effect.Opacity(this.currentChoice, { duration: 0.5, to: 1 }); },
		afterClose: function() { FetchPage($F('menu')); },
		closeEffects: { spiral: {direction: 'counterclockwise' }, opacity: { chosen: false, to: 0 } },
		selected: function() { $(this).setOpacity(1.0); },
		populate: Pinwheel.Populate.cssSprite('images/buttons.png', {
			options: ['home', 'author', 'code', 'errata', 'media'],
			get: function(value) {
				return { x: -102 * this.options.indexOf(value) };
			}
		}),
		size: 102
	});
}

function FetchPage(p) {
	if (currentPage != p) {
		if (p == 'home')
			window.location.href = 'index.php';
		else
			window.location.href = p + '.php';
	}
}