jQuery(function ($) {
	// clear search default text on focus
	$(".clearDefault").focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});
	// submit forms with links
	$("a.submit").click(function(){	
		$(this).closest("form").submit();
		return false;	
	});
	$('form input').keypress(function(e){
		var c = e.which ? e.which : e.keyCode;
		if(c == 13){
		    $(this).closest('form').submit();
		} 
	});
	// search popup 
	$("#nav-search a").click(function(){	
		$(this).toggleClass("open");
		$("#searchForm").slideToggle(100);
		return false;	
	});
	// ingredients
	$("dl.ingredients dd").hide();
	$("dl.ingredients dt a").click(function(){	
		$(this).toggleClass("open");
		$(this).parent().next("dd").slideToggle(100);
		return false;	
	});
	// product info
	$("dl.prodInfo dd").hide();
	$("dl.prodInfo dt a").click(function(){	
		$(this).toggleClass("open");
		$(this).parent().next("dd").slideToggle(100);
		return false;	
	});
        // subscribe to newsletter
        $("#newsletterForm").submit(function(){
            $("#newsletterForm h5").css('fontStyle', 'normal').css('color', 'black').text('please wait...');
            var name = $("input[name='name']", this).val();
            var email = $("input[name='email']", this).val();
            $.post('/campaignmonitor/add.php', {name: name, email: email}, function(data){
                if(data == '201'){
                    $("#newsletterForm h5").css('fontStyle', 'italic').css('color', 'black').text('thanks for signing up!');
                }else{
                    $("#newsletterForm h5").css('fontStyle', 'italic').css('color', 'red').text(data.toLowerCase());
                }
            });
            return false;
        });
        // expandable lists
	$("dl.expand dd").hide();
	$("dl.expand dt a").click(function(){
		$(this).toggleClass("open");
		$(this).parent().next("dd").slideToggle(100);
		return false;
	});
	
	$("table td a.more").click(function(){
		$("span.show", $(this).parent()).toggle();
		if($(this).text() == 'more...') {
			$(this).text('less');
		}else{
			$(this).text('more...');
		}
		
		return false;
	});
});
