var custom_selector_hover;
$(document).ready(function(){
    $(".custom_selector .head").hover(function(){$(this).addClass("hover");}, function(){$(this).removeClass("hover");});
    $(".custom_selector .head").click(handleCustomSelector);

    $(".custom_selector .options li a").click(selectCustomSelector);

    $(".updateSortBy").click(normalLinkChangeCustomSelector);
    $("#order_order, #order_by, #site_filter").change(function(event) { $("#do_search").submit(); }) ;
});


function handleCustomSelector()
{
    var head = $(this);
    var custom_selector = head.parents(".custom_selector");
    var option = custom_selector.find("ul.options");

    if(option.is(":visible"))
    {
       head.removeClass("active");
       closeCustomSelector(option);
    }
    else
    {
       head.addClass("active");
       openCustomSelector(option);
    }

    return false;
}



function openCustomSelector(option)
{
    option.fadeIn("fast");
}


function closeCustomSelector(option)
{
    option.fadeOut("fast");
}

function selectCustomSelector(){

    var value = $(this).attr("href").replace("#", "");
    var html_value = $(this).html();

    var custom_selector = $(this).parents(".custom_selector");
    var option = custom_selector.find("ul.options");
    var head_var = custom_selector.find(".head var");
    var hidden_input = custom_selector.find("input[type='hidden']");
    hidden_input.val(value);
    head_var.html(html_value);

    closeCustomSelector(option);

     $("#do_search").submit();

    return false;
}


function normalLinkChangeCustomSelector()
{
    var value = $(this).attr("href").replace("#", "");
    var hidden_input = $("input[name='order_by']");
    hidden_input.val(value);
    $("#do_search").submit();
    return false;
}
