(function($){
		
	function htmlPrep() {
		Cufon.replace('#navigation > .shell > ul > li > a', { hover: true, fontFamily: 'Gotham Medium'});
		Cufon.replace('#navigation .shell ul li .dd a', { fontFamily: 'Gotham Medium', color: "#3a6f8f"});
		Cufon.replace('#navigation .shell ul li .dd a.hover', { fontFamily: 'italic'});
		Cufon.replace('.top-nav a', { hover: true, fontFamily: 'Gotham Medium' });
	
		$('#navigation .shell > ul > li > ul').wrap('<div class="dd" />');
		$('#navigation .shell > ul > li:last').addClass('last');
	
		$(document).find('#featuredContent .content div.img').css('height', $('#featuredContent .content div.img img').height());
		$(function(){
			$("#navigation ul li").hover(function() {
				if(!($(this).find(".dd").is(':animated')))
				{
					$(this).find(".dd").slideDown();
				}
			}, function(e) {
				$(this).find(".dd").slideUp();
			});

			$('.dd a').hover(function(){
				$(this).addClass('hover');
				Cufon.refresh('#navigation .shell ul li .dd a.hover');
			},function(){
				$(this).removeClass('hover');
				Cufon.refresh('#navigation .shell ul li .dd a');
				Cufon.refresh('#navigation .shell ul li .dd a');
			});
		});
		
		/* facebox Js ?? */
		$(document).load(function() {});
	}
	
	function mailChimp() {
		if ( $(document).find('a.newsletterPopup').length != 0 ) {
		
			$('a.newsletterPopup').click(function(){
				$('#newsletterPopupContent').remove();
				$('body').append('<div id="newsletterPopupContent" />');
				$('body').append('<div id="facebox_overlay_before" />');
				var offset = $(window).scrollTop();
				offset = $(window).height()/4 + offset;
				$('#facebox_overlay_before').css('width', $(window).width()).css('height', $(window).height()).css('background-position', 'center ' + offset + 'px' );
				$('#newsletterPopupContent').load($('a.newsletterPopup').attr('href') + ' #contentWrapper', function(){
					$.facebox($('#newsletterPopupContent'));
				});
				return false;
			});
		}
	
		$('.mc_form_inside .mc_merge_var input').live('focus',function() {
			$(this).parent('.mc_merge_var').find('.mc_var_label').hide();
		}).live('blur',function() {
			if ( $(this).parent('.mc_merge_var').find('.mc_input').val() == '' ) {
				$(this).parent('.mc_merge_var').find('.mc_var_label').show();
			}
		})
	
		$(function($) {
			// Change our submit type from HTML (default) to JS
			$('#mc_submit_type').val('js');

			// Attach our form submitter action
			$('#mc_signup_form').ajaxForm({
				url: mailchimpSF.ajax_url, 
				type: 'POST', 
				dataType: 'text',
				beforeSubmit: mc_beforeForm,
				success: mc_success
			});

			$('form.MCUnsubscribeForm').ajaxForm({
				url: mailchimpSF.ajax_url + '?mc_unsubscribe', 
				type: 'POST', 
				dataType: 'json',
				beforeSubmit: mc_beforeForm,
				success: mc_unsubscribe_success
			});
		});

		function mc_beforeForm(){
			// Disable the submit button
			$('#mc_signup_submit').attr("disabled","disabled");
			$('#facebox .popup').append('<div id="form_overlay" />');
			var height = $('#facebox').innerWidth();
			var offset = height / 2;
			offset = offset - 50;
			$('#form_overlay').css('width', height + 'px').css('height', $('#facebox').innerHeight() + 'px').css('background-position', 'center ' + offset + 'px' );
		}
		function mc_success(data){

			$('#form_overlay').hide().remove();

			// Re-enable the submit button
			$('#mc_signup_submit').attr("disabled","");

			var reg = new RegExp('class="mc_error_msg"');
			if ( reg.test(data) ){
				$('#mc_message').html(data);
			} else {
				$('.mcSubscribeFormWrapper').empty().html(data);
			}

		}

		function mc_unsubscribe_success(data){
			$('#form_overlay').hide().remove();
			$('div.mcUnsubscribeFormWrapper').empty().append(data.returndata);
		}
	}
		
	function setupSameAddressCheckbox() {
		$('#sameBillingAddress').live('click', function(){
			$('#form-bill-address').val($('#form-address').val());
			$('#form-bill-address2').val($('#form-address2').val());
			$('#form-bill-city').val($('#form-city').val());
			$('#form-bill-zip').val($('#form-zip').val());
			$('#form-bill-state').val($('#form-state').val());
		});
	}
		
	// init when document is ready
	$(function() {
		htmlPrep();
		mailChimp();
		setupSameAddressCheckbox();
		
		// define commonly used functions globally by extending jQuery
		jQuery.restart = {

			formFocusHandlers: function() {
				$('.blink').focus(function() {
					if ($(this).val() == $(this).attr('title')) {
						$(this).val('');
					}
				});
				$('.blink').blur(function() {
					if ($(this).val() == '') {
						$(this).val($(this).attr('title'));
					}
				});
			},

			validateZIP: function(field) {
				var check = "pass";
				var valid = "0123456789-";
				var hyphencount = 0;

				if (field.length!=5 && field.length!=10) {
				check = "Please enter your 5 digit or 5 digit+4 zip code.";
				return check;
				}
				for (var i=0; i < field.length; i++) {
				temp = "" + field.substring(i, i+1);
				if (temp == "-") hyphencount++;
				if (valid.indexOf(temp) == "-1") {
				check = "Invalid characters in your zip code.  Please try again.";
				return check;
				}
				if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-")) {
				check = "The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'.   Please try again.";
				return check;
				   }
				}
				return check;
			},

			validateFields: function(fields){
				var check = true;
				for(i = 0; i < fields.length; i++){
					if($(fields[i]).val() == $(fields[i]).attr('title')){
						check = false;
					}
				}
				return check;
			}

		} // end of jQuery extensions
		
	});
	
})(jQuery);
