
        var searchFiltersValue = new Array("Recipe","Testing","Tasting","Science","Episode","Video","");
        var searchFiltersText = new Array("Search Recipes","Search Equipment Reviews","Search Taste Tests","Search Science","Search Episodes","Search Videos","Search All");
        
        function setSearchFieldContents(n) {
            //alert($("#global_search_query").val()+", "+searchFiltersText[n]+", "+n);
            if ($.inArray($("#global_search_query").val(), searchFiltersText) > -1) {
                $("#global_search_query").val(searchFiltersText[n]);
            };
        };
        
        function oc(a)
        {
          var o = {};
          for(var i=0;i<a.length;i++)
          {
            o[a[i]]='';
          }
          return o;
        };
        
        function HoverImage(filename) {
            switch(true) {
                case (filename.indexOf('gray')!==-1):
                    var re = new RegExp("(.+)_gray\\.(gif|png|jpg)", "g");
                    return filename.replace(re, "$1_black.$2");
                case (filename.indexOf('black')!==-1):
                    var re = new RegExp("(.+)_black\\.(gif|png|jpg)", "g");
                    return filename.replace(re, "$1_color.$2");
                default:
                    var re = new RegExp("(.+)\\.(gif|png|jpg)", "g");
                    return filename.replace(re, "$1_hover.$2");
            }
        }
        function NormalImage(filename) {
            switch(true) {
                case (filename.indexOf('black')!==-1):
                    var re = new RegExp("(.+)_black\\.(gif|png|jpg)", "g");
                    return filename.replace(re, "$1_gray.$2");
                case (filename.indexOf('color')!==-1):
                    var re = new RegExp("(.+)_color\\.(gif|png|jpg)", "g");
                    return filename.replace(re, "$1_black.$2");
                default:
                    var re = new RegExp("(.+)_hover\\.(gif|png|jpg)", "g");
                    return filename.replace(re, "$1.$2");
            }
        }
    
        $(document).ready(function() {
            $("#btn_search_filter_select").click(function() {
                $("#search_filter_select").show();
                $("#search_filter_select").focus();
            });
            $("#search_filter_select li:first").click(function() {
                $("#search_filter_select").hide();
            });
            
            $("li.search_filter_option a").click(function() {
               
                var catID = $("li.search_filter_option").index($(this).parent());
                $("input[name=rcat]").val(searchFiltersValue[catID]);
                if ($.inArray($("#global_search_query").val(), searchFiltersText) > -1) 
                    { $("#global_search_query").val(searchFiltersText[catID]); }
                $("#search_filter_select").hide();
            });
            
            $("#global_search_query").focus(function() { 
                lastVal = $(this).val();
		        $(this).val("");
		        $(this).attr("style","color:#000");
            });
            
            $("#global_search_query").blur(function(){
                if ($(this).val() == ""){
                    $(this).val(lastVal);
                    $(this).attr("style","color:#555");
                } else { 
                    $(this).unbind('focus');
                }
            });
            
            // STATION FINDER
            $("#station_finder").click(function(){
                window.open(this.getAttribute("href", 2),'stationfinder','height=315,width=600,scrollbars=yes');
                return false;
            });
            
            
            
            
            try {
                $(function() {
                    $('#dek, #overview, #methodology, p.whyItWorks, #whyItWorks').truncate({max_length: 200});
                });
            } catch(err) {  }
            
            // Change the image of hoverable images
            $("*.hover,.button").hover( function() {
                var hoverImg = HoverImage($(this).attr("src"));
                $(this).attr("src", hoverImg);
            }, function() {
                var normalImg = NormalImage($(this).attr("src"));
                $(this).attr("src", normalImg);
            });
            
            // SCROLLABLE PLAYLIST
            try{
                $("#playlist .scrollable").scrollable({size:4, clickable:false}); 
                if ($('#playlist_items img').length <= 4) {  
                    $('.nextPage').addClass('disabled');  
                } else { 
                    $('.nextPage').removeClass('disabled');     
                } 
            } catch(err) {  }
            
	// SHOW/HIDE register panel
	$("a.form_toggle").click(function(){
		$("#membershipLinks li div").hide();
		$(this).parent().children('div').show();
		$(this).parent().find('input.email').focus();
		return false;
	});
	$('#membershipLinks li div').click(function(e) {
		e.stopPropagation();
	});
	$(document).click(function() {
		$('#membershipLinks li div').hide();
	});
	$(".faq").click(function(){
		$('#membershipLinks li div').hide();
	});
			
	$(".close a").click(function(){
                $(this).parent().parent('#membershipLinks li div').hide();
                return false;
	});
    
            
            try {
                
                // HOMEPAGE scrollable feature
                var feature = $("#features").scrollable({size: 1, clickable: false, keyboard: false}).autoscroll(7000).circular({api: true}); // instantiate scrolling
                
                $("#feature_scroll span.feature_subtitle").text(feature.getVisibleItems().children("h2").text()); // add title to nav bar below feature
                
                feature.onSeek(function() {
                    // change title when feature scrolls
                    $("#feature_scroll span.feature_subtitle").text(this.getVisibleItems().children("h2").text()); 
                });
                
                $("#features").hover(function(){feature.pause()}); // pause the feature during hover
            } catch(err) {  }            
            
            try {
                //Kitchen Tour scrollable feature
                var tour = $("#tour_scrollable").scrollable({size: 1, clickable:false, api:true});

            } catch(err) {  }   
            
            // FAQ Page Show & Hide Jquery Script    
            $('.faqAnswers').hide();	
			$('a.faq').click(function(ev) {
			    ev.preventDefault();
				$(this).siblings('.faqAnswers').slideToggle(300);
				$(this).toggleClass('current');
	 		});
	 		$('a.hide_faq').click(function(ev) {
	 		    ev.preventDefault();
	 			$this = $(this);
	 			$this.parent().slideUp(300);
	 			$this.removeClass('current');
	 			$this.parent().siblings('a.faq').removeClass('current');
	 		});
	 		

	 		//validate Email Address on Overlays, Paywalls and Ads
			jQuery.validator.messages.required = "";
			jQuery.validator.messages.email = "";
			jQuery.validator.messages.maxlength = "";
			jQuery.validator.messages.minlength = "";
			
			jQuery.validator.addMethod("goodSearchQuery", function(value, element) {
                return this.optional(element) || jQuery.inArray(value,searchFiltersText) < 0;
            }, "");

			
			$('#regOverlay').validate();      
			$('#joinOverlay').validate();   
			$('#ftJoin').validate(); 
			$('#ftJoinVertical').validate(); 
			$('.registration').validate();
			$('#adJoin').validate();
			$('#paywallForm').validate(); 
			$('#longletter').validate();
			$('#sweeps_register').validate();
			$('form.login').validate();
			$('#global_search').validate({

			    rules: {
			        q: {
			            required: true,
			            goodSearchQuery: true
			        }
			    },
			    invalidHandler: function(form, validator) {
                    var errors = validator.numberOfInvalids();
                    if (errors) {
                        alert('Please enter a search term.');
                    }
                }
			});
		    try {
			    $('input.required').rules('add','required'); // Validate REQUIRED fields
			} catch(e) { }
			// check that e-mails are E-MAILS
			try {
			 $('input.email').rules('add','email');
			} catch(e) { }
			// match confirmation e-mail against e-mail
			try {
			 $('input[name="confEmail"].required').rules('add', {
				 equalTo: 'input[name="cds_email"]'
			 });
			} catch(e) { }  

        
            $('#nav_site li, .button, input.hover, .video_cover, .feature_cover').supersleight();
            
      		
      	//	$('#refine ul li .filter_sublist .hover')
            
        $("#video_block a").click(function(){
            $("#video_block").hide();
            $("#player_block").show();
            return false;
        });
        $("#player_block a.close").click(function(){
            $f().pause();
            $("#video_block").show();
            $("#player_block").hide();
            return false;
        });
        
        var lastVal = ""; 
		// Global var to hold the last state of a field contents
            
		$("input[type='text']:not(#global_search_query)").focus(function(){
            lastVal = $(this).val();
            $(this).val("");
        });
        
        $("input[type='text']:not(#global_search_query)").blur(function() {
            if ($(this).val() == ""){        
                $(this).val(lastVal);
            } else {            
                $(this).unbind('focus');    
            }
        });
        
        // VIDEO LIBRARY FUNCTIONS        
        
        try {
            var selectedVideo = $.query.get('docid');
            $('a.vid'+selectedVideo).children(".video_cover").addClass("playing");
            $('li.vid'+selectedVideo).children("a.watch_this_clip").addClass("playing").text("now playing");
        } catch(e2) {  };
        
        // HOVER PLAY BUTTONS
        $("a.video_link").hover(function(){
            $(this).children(".video_cover").not('.playing').show();        
        }, function() { 
            $(this).children(".video_cover").not('.playing').hide(); 
        });
        

	    $("div.feature").hover(function(){
    	  	$(this).children(".feature_cover").show();
       	}, function() {
      		$(this).children(".feature_cover").hide();
      	});
   
        
        // VIDEO LINK HANDLER
       // $("a.video_link:not(#video_block a)").click(function(){
       //     document.location.href = $.query.set('docid',$(this).attr('href'));
       //     return false;
      //  });
        
        // PLAYLIST FLYOUTS
        $("#playlist_items a").each(function(){   
            var el = $(this);   
            el.tooltip({   
                //position: 'center left',   
                position: 'center left',   
                offset : [-230, 17],     
                tip : '#'+el.attr('name')
                //relative: "true"
            });   
        });  
        
        $("#video_block a.video_link").hover(function(){
            $(this).children(".video_cover").show();        
        }, function() { 
            $(this).children(".video_cover").hide(); 
        });
        
        
        // Expand Panel
        // Expand Panel
        $("#open").click(function(){
            $("div#panel").slideDown("slow");
        
        });	
        
        // Collapse Panel
        $("#panel #close").click(function(){
            $("div#panel").slideUp("slow");	
        });		
        
        $("div#panel").slideDown("slow");
        
        // LOGIN ***********************************************
    	try{
    		document.forms["login"].elements["email"].focus();
    
	
			$('#page_login #password').focus(function() {
				$('#no_password:checked').click();
				$('#yes_password:not(checked)').click();
			});
		} catch(e3) { };
		
		// CUSTOMER SERVICE NAV ********************************
		$('#custserv_navigation li ul').hide();
		$('#custserv_navigation h3').click(function() {
			$(this).siblings('ul').toggle('fast');
			$(this).toggleClass('opened');
		});
		$('.custserv_selfService_action').siblings('ul').hide();
		$('h5.custserv_selfService_action').click(function() {
			$(this).siblings('ul').toggle('fast');
			$(this).toggleClass('opened');
		});
});
        
        
        

