var action= new Array();
var action2= new Array();



document.observe('dom:loaded',function(){
	if(!$('myGallery307')){
		init_menu();
		initFolder();
	}
});

	function initFolder(){
	
		$$('.folder').each(function (element,index) {
			
			cont = element.down().innerHTML;
			cont = cont.replace(/ /ig,"+");
			anker = self.document.location.hash.substring(1);
			action2[index] = {
					effect: null,
					height: element.down('div').getHeight()
			};
			
			element.down('div').setStyle({ overflow: "hidden" });
			
			if(cont!=anker){
				element.down("div").setStyle({ height: "0px" });
			}else{
				element.className = 'folder opened';	
			}
			 
			
			
			element.down("div").show();
			
			element.down().observe('click', function(){
				elem = element.down().next();
				
				
				
				if(!element.className.match('opened')){
					
					if(action2[index].effect) action2[index].effect.cancel();
					
					action2[index].effect = new Effect.Morph(elem, {
						duration: 0.5,
						style: {
							height: action2[index].height + "px",
							display: "block"
						}
					});
					element.className = 'folder opened';
				}else{
					if(action2[index].effect) action2[index].effect.cancel();
					action2[index].effect = new Effect.Morph(elem, {
						duration: 0.5,
						style: {
							height: "0px",
							display: "none"
						}
					});
					element.className = 'folder'
				}
				
			});	
		}, this);
		
	}
	
	
	function init_menu(){
	
		
		$$('.sub').each(function(element){
			element.removeClassName('sub');
			element.addClassName('subjs');
			element.setStyle({ overflow: "hidden" });
			element.hide();
		});
		
		$$('#navigation li').each(function (element,index) {
			
			element.setStyle('position:relative;');
			
			if(element.down("ul")){
				//-----------
				
				action[index] = {
					effect: null,
					height: element.down("ul").getHeight()
				};
				
				element.down("ul").setStyle({ height: "0px" });
				element.down("ul").show();
			//-----------	
				element.observe('mouseenter', mouseEnterEvent.bindAsEventListener(this, element.down("ul"), index));
				//-----------
				element.observe('mouseleave', mouseLeaveEvent.bindAsEventListener(this, element.down("ul"), index));
			//-----------
			}
			
		});
	}
	
	function mouseEnterEvent(event) {
		var args = $A(arguments);
		var element = args[1];
		var index   = args[2];
		
		el = element;
		
		if (action[index].effect != null) {
			action[index].effect.cancel();
			action[index].effect = null;
		}
		
		action[index].effect = new Effect.Morph(el, {
			duration: 0.5,
			style: {
				height: action[index].height + "px"
			}
		});
	}
	
	function mouseLeaveEvent(event) {
		var args = $A(arguments);
		var element = args[1];
		var index   = args[2];
		
		el = element;
		
		if (action[index].effect != null) {
			action[index].effect.cancel();
			action[index].effect = null;
		}
		
		action[index].effect = new Effect.Morph(el, {
			duration: 0.5,
			style: {
				height: "0px"
			}
		});
	}
