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 = {
                'leamvo' : 'Your code has been processed.  A gift will be included with all qualifying orders. One discount item per customer. Thank you!',
                'svmomsmvo' : 'Your code has been processed.  A gift will be included with all qualifying orders. One discount item per customer. Thank you!',
		'skinlightening' : 'Your code has been processed.  A gift will be included with all qualifying orders. One discount item per customer. Thank you!',
		'SunDamage' : 'Your code has been processed.  A gift will be included with all qualifying orders. One discount item per customer. Thank you!',
		'safekids' : 'Your code has been processed.  A gift will be included with all qualifying orders. One discount item per customer. Thank you!',
                'abbys' : 'Your code has been processed.  A gift will be included with all qualifying orders. One discount item per customer. Thank you!',
		'openhouse' : 'Your code has been processed.  A gift will be included with all qualifying orders. One discount item per customer. Thank you!',
		'NATURE' : 'Your code has been processed.  A gift will be included with all qualifying orders. One discount item per customer. Thank you!',
		'protect' : 'Your code has been processed.  A gift will be included with all qualifying orders. One discount item per customer. Thank you!',
		'remodelista' : 'Your code has been processed.  A gift will be included with all qualifying orders. One discount item per customer. Thank you!',
		'Protect' : 'Your code has been processed.  A gift will be included with all qualifying orders. One discount item per customer. Thank you!',
		'roses' : 'Your code has been processed.  A gift will be included with all qualifying orders. One discount item per customer. Thank you!',
		'valentine' : 'Your code has been processed.  A gift will be included with all qualifying orders. One discount item per customer. Thank you!',
		'rose' : 'Your code has been processed.  A gift will be included with all qualifying orders. One discount item per customer. Thank you!',
		'repair' : 'Your code has been processed.  A gift will be included with all qualifying orders. One discount item per customer. Thank you!',
		'AntiWrinkle' : 'Your code has been processed.  A gift will be included with all qualifying orders. One discount item per customer. Thank you!',
		'faceoil' : 'Your code has been processed.  Your gift will be included with all qualifying orders. One discount item per customer. Thank you!',
		'kidsafe' : 'Your code has been processed.  Your gift will be included with all qualifying orders. One discount item per customer. Thank you!',
		'mom' : 'Your code has been processed.  Your gift will be included with all qualifying orders. One discount item per customer. Thank you!',
		'sunscreen' : 'Your code has been processed. Your gift will be included with all qualifying orders.  One discount item per customer. Thank you!',
		'VivaEWG' : 'Your code has been processed. Your gift will be included with all qualifying orders. One discount item per customer. Thank you!',
		'free' : 'Free Shipping on all US and CA Orders Over $100. One discount item per customer. Thank you!',
		'natural' : 'Your code has been processed. Your gift will be included with all qualifying orders. Thank you!',
		'SG2011' : 'Your code has been processed.  Your gift will be included with all qualifying orders.  Thank you!',
		'NewESC' : 'Your code has been processed.  Your gift will be included with all qualifying orders.  Thank you!',
		'NaterTot' : 'Your code has been processed.  Your gift will be included with all qualifying orders.  Thank you!',
		'MVOBabyz' : 'Your code has been processed.  A Moisturizing Face Screen Sample will be included in all qualifying orders.  Thank you!',
		'NaturalMama' : 'Your code has been processed.  A Moisturizing Face Screen Sample will be included in all qualifying orders.  Thank you!',
		'WiseShe' : 'Your code has been processed.  An Anti-Aging Oil Plus will be included with all qualifying orders.  Thank you!',
		'MomJeans' : 'Thank you!  A 1/4oz Anti-Aging Oil Plus will be included with all qualifying orders. We appreciate your purchase!',
		'MVO808' : 'Thank you!  A free Kid Safe Screen will be included in all qualifying orders.  We appreciate your business!',
		'NoAcne' : 'Thank you!  Your free Moisturizing Face Screen will be included in all qualifying orders.  Please specify your tint preference in Special Instructions.',
		'KristenPetrelluzzi' : 'Thank you! Your Ambassador fall reward will be included in your order.  Please specify your tint preference in special instructions.',
		'LisaBourey' : 'Thank you! Your Ambassador fall reward will be included in your order.  Please specify your tint preference in special instructions.',
		'NicoleHeslip' : 'Thank you! Your Ambassador fall reward will be included in your order.  Please specify your tint preference in special instructions.',
		'LisaCannone' : 'Thank you! Your Ambassador fall reward will be included in your order.  Please specify your tint preference in special instructions.',
		'CynthiaLoke' : 'Thank you! Your Ambassador fall reward will be included in your order.  Please specify your tint preference in special instructions.',
		'Joanna' : 'Thank you! Your Ambassador fall reward will be included in your order.  Please specify your tint preference in special instructions.',
		'kellysiebecker' : 'Thank you! Your Ambassador fall reward will be included in your order.  Please specify your tint preference in special instructions.',
		'NancyBruno' : 'Thank you! Your Ambassador fall reward will be included in your order.  Please specify your tint preference in special instructions.',
		'organicskin' : 'Your code has been processed.  A gift will be included with all qualifying orders. One discount item per customer. Thank you!'
        }
	
	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();
});
