/*
	eclipse-creative.com
	
	20091215	tomc
*/

// ------------------------------------------------------------------------------------------
/*
	MENU INTERFACE
*/
// ------------------------------------------------------------------------------------------
var Menu = new Class({
	
    Implements		: Options,
    options			: {
		ul			: null
	},
    
	/*
		CONSTRUCTOR
	*/
	initialize: function(options){
        this.setOptions(options);
    }
});

// ------------------------------------------------------------------------------------------
/*
	SUB MENU
*/
// ------------------------------------------------------------------------------------------
var SubMenu = new Class({
    Implements		: Options,
    options			: {
		ul			: null,
		parent		: null
	},
    
	/*
		CONSTRUCTOR
	*/
	initialize: function(options){
        this.setOptions(options);
		
		if( !this.options.parent || !this.options.ul ){
			throw("missing element option");
			return;
		}
		
		/*
			CREATE WRAPPING DIV
			ul will need to slide within this
		*/
		div = new Element("div",{ "class":"sub-wrapper"}).inject(this.options.ul, "before");
		
		this.options.ul.inject( div, "top" );
		
		// todo: alot of this stuff can transfer into the stylesheet // 
		this.options.ul.removeClass( "abs" );
		this.options.ul.setStyle( "display", "block" );
		this.options.ul.slide('hide');
		
		this.options.parent.removeEvents("mouseenter");
		this.options.parent.removeEvents("mouseleave");
		
		this.options.parent.addEvents({
			mouseenter:function(e){
				
				this.options.ul.slide('in');
				this.options.parent.morph({backgroundColor:"#c8161d"});
				this.options.parent.getElement("a").morph({color:"#ffffff"});
				
			}.create({
				event	:true,
				bind	:this
			}),
			mouseleave:function(e){
				
				this.options.ul.slide('out');
				this.options.parent.morph({backgroundColor:"#ffffff"});
				this.options.parent.getElement("a").morph({color:"#000000"});
				
			}.create({
				event	:true,
				bind	:this
			})
		});
    }
});


/*
	ENTRY
*/
window.addEvent("domready", function(){
	
	
	new Menu({
		ul		:$("top-menu")
	});
	
	
	$$("ul.top-menu li.item").each(function(li,i,v){
		li.addEvents({
			
			mouseenter:function(e){
				this.morph({backgroundColor:"#ffffff"});
				this.getElement("a").morph({color:"#c8161d"});
			},
			
			mouseleave:function(e){
				this.morph({backgroundColor:"#ffffff"});
				this.getElement("a").morph({color:"#000000"});
			}
		});
		
		
		if( sub = li.getElement("ul.sub-menu") ){
			
			new SubMenu({
				ul		:sub,
				parent	:li
			});
			
		}
	});
	
	
	document.getElement("ul.top-menu li.booknow").addEvents({
		mouseenter:function(){
			this.get('morph').cancel();
			this.setStyles({borderColor:'#940609'});
		},
		mouseleave:function(){this.morph({borderColor:'#ffffff'});}
	});
	
	
	
	
	
	
	
	
	
	
	
	
	

});











