var dropDowns = new Array();

function intiateDropDowns() {
	var i=0;
	$$('.topFlyout').each(function(dropDown){
		dropDowns[i] = new dropDownMenu(dropDown, i);
		i++;
	});
}

var dropDownMenu = Class.create({
	initialize:function(dropDown, currentNumber){
		this.dropDown = dropDown.identify();
		this.position = currentNumber;
		this.open = false;
		
		$(this.dropDown).onmouseover = this.dropMenu.bindAsEventListener(this);
		$(this.dropDown).up().onmouseover = this.dropMenu.bindAsEventListener(this);
		$(this.dropDown).onmouseout = this.pickupMenu.bindAsEventListener(this);
		$(this.dropDown).up().onmouseout = this.pickupMenu.bindAsEventListener(this);
	},
	
	dropMenu:function(){
		for(i=0;i<dropDowns.length;i++){
			if (dropDowns[i].currentlyOpen() && i!=this.position){dropDowns[i].pickupMenu();}	
		}
		if ($(this.dropDown).style.display=='none'){
			this.open = true;
			$(this.dropDown).up().addClassName('hoverDrop');
			new Effect.BlindDown($(this.dropDown),{delay:.0,duration:.4,queue:{scope:$(this.dropDown).id,limit:1,position:'front'}});
		} else {
			this.queueScope = Effect.Queues.get($(this.dropDown).id+'_close');
			this.queueScope.each(function(effect){effect.cancel();});
			$(this.dropDown).up().addClassName('hoverDrop');
		}
	},
	
	pickupMenu:function(){
		if($(this.dropDown).style!='none'){
			this.open = false;
			$(this.dropDown).up().removeClassName('hoverDrop');
			new Effect.BlindUp($(this.dropDown),{delay:.0,duration:.2,queue:{scope:$(this.dropDown).id+'_close',limit:1,position:'front'}});
		}else{
			this.open = false;
			$(this.dropDown).up().removeClassName('hoverDrop');
			this.queueScope = Effect.Queues.get($(this.dropDown).id);
			this.queueScope.each(function(effect){effect.cancel();});
			$(this.dropDown).style='none';
		}
	},
	
	currentlyOpen:function(){
		return this.open;
	}
});
