var logged_in;

jQuery.ajaxSetup({
   'beforeSend': function(obj){obj.setRequestHeader("Accept","text/javascript")}
});

$(document).ready(function()
{

    $("#big-search-box").Watermark("ex: wordpress, seo, facebook...");

    $(".positive-checkbox").change(function()
    {
        var className = $(this).attr('checked') ? "positive" : "negative";
        $('.comment-form').removeClass('positive');
        $('.comment-form').removeClass('negative');
        $('.comment-form').addClass(className);
    });

    var last_search = "";
    var search_required = false;

    $("#big-search-box").bind("keyup", function() {
      if (!search_required)
      {
        search_required = true;  
        $("#big-search-box").addClass("loading"); // show the spinner
        setTimeout(search, 1000);
      }
    });

    function search()
    {
        search_required = false;

        if ($("#big-search-box").val() == last_search)
        {
            $("#big-search-box").removeClass("loading"); // hide the spinner
            return;
        }
        var form = $("#live-search-form"); // grab the form wrapping the search bar.
        var url = "/tasks/live_search"; // grab the URL from the form's action value.
        var formData = form.serialize(); // grab the data in the form
        last_search = $("#big-search-box").val();
        $.get(url, formData, function(html) { // perform an AJAX get, the trailing function is what happens on successful get.
          $("#big-search-box").removeClass("loading"); // hide the spinner
          $("#live-search-results").html(html); // replace the "results" div with the result of action taken
        });
    }

});

