
function search_load_cat(o) {
    var feedobj = o;
    var feed_id = $(feedobj).val();
    var showfirst = "yes";
    
    var catobj = $("#search_category");
    $(catobj).html("");
    
    if(feed_id > 0) {
    
        $.getJSON("/scripts/data.json.php", {action: "categories", feed_id: feed_id, showfirst: showfirst}, function(response){
            if(response.result == "ok") {
                $.each(response.rows, function(i, row) {
                    $("<option/>").attr("value", row.id).html(row.name).appendTo(catobj);
                });
            }
        });
    }
}

function showFeed(feed_id) {
    var urlHTML = "feed_dialog.php?feed="+feed_id;
    $.nyroModalManual({
	    modal: true,
	    resizeable: false,
        url: urlHTML,
        contentLoading: ""
    }, function(){
    });
}

var ai;

function fadeNextimage() {
    var images = $("#feed_table_rows img:hidden");
    if(images.length > 0) {
        $(images).eq(0).fadeIn(250);
    } else {
        clearInterval(ai);
    }
}

function seachSubmit(f) {
    var form = $(f);
    var val = 0;
    if($("#search_feed").val() > 0) val = val + 1;
    if($("#search_category").val().length != '') val = val + 1;
    val = val + $('#search_string').val().length;
    if(val > 0) {
        return true;
    } else {
        return false;
    }
}

$(document).ready(function(){

    $("#search_feed").change(function(){
        search_load_cat(this);
    });
    
    $("#ajaxloader").ajaxStart(function(){
        $(this).show();
    });
    
    $("#ajaxloader").ajaxStop(function(){
        $(this).hide();
    });
    
    $("#feed_table_rows a").click(function(){
       var a = this;
       var feed_id = $(this).attr("rel");
       showFeed(feed_id);
       return false;
    });
    
    
    $("#feed_table_rows img").hide();
    ai = setInterval("fadeNextimage()", 100);
    
});
