window.addEvent('load', function() {
	$$('.slideshow').each(function(e) {
		new Slideshow({slideTarget:e, hasButtons:true, slideDuration:10000});
	});
});

window.addEvent('domready', function() {
	$(document.body).removeClass('js-disabled');
	/* Navigation */
	$$('#mainnav_sleeve>ul>li').addEvents({
		'mouseenter':function() {
			this.addClass('over');
		},
		'mouseleave':function() {
			this.removeClass('over');
		}
	});

	$$('#mainnav_sleeve>ul>li>a').addEvent('focus', function() {
		$$('#mainnav_sleeve>ul>li.over').removeClass('over');
		this.getParent().addClass('over');
	});

	$$('#mainnav_sleeve>ul>li div li:last-child a').addEvent('focus', function() {
		this.getParents('li')[1].addClass('over');
	});

	/* Mast Search Area Toggle */
	$$('#mast_search a').addEvent('click', function(e) {
		e.stop();
		this.getParent().toggleClass('open');
	});

	/* Sponsors */
	var counter = 0;
	var howManySponsors = $$('#sponsors li').length;

	if(howManySponsors > 1) {
		$$('#sponsors li').each(function(e) {
			e.setStyle('z-index',(99-counter));
			counter++;
		});

		counter = 0;
		function RotateSponsors() {
			if((counter+1) == howManySponsors) {
				counter = 0;

				$$('#sponsors li')[counter].fade('in');
				$$('#sponsors li')[(counter+howManySponsors)-1].fade('out');
			} else {
				/* Start next round */
				$$('#sponsors li')[counter].fade('out');
				$$('#sponsors li')[counter+1].fade('in');
				counter++;
			}
		}

		RotateSponsors.periodical(5000);
	}

	/* Author Bio slider */
	if($defined($$('.author_bio')[0])) {
		$$('.author_bio')[0].setStyles({'height':$$('.author_bio')[0].getSize().y,'display':'none'});
		$$('.author_more').addEvent('click', function(e) {
			e.stop();
			new Fx.Reveal($$('.author_bio')[0]).toggle();
		});
	}

	/* Flickr Footer Milkbox */
	$$('#flickr li a').addEvent('click', function() {
		$(document.body).addClass('milkboxopen');
	});
});
