$("document").ready(function() {
    
    $("#filter_categories").mouseup(function() {
        $("#categoryFilter").dialog('open');
    });

    $("#categoryFilter").dialog({
			height: "auto",
                        opacity: 0.8,
                        width: 700,
			modal: true,
                        position: ['center','100'],
                        autoOpen: false
    });
    
    $("input.category_toggle").button();
    
    
    $("#categoryFilterUpdate").mouseup(function() {
        
        var notChecked = "";
        $(".category_toggle:input:not(:checked)").each(function() {
            // Build the Not Checked list.
            thisID = $(this).attr('title');
            notChecked = notChecked+""+thisID+"|";
        });
    
        if (notChecked == undefined || notChecked == "" || notChecked == null) {
            notChecked = 0;
        }
        
    
        $.ajax({
            type: "GET",
            url: "./assets/functions/ajax.php?function=categoryFilterUpdate&filter="+notChecked,
            cache: false,
            beforeSend: function() {
                $("#categoryFilterUpdate").attr({disabled: true}).val("Updating...");
            },
            success: function(output) {
                if (output.substr(0,5) == "ERROR") {
                    alert(output);
                } 
                $("#categoryFilterUpdate").val("Updated! Refresh page for changes to take effect.").effect("highlight", {}, 6000, function() {
                    $("#categoryFilterUpdate").attr({disabled: false}).val("Update");
                });
                
            }
        });
    
    });
    
    
    // Rating page filter
    $("#searchRatingFilter").on("change", function() {
	window.location = site+"/rating/"+$("#ratingValue").text();
    });

    
    
});
