YUI().use('node', 'anim-base', function (Y) {
	Y.on('mouseenter', function (e) {
		
		if (e.container.animCollapse != null)
			e.container.animCollapse.stop();
		
		if (e.container.animExpand == null) {
			e.container.animExpand = new Y.Anim({
		        node: e.container,
		        to: { height: 146 },
				duration: 0.1
		    });
		}
		
		e.container.animExpand.run();
		
		if (e.container.childsShow == null)
			e.container.childsShow = e.container.queryAll('.toggleshow');
		
		e.container.childsShow.each( function(nodes, index, nodeList) {
			
			if (nodes.hideRElem != null)
				nodes.hideRElem.stop();
			
			if (nodes.showRElem == null) {
				nodes.showRElem = new Y.Anim({
			        node: nodes,
			        to: {opacity: 0},
					duration: 0.1
		    	});
			}
			nodes.showRElem.run();
		});
		
		e.container.animExpand.on('end', function(ev) { 
			var target = ev.target._node;
			
			if (target.childsHide == null)
				target.childsHide = target.queryAll('.togglehide');
				
			target.childsHide.each( function(node, index, nodeList) {
				if (node.hideElem != null)
					node.hideElem.stop();
				
				if (node.showElem == null) {
					node.showElem = new Y.Anim({
				        node: node,
				        to: {opacity: 1},
						duration: 0.2
			    	});
				}
				node.showElem.run();
			});
			
		});
		
		
	}, '.overbox');
	
	Y.on('mouseleave', function (e){
		
		if (e.container.animExpand != null)
			e.container.animExpand.stop();
		
		if (e.container.animCollapse == null) {
			e.container.animCollapse = new Y.Anim({
				node: e.container,
				to: {
					height: 99
				},
				duration: 0.4
			});
		}
		
		e.container.animCollapse.run();
		
		//e.container.animCollapse.on('end', function (evh){
			//var targeth = evh.target._node;
			var targeth = e.container;
			
			if (targeth.childsHide == null)
				targeth.childsHide = targeth.queryAll('.toggle');
			
			targeth.childsHide.each(function(nodeh, index, nodeList) {
				
				if (nodeh.showElem != null)
					nodeh.showElem.stop();
				
				if (nodeh.hideElem == null) {
					nodeh.hideElem = new Y.Anim({
						node: nodeh,
						to: {
							opacity: 0
						},
						duration: 0.3
					});
				}
				nodeh.hideElem.run();
			});
			
			if (targeth.childsShow == null)
				targeth.childsShow = targeth.queryAll('.toggle');
			
			targeth.childsShow.each(function(noderh, index, nodeList) {
				
				if (noderh.showRElem != null)
					noderh.showRElem.stop();
				
				if (noderh.hideRElem == null) {
					noderh.hideRElem = new Y.Anim({
						node: noderh,
						to: {
							opacity: 1
						},
						duration: 0.3
					});
				}
				noderh.hideRElem.run();
			});
		//});
		
		
	}, '.overbox');
});
