$(document).ready(function(){
$('.sort-widget-container').css('display', 'block');
//Don't fill the top search box in if we have the affiliate search form on screen
if ($("#quick_search_form").exists() && $("#affiliate_product_search_text_field").exists() == false)
{
	//Feed whatever was entered in to the search field to the quick search field at the top of the page
	$("#quick_search_text_field").val($("#search_phrase").val());
	//Check if the spelling suggestion actually found any matches, no need to show it if the spelling suggestion doesn't bring any results back
	$.getJSON("/modules/views/did_you_mean_ajax_json.php?did_you_mean_phrase=" + $('#did-you-mean-link').text() + "&orig_phrase=" + $("input[name='search_phrase']").val(), function(data)
	{
		if (data['results_returned'] > 0)
		{
			$("#did-you-mean-link").after(" ? <span> (we found " + data['results_returned'] + " results for <strong><a href='" + $('#did-you-mean-link').attr('href') + "'>" + $('#did-you-mean-link').text() + " </a></strong>)</span>");
			$("#did-you-mean-container").show();
		}
	});
}
  //Trigger submit when someone changes the sort filter
  $('#sort_upper,#sort_lower').change(function()
  {
    $("input[name='action']").val("sorting");
    $("input[name='page']").val("1");
    $("input[name='sort']").val($(this).val());
    $("#quick_search_form,#advanced_search_form").trigger("submit");
  });

  //Trigger submit getting the value from the quick search field when clicking the advanced search link
  $('#top_advanced_search_link').click(function()
  {
    var href = $(this).attr('href');
     $(this).attr('href', href + '&search_phrase=' + $("#quick_search_text_field").val());
  });

  $("#quick_search_form,#advanced_search_form").submit(function()
  {
    $("input[name='page']").val("1");
    $("input[name='action']").val("submit_search");
  });

  $('#filter-tab').click(function()
  {
    if( $('#available-filter-container').is(":visible") == true){
      $('div[id^="available-filter-"]').hide();
      $('#tab_header').css('border-bottom', '#C9C8C6 1px solid');
      $('#filter-tab').html("<img style='width:20px;height:20px;margin-top:-2px;' src='/images/icons/bullet_arrow_up.png'/>Show Filters");

    }
    else{
      $('div[id^="available-filter-"]').show();
      $('#tab_header').css('border-bottom', 'none');
      $('#filter-tab').html("<img style='width:20px;height:20px;margin-top:-2px;' src='/images/icons/bullet_arrow_down.png'/>Hide Filters")
    }
  });

  $('.more-link').click(function()
  {
    $('.more-link').hide();
    $('.filter').show();
  });

if($('#sort').val() != "" && $('#sort').val() != null)
{
  $('#sort_upper,#sort_lower').val($('#sort').val());
}


});






