jQuery(function( $ ){

$(".vjs-flash-fallback OBJECT").css({"visibility":"hidden","cursor":"pointer"});
$(".vjs-flash-fallback").click( function(){ $(".vjs-flash-fallback OBJECT").css("visibility","visible");  });

$('#Market.Herbs101 .Item a').click( function(e) { e.preventDefault(); });

$('#Logo SPAN').cycle({
	 fx:    'fade', 
    speed:  '600',
    next: 'SPAN',
    timeout: 3000 
	});	
	
$('#Slideshow').cycle({ 
    fx:     'fade', 
    speed:  1100, 
    timeout: 0 ,
    pager:  '.SlideNav',      
    pagerAnchorBuilder: function(idx, slide) {return '<li><a href="#"> <img src="' + slide.src + '" width="36" height="44" /> </a></li>';} 
});

$('#RecipeSlides').cycle({
    fx: 'fade', 
    speed: 10, 
    timeout: 0 ,
    pager:  '#RecipePager',      
    pagerAnchorBuilder: function(idx, slide) {return '<li><a href="'+slide.id+'">' + slide.title + '</a></li>';} 
});


$('#TabbedContent').cycle({
    fx: 'fade', 
    speed: 10, 
    timeout: 0 ,
    pager:  '#TabbedPager',      
    pagerAnchorBuilder: function(idx, slide) {return '<li><a href="'+slide.id+'">' + slide.title + '</a></li>';} 
});



$('#RecipePager A').click( function(){ if($.browser.msie){ window.location = this.href;} });

$("#comment_form textarea").counter({
    type: 'char',
    goal: 350,
    count: 'down'            
});

$.validator.addMethod("blankname", function(value) { return value != "name*"; }, '');

$("#freeform").validate({
   rules: {
     // simple rule, converted to {required:true}
     name: {
     required: true,
     blankname: true
     },
     // compound rule
     email: {
       required: true,
       email: true
     },
     comment: {
     required: true
     },
     recipient_email:
     {
     required: true,
     email: true
     },
     recipient_name:
     {
     required: true
     }
     
   },
   messages: {
     email: {  required: "", email: "" },
     name: {  required: "" },
     comment: { required: "" },
     recipient_name: { required: "" },
     recipient_email: {  required: "", email: "" }
     
   }
});

$('#Recipes.TellAFriend #SubmitPopup').not('.Iphone').find('INPUT.Link').val(parent.window.location); 

$("#subForm input:submit").click(function() { 
      
      // First, disable the form from submitting
      $('form#subForm').submit(function() { return false; });
      
      // Grab form action
      var formAction = $("form#subForm").attr("action");
      
      // Hacking together id for email field
      // Replace the xxxxx below:
      // If your form action were http://mysiteaddress.createsend.com/t/r/s/abcde/, then you'd enter "abcde" below
      var id = "bijqi";
      var emailId = id + "-" + id;
      
      // Validate email address with regex
      if (!checkEmail(emailId)) {
        alert("Please enter a valid email address");
        return;
      }
      
      // Serialize form values to be submitted with POST
      var str = $("form#subForm").serialize();
      
      // Add form action to end of serialized data
      // CDATA is used to avoid validation errors
      //<![CDATA[
      var serialized = str + "&action=" + formAction;
      // ]]>
      
      // Submit the form via ajax
      $.ajax({
        url: "/proxy.php",
        type: "POST",
        data: serialized,
        success: function(data){
          // Server-side validation
          if (data.search(/invalid/i) != -1) {
            alert('The email address you supplied is invalid and needs to be fixed before you can subscribe to this list.');
          }
          else
          {
          
            $(".Form li").hide()
            $(".Form").html("<li><p><span>Thanks!</span><br />We'll be in touch soon.</p></li>");
            // For screen reader accessibility
           
           // Fire off Google Analytics fake pageview
            //var pageTracker = _gat._getTracker("UA-XXXXX-X");
            //pageTracker._trackPageview("/newsletter_signup");
          }
        }
      });
    });
    
$('.DropMenu A').toggle(
    function(){ $(this).addClass("Open"); $(this).parent().find('ul').show(); },
    function(){ $(this).removeClass("Open"); $(this).parent().find('ul').hide();  
 });

$('#Promos .Item').hover( 
	function(){ $(this).addClass("On"); },
	function(){ $(this).removeClass("On"); 
});

$('.ClosePop').closeDOMWindow({eventType:'click'}); 
$('.PopUp').openDOMWindow({ 
borderColor:'#7accc8',
borderSize: 7,
width: 440,
modal: 1,
height: 610,
eventType:'click', 
windowSource:'iframe', 
windowPadding:0,  
loaderHeight:16, 
loaderWidth:17,
overlayColor:'#FFF',
overlayOpacity:'85'
});


$('.TellAFriendPop').openDOMWindow({ 
	borderColor:'#7accc8',
	borderSize: 7,
	width: 440,
	modal: 1,
	height: 470,
	eventType:'click', 
	windowSource:'iframe', 
	windowPadding:0,  
	loaderHeight:16, 
	loaderWidth:17,
	overlayColor:'#FFF',
	overlayOpacity:'85'
}); 


/* Know Your Label */
$('#Stage A').click(function(){ return false; });	

$('.Button').hover( 
function(){ $(this).find('span').show(); },
function(){ $(this).find('span').hide();    
});	

$('.FirstPoint').hover( function(){ $('.Button.One').mouseover(); }, function(){ $('.Button.One').mouseout(); });
$('.SecondPoint').hover( function(){ $('.Button.Two').mouseover(); }, function(){ $('.Button.Two').mouseout(); } );
$('.ThirdPoint').hover( function(){ $('.Button.Three').mouseover(); }, function(){ $('.Button.Three').mouseout(); });
$('.FourthPoint').hover( function(){ $('.Button.Four').mouseover(); }, function(){ $('.Button.Four').mouseout();  });
$('.FifthPoint').hover( function(){ $('.Button.Five').mouseover(); }, function(){ $('.Button.Five').mouseout(); } );


$("select[class*=flexselect]").flexselect();
$("input:text:enabled:first").focus();
  
$('INPUT.Name').focus( function() {  if($(this).attr("value") == "name") $(this).attr("value", ""); });
$('INPUT.Name').blur(function() {  if($(this).attr("value") == "") $(this).attr("value", "name"); });

$('INPUT.Email').focus( function() {  if($(this).attr("value") == "email") $(this).attr("value", ""); });
$('INPUT.Email').blur(function() {  if($(this).attr("value") == "") $(this).attr("value", "email"); });



});

(function(b) { b.fn.extend({ counter: function(a) { a = b.extend({}, { type: "char", count: "down", goal: 140 }, a); var d = false; return this.each(function() { function e(c) { if (typeof a.type === "string") switch (a.type) { case "char": if (a.count === "down") { g = " character(s) left"; return a.goal - c } else if (a.count === "up") { g = " characters (" + a.goal + " max)"; return c } break; case "word": if (a.count === "down") { g = " word(s) left"; return a.goal - c } else if (a.count === "up") { g = " words (" + a.goal + " max)"; return c } break; default: } } var g, f = b(this); b('<div id="' + this.id + '_counter"><span>' + e(b(f).val().length) + "</span>" + g + "</div>").insertAfter(f); var i = b("#" + this.id + "_counter span"); f.bind("keyup click blur focus change paste", function(c) { switch (a.type) { case "char": c = b(f).val().length; break; case "word": c = f.val() === "" ? 0 : b.trim(f.val()).replace(/\s+/g, " ").split(" ").length; break; default: } switch (a.count) { case "up": if (e(c) >= a.goal && a.type === "char") { b(this).val(b(this).val().substring(0, a.goal)); d = true; break } if (e(c) === a.goal && a.type === "word") { d = true; break } else if (e(c) > a.goal && a.type === "word") { b(this).val(""); i.text("0"); d = true; break } break; case "down": if (e(c) <= 0 && a.type === "char") { b(this).val(b(this).val().substring(0, a.goal)); d = true; break } if (e(c) === 0 && a.type === "word") d = true; else if (e(c) < 0 && a.type === "word") { b(this).val(""); d = true; break } break; default: } f.keydown(function(h) { if (d) { this.focus(); if (h.keyCode !== 46 && h.keyCode !== 8) if (b(this).val().length > a.goal && a.type === "char") { b(this).val(b(this).val().substring(0, a.goal)); return false } else return h.keyCode !== 32 && h.keyCode !== 8 && a.type === "word" ? true : false; else { d = false; return true } } }); i.text(e(c)) }) }) } }) })(jQuery);
 



