Cufon.replace('#shopZM, #moreNews .newsTime, h1, h2, h3', { hover:true });

$(document).ready(function() {
	
	$("a").attr("title", "");
	
	$('.subNav').css("padding-top", "0").hide();
	$('.subnav li:first').css("margin-top", "6px");
	
	/* For Touch on iPhone/iPad (no hover state) */
	if((navigator.userAgent.match(/iPhone/i))
	|| (navigator.userAgent.match(/iPod/i))
	|| (navigator.userAgent.match(/iPad/i))
	|| (navigator.userAgent.match(/Android/i))) {
		$('#nav li.sub a').not('.subNav li a').bind('touchstart, click', function(e){
	        e.preventDefault();
			$(this).parent().find('.subNav').slideToggle();
			return false;
	    });
	/* For regular browsers */
	} else {
		$('#nav li.sub').not('.subNav li').hover(function(){
			$(this).find('.subNav').css("height", "").animate({opacity: "1"}, 250, function(){
				$(this).slideDown();
			})
		},function(){
			$(this).find('.subNav').stop().hide();
		});
	}
	
	
	/* Build Nav for Wine Reviews by Vintage */
	
	$(".wineAccolades h4").hide();
	$(".wineAccolades div").hide();
	$(".wineAccolades div:first").show();
	$(".wineAccolades").prepend('<ul class="accolades"></ul>');
	
	$(".wineAccolades h4").each(function(){
		var ID = $(this).attr("id");
		ID = ID.replace("accolade_vintage_", "");
		$("ul.accolades").append('<li id="accolade_btn_'+ ID +'">'+ ID +' Vintage</li>');
	});
	
	$("ul.accolades li:first").addClass("current");
	$("ul.accolades li").click(function(){
		var ID = $(this).attr("id");
		ID = ID.replace("accolade_btn_", "#accolade_vintage_");
		$(".wineAccolades div").hide();
		$(ID).next("div").fadeIn();
		$("ul.accolades li.current").removeClass("current");
		$(this).addClass("current");
		
		return false;
	});
	
	
	/* Build Photo Captions from ALT tag */
	
	var caption = $(".photo img, .photoWide img").attr("alt");
	if (caption != null && caption != "") {
		$(".photo img, .photoWide img").not("#wine_page .photo img").after('<p class="caption">'+ caption +'</p>');
	}
	
	
	/*Email Address*/
	
	/* Signup Form ajax -- */
	
	$("#eNewsSignUp input").focus(function(){
		
		var _name = $(this).attr("name");
		var _value = $(this).attr("value");
		
		if( _name == "name" && _value == "Name")
		{
			$(this).attr("value","");
		}
		
		if( _name == "email" && _value == "Email Address")
		{
			$(this).attr("value","");
		}
	});
	
	
	$("#eNewsSignUp input").blur(function(){
		
		var _name = $(this).attr("name");
		var _value = $(this).attr("value");
		
		if( _name == "name" && _value == "")
		{
			$(this).attr("value","Name");
		}
		
		if( _name == "email" && _value == "")
		{
			$(this).attr("value","Email Address");
		}
	});
	
	$("#eNewsSignUp").submit(function(){
		
		var _error = false;
		
		$(this).find("input").each(function(){
			
			if($(this).attr("name") == "name" && $(this).attr("value") == "Name")
			{
				_error = true;
			}
			
			if($(this).attr("name") == "email" && $(this).attr("value") == "Email Address")
			{
				_error = true;
			}
			
		})
		
		if(_error)
		{
			alert("Please make sure your name and email address are typed correctly.");
			return false;
		}
		
		$(this).fadeOut("700", function(){
			
			this.reset();
			
			$("#emailThankYou").fadeIn();
			
		});
		
		
		return false;
		
	});
	
	
	$("#recipeArchiveLink").hide();
	
	$("#recipeSwitchrForm").submit(function(){ 
		
		// find the recipe id
		
		var _recipe = $(this).find("select").attr("value");
		
		if( _recipe )
		{
			_href = $("#recipe_" + _recipe).attr("href");
			
			window.location.replace(_href);
		}
		
		return false; 
		
	}).show();
	
});
