$(function() {

    /*Autocomplete the search box */    
    /*submit the search for when the enter key is pressed*/
    $("#search_query").autocomplete("/ajax/search/", 
        { minChars:3, 
          cacheLength :5, 
          maxItemsToShow:10,
          matchSubset: 0,
          delay:100, 
          autoFill:false, 
          onItemSelect:function() { $('#search_query')[0].form.submit() }
    });
    $("#search_query_channel").autocomplete("/ajax/search/", 
      { minChars:3, 
        cacheLength :5, 
        resultsClass: "ac_results ac_results_channel",
        maxItemsToShow:10, 
	    matchSubset: 0,
        delay:100, 
        autoFill:false, 
        onItemSelect:function() { $('#search_query_channel')[0].form.submit() }
        });
    $(".search_query").focus(function() {
        this.select();
    })
    $(".search_query").keypress(function (e) {
        if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
            this.form.submit();
            return false;   
        } else {   
            return true;   
        }   
    });   

});

if ($('body#search').length > 0) {
    $(function() {
        $('.related-popup-link').click(function() {
            $('#related-popup-' + this.rel).slideToggle();
        });
        $('#tab-' + SEARCH_STATE).addClass('sel');
        $('#subtab-' + SEARCH_STATE_SUB).addClass('sel');
        CATEGORY_IDS = [110,220];
        if (CATEGORY_IDS && CATEGORY_IDS.length > 0) {
            for (i in CATEGORY_IDS) {
                e = $('#category_' + CATEGORY_IDS[i]);
                e.parents('.related-popup').show();
                e.click();
            }
        };
    })
};
