/**
 * @author KKelly
 */
YUI().use('node', 'anim', 'node-menunav', function(Y){
	//pre-declare all vars
	var menu = Y.one("#main_nav_wrapper"),
		images = Y.all('#content img.caption');
	/*
	 * Main Menu
	 */
	menu.all(".yui3-menu.first-of-type").each(function(node, nodeIndex, nodeList){
		node.append('<div class="yui3-menu-subnav-indicator"></div>');//create an element in the first sub nav of each main menu item that we can style and position
	});
	
	menu.plug(Y.Plugin.NodeMenuNav, {submenuShowDelay:100});// make the dropdowns show faster
	menu.get("ownerDocument").get("documentElement").removeClass("yui3-loading");
	
	Y.one('html').removeClass('yui3-js-disabled');
	/*
	 * image alt enhancements
	 */
	images.each(function(node, nodeIndex, nodeList){
		var container = Y.Node.create('<div class="img_wrapper"></div>'),
			img = node,
			animFadeIn,
			caption = Y.Node.create('<div class="caption"></div>');
		
		caption.set("innerHTML", img.getAttribute('alt') );
		
		if ( img.hasClass( 'left' ) ){
			container.addClass( 'img_wrapper_left' );
			img.removeClass('left');
		}
		if ( img.hasClass( 'right' ) ){
			container.addClass( 'img_wrapper_right' );
			img.removeClass('right');
		}
		node.replace(container);
		
		container.appendChild( img );
		container.appendChild(caption);
		
		container.setStyle('width', img.getAttribute('width'));
		container.setStyle('height', img.getAttribute('height'));
		caption.setStyle('opacity', 0);
		
		animFadeIn = new Y.Anim({node:caption, to: { opacity:1 }});
		
		animFadeIn.run();
	});
});
