/*
--------------------------------------------------------------------------------
Decorate the nav list with classes corresponding to their position
Emulates css nth-child functionality
This function is necessary since there is no robust way to style individual
navigation items based on the markup generated by the default wp_list_pages function.
--------------------------------------------------------------------------------
*/
window.addEvent('domready',
	function() {
		$$('.nav li a').each(
			function(link,index) {
				link.addClass('child' + index);
			}
		);
	}
);

/*
--------------------------------------------------------------------------------
Replace links to youtube videos with a video player
--------------------------------------------------------------------------------
*/
window.addEvent('domready',
	function() {
		$$('a[href*=\'youtube\']').each(
			function(link,index) {
				youtubeId = link.getProperty('href').substr(link.getProperty('href').indexOf('?v')+3);
				var youtubeVideo = new Swiff('http://www.youtube.com/v/' + youtubeId, {
				    width: 560,
				    height: 305,
				    params: {
				        wmode: 'opaque',
				        bgcolor: '#000000'
				    }
				});
				
				var videoContainer = new Element('div', {
				    'class': 'youtubeVideo'
				});
				videoContainer.adopt(youtubeVideo);
				videoContainer.replaces(link.getParent());
			}
		);
	}
);