$(document).ready(function() {

    // hide the filter button
    $("#recipe-sort").hide();

    // browse recipes filter
    $("#filter input[name*='filter']").click(function() {
        $.ajax({
            type: "POST",
            url: "/recipes/browse/" + this.value,
            success: function (msg) {
                $("#browse").html(msg);
            }
        });
		
    });
    
    // search results filter
    var order;
    $("#search-order input[name*='filter']").click(function() {
        if ( order == 1 ) {
            order = 2;
        }
        else {
            order = 1;
        }
        $.ajax({
            type: "POST",
            url: "/search",
            data: "recipe-search=" + $("#recipe-search").val() + "&filter=" + this.value + "&order=" + order,
            success: function (msg) {
                $("#result").html(msg);
            }
        });
    });
   
   // see more recipes
    $("p.see-more-recipes a").click(function(e) {
        e.preventDefault();
        // filter = $("input[name='filter']:checked").val();
        $.ajax({
            type: "POST",
            url: "/recipes/browse/more",
            // data: "filter=" + filter,
            success: function (msg) {
                $("#browse").html(msg);
                scroll(0,0);
            }
        });
        
    });
   
});


