jQuery(
	function() {
		jQuery("div.menu li:first-child").addClass("first");
		jQuery("div.menu li:last-child").addClass("last");
	}
);

jQuery(function() {
	$('li#menu-item-44 > ul > li > a').each(function() {
		var our_puds = 'our-puds';
		var hash = $(this).attr('href').substring(
		$(this).attr('href').indexOf(our_puds) + our_puds.length + 1);
		var new_link = $(this).attr('href').replace('/' + hash, '');
		var new_link = new_link + '#' + hash;
		$(this).attr('href', new_link);
	})
})


jQuery(
	function() {
		jQuery('#ganache-form').validate({
			showErrors: false,
			hideLabel: false,
			highlight: customErrorHighlight
		});
		jQuery('#banners').cycle({
			fx: 'fade',
			speed: 750,
			timeout: 4000
		});
	}
);

jQuery(
	function() {
		// $('body.film .group a.recipe-permalink').parents(".group").css("cursor", "pointer").click(
		// 			function() {
		// 				console.log($(this));
		// 				return;
		// 				$(this).find("a.recipe-permalink").click();
		// 			}
		// 		);
		
		$('body.film .group a.recipe-permalink').fancybox(
			{
				autoScale:false,
				padding:5,
				titleShow:false,
				autoDimensions:true,

				onComplete:function() {
					$("#fancybox-inner .col1, #fancybox-inner .col2").removeClass('border');
					if (jQuery('#fancybox-inner .col1').height() > jQuery('#fancybox-inner .col2').height()) {
						jQuery('#fancybox-inner .col1').addClass('border');
					} else {
						jQuery('#fancybox-inner .col2').addClass('border');
					}
				}
			}
		);
		$('.fancy').fancybox(
			{
				autoScale:false,
				padding:10,
				titleShow:false,
				autoDimensions:true
			}
		);
	}
);

jQuery(
	function() {
		$('body.home .sidecol .item img, body.home .sidecol .item h3').css("cursor", "pointer").click(
			function() {
				var link = $(this).parents(".item").find("a");
				
				if ( link.attr("target") == "_blank" ) {
					window.open(link.attr("href"));
				} else {
					location.href = link.attr("href");
				}
			}
		);
	}
);

jQuery(
	function() {
		// ARGH IEEEEEEEEEEEEEEEEEEEEEEEEEE! YOUR Z-INDEXES VEXES MEEEEEEEEEEEEEE!
		if ( jQuery.browser.msie && parseInt(jQuery.browser.version) < 8 ) {
			$(".gfield_description").has(".tooltip").css({position: 'relative', height: '30px'}).prepend('<div class="tooltip-outer" />').css({'margin-top': '-28px'}).click(
				function() {
					if ( $(this).find('.tooltip').is(':visible') ) {
						$(this).find('.tooltip').hide().parents('.gfield_description').height(30);
					} else {
						$(this).find('.tooltip').show().css({position: 'static', 'margin-top': '10px'}).parents('.gfield_description').height($(this).find('.tooltip').height() + 65);
					}
				}
			);
		} else {
			$(".tooltip").hide().wrap('<div class="tooltip-outer" />').parent().hoverIntent({
				timeout: 750,
				over: function() {
					$(this).find(".tooltip").fadeIn().animate({top:10, left:15}, {queue:false})
				},
				out: function() {
					$(this).find(".tooltip").fadeOut().animate({top:0, left:0}, {queue:false});
				}
			});
		}
		
		if ( jQuery.browser.msie && parseInt(jQuery.browser.version) < 7 ) {
			$('.gfield_checkbox').parents('.gfield').find('> label').hide()
				.parent().find('input').css({'float': 'left', 'margin-right': '10px'}).siblings('label').css('margin-left', '0')
				.parents('.ginput_container').width('auto')
				.find('label').width('310px');
			$('input[type="checkbox"]').css({background: 'none', border: 'none', width: 'auto'});
		}
	}
);
		
jQuery(
	function() {
		jQuery('.mega').hover(
		function() { jQuery(this).find('#mega-div').fadeIn('slow'); },
		function() { jQuery(this).find('#mega-div').fadeOut('normal'); }
		);

		jQuery('div.menu ul').droppy({speed:250, hideDelay:5000, level:1});

		jQuery('div.menu ul li a').click(function() {
		var next = jQuery(this).next();

		if (next.is('ul') && !next.is(':visible')) {
			jQuery('div.menu ul ul ul:visible').slideUp(250).prev().removeClass('active');
			next.slideDown(250).prev().addClass('active');
			return false;
		}
		});

		// Update the our puds drop down to link to the subcategories with hashtags
		jQuery('div.menu ul #home_our-puds ~ ul > li > a').each(function() {
		this.href = this.href.substring(0, this.href.indexOf('our-puds')+8) + "#" + this.href.substring(this.href.indexOf('our-puds')+9);
		});
	}
);

jQuery(
	function() {
		$("#freestuff .newsletter form input").each(function() {
 			// Apply the css here so that people without js enabled can still use the form properly.
 			jQuery(this).parent().siblings('label').css({
				'cursor':'text',
 				'position':'absolute',
 				'left':'5px',
 				'top':'5px'
 			});
 		}).fancyLabels({slide:true, fade:0.75});
	}
);

// Stop typographic widows on post titles
jQuery(
	function() {
		jQuery("h2, .pud-shelf .plate, .description p").each(function() {
			var wordArray = $(this).text().split(" ");
			if ( wordArray.length > 3 ) {
				wordArray[wordArray.length - 2] += "&nbsp;" + wordArray[wordArray.length - 1];
				wordArray.pop();
				$(this).html(wordArray.join(" "));
			}
		});
		Cufon.replace('h2');
	}
);

// For checkbox groups that have only one checkbox, Gravity Forms by default displays
// the "required" asterisk in the overall label — which, in those types of checkbox,
// is usually empty. So, you get a lone asterisk, floating helplessly, uselessly, and
// alone above the checkboxes. This fixes that.
jQuery(
	function() {
		// Find fields that are both checkbox groups and are required.
		jQuery(".gfield").has('.gfield_checkbox').has(".gfield_required").each(
			function() {
				// This function is just for single-option checkboxes,
				// where an overall label doesn't exist. In those instances,
				// the text of the overall label will just be "*".
				if ( $(this).find(".gfield_label").text().replace(/\s/, '') == "*" ) {
					// Hide the lone asterisk.
					$(this).find(".gfield_required").hide();
					// Add an asterisk to our lone checkbox.
					$(this).find(".gfield_checkbox label").append('<span class="gfield_required">*</span>');
				}
			}
		);
	}
);

jQuery(
	function(){
		jQuery(".gfield").has('.gfield_checkbox').each(
			function(){
				$(this).find(".validation_message").addClass("narrow")
			})
	}
);

// jQuery(window).load(function() {
// 	if (jQuery('.sidecol .item').length > 0) {
// 		jQuery('.sidecol .item').equalHeights();
// 	}
// });

function customErrorHighlight(element, errorClass, validClass, errorMsg) {
if (jQuery(element).parent().hasClass('question') || jQuery(element).parent().hasClass('group')) {
if (jQuery(element).parent().prev().length > 0) {
	jQuery(element).parent().prev().addClass(errorClass);
} else {
	jQuery(element).parent().next().addClass(errorClass);
}
} else if (jQuery(element).parents('table').get(0)) {
var tbl = jQuery(element).parents('table').get(0);
jQuery(tbl).parent().find('label:first-child').addClass(errorClass);
} else {
if (jQuery(element).prev().length > 0) {
	jQuery(element).prev().addClass(errorClass);
} else if(jQuery(element).next().length > 0) {
	jQuery(element).next().addClass(errorClass);
}
}
}

// .cufon-canvas{text-indent:0!important;}@media screen,projection{.cufon-canvas{display:inline!important;display:inline-block!important;position:relative!important;vertical-align:middle!important;font-size:1px!important;line-height:1px!important;}.cufon-canvas .cufon-alt{display:-moz-inline-box!important;display:inline-block!important;width:0!important;height:0!important;overflow:hidden!important;text-indent:-10000in!important;}.cufon-canvas canvas{position:relative!important;}}@media print{.cufon-canvas{padding:0!important;}.cufon-canvas canvas{display:none!important;}.cufon-canvas .cufon-alt{display:inline!important;}}
