(function(jQuery) {			
	jQuery.fn.rcMenu = function(options) {
		// DEFINE SOME DEFAULT SETTINGS
		jQuery.fn.rcMenu.defaults = {
			'delay': 200,
			'transition': 'slideDown',
			'hoverEffect': 'raiseUp',
			'equaliseHeight': false,
			'animateOnLoad': true,
			'isOnInnerPage': true
		}
		
		var opts = jQuery.extend({}, jQuery.fn.rcMenu.defaults, options);
		
		return this.each(function(){
			var el = jQuery(this),
				kids = el.children(),
				delay = opts.delay;
			
			// IF REQUIRED, PAD THE TOP OF THE MENU SO IT APPEARS VERTICALLY CENTERED AGAINST A COMPARING COLUMN
			if(opts.equiliseHeight) {
				var compColHeight = jQuery(opts.equiliseHeight).height();
				var menuHeight = el.height()
				
				if(compColHeight > menuHeight) {
					el.css({'paddingTop': (compColHeight - menuHeight) / 2 + 'px'});
				}
			}
			
	
			// ANIMATE THE ELEMENTS ONTO THE PAGE
			if(opts.isOnInnerPage) {
				el.show()
					.find('li:not(:first)').hide()
					.end().find('li:first').css({'cursor': 'pointer'});
					
				el.hover(function() {
					jQuery(this).children().stop(true, true).slideDown(300);
				}, function() {
					jQuery(this).children().not(':first').stop(true, true).slideUp(200);
				}).click(function() {
					jQuery(this).children().not(':first').stop(true, true).slideToggle(200);
				});			
			} else {
				kids.find('div').hide().end().hide();				
				kids.delay(300).each(function(){
					switch(opts.transition) {
						case 'slideDown':
							jQuery(this).delay(delay).slideDown();
							break;
						
						case 'fade':
							jQuery(this).delay(delay).fadeIn();
					}						
					delay += opts.delay;
				});
			}
			
			// ADD AN EFFECT ON MOUSEOVER
			kids.has('a').each(function(){
				switch(opts.hoverEffect) {
					case 'none':
						break;
					case 'nudgeBackground':
						jQuery(this).hover(function(){
							jQuery(this).stop(true, true).animate({'backgroundPosition': '-135px'}, 300).find('div').fadeIn(300);	
						}, function(){
							jQuery(this).stop(true, true).animate({'backgroundPosition': '-125px'}, 300).find('div').fadeOut(300);	
						})							
						break;
					
					case 'raiseUp':
						jQuery(this).hover(function(){
							jQuery(this).stop(true, true).animate({'marginTop': '-10px'}, 300).find('div').fadeIn(300);	
						}, function(){
							jQuery(this).stop(true, true).animate({'marginTop': '0px'}, 300).find('div').fadeOut(300);	
						})
						break;	
				}
			})
		});
	}
})(jQuery);		
