jQuery(function($){
	var MegaMenu = function(){
		var $mainMenu = $('#navMainTopLevel ul');

		if ($mainMenu.length === 0) {
			return;
		}
						
		$('#navMain .navMainSecondLevel').each(function(){
			$mainMenu.find('> li:eq('+$(this).attr('title')+')').append(this);
			$(this).removeAttr('title');
		});
		
		$mainMenu.find('> li').each(function(index){
			$(this).addClass('item-'+index);
		}).mouseenter(function(){
			$(this).find('.navMainSecondLevel').fadeIn('fast');
		}).mouseleave(function(){
			$(this).find('.navMainSecondLevel').fadeOut('fast');
		});
		
	};
	
	MegaMenu();
});

jQuery(function($){
	
	var discountCodes = {
		'newmvo' : 'Thank you. &nbsp;Your free Gentle Cleanser will be sent with your other purchases.',
                'leamvo' : 'Your free mist will be sent with your other purchases.  Specify Gentle Mist or Anti Aging Mist in the Special Instructions area on the Checkout page.',
                'svmomsmvo' : 'Thank you. Your free Gentle Cleanser will be sent with your other purchases.',
                'Story' : 'Thank you. Your free Anti Aging Mist will be sent with your order.',
		'BabyElan' : 'Thank you.  Your free 1/8 oz MFS Plus sampler will be included in your order.',
		'BabyScoop' : 'Thank you.  Your free MFS+ sampler trio (medium tint, light tint and no tint) will be included in your order.',
		'FaceOil' : 'Thank you.  Your free 1/4oz Face Oil will be included in your order.',
		'skinlightening' : 'Thank you.  Your free Vitamin C Supplement will be included in your order.',
		'HYDRATE' : 'Thank you.  Your free Anti-Aging Mist will be included in your order.',
		'Blommi' : 'Thank you.  Your Moisturizing Face Screen sampler trio (light, medium and no tint) will be included in your order.',
		'DaySerum' : 'Thank you.  Your AA Day Serum 1/8 oz trio sampler will be included in your order.',
		'VivaFaceOil' : 'Thank you.  Your 1/4 oz Anti-Aging Oil+ will be included in your order.',
		'VIVA' : 'Thank you.  Your free sample-size Skin Lightening Serum will be included in your order.'
        }
	
	var checkDiscountCode = function(){		
		
		if (typeof ApplyDiscountCode !== 'function') {
			return;
		}
		
		var _func = ApplyDiscountCode;
		
		ApplyDiscountCode = function(){
			_func.apply(this, arguments);

			var val = $('#DiscountCode').val();
			
			if (discountCodes.hasOwnProperty(val)){
				if ($('#discount-code-message').length > 0) {
					return;
				}
			
				$('#DiscountCode').parent().append('<span id="discount-code-message">'+discountCodes[val]+'</span>');				
			}
			
			else {
				$('#discount-code-message').remove();
			}
			
		};
	};
	
	checkDiscountCode();
});