function show_resultes(event) {
    var tag_name = $$('input[name=tag]').getLast().get('value');
    var show_by = $$('#show_by a[alt=active]').getLast().get('text');
    var order_by = $$('#order_by a[alt=active]').getLast().get('text');
    var jsonRequest = new Request.JSON({
        url: "/tagssearch/",
        method: 'get',
        data: {q: tag_name, show_by: show_by, order_by: order_by},
        onComplete: function(json){
            $('index_tag_cloud_content').empty();
            if(json.tags.length){
            json.tags.each(function(item){
                var tag  = new Element('a', {class: 'font'+item[1], html: item[0], href: '/code/tag/?tag='+item[0]})
                var sup = new Element('sup', {html: item[2]+' '})
                tag.inject('index_tag_cloud_content');
                sup.inject('index_tag_cloud_content');
            });
            }else{
                var el = new Element("div", {html: "<span>No tags found</span>"})
                el.inject('index_tag_cloud_content');
            }
        }
    }).send();
    event.stop();
}

window.addEvent('domready', function() {
    $$("input[name=tag]").addEvent('keyup', function(event) {
        show_resultes(event);

    });
    $$('#show_by a').addEvent('click', function(event) {
        $$('#show_by a').set('alt', '');
        $$('#show_by a').removeClass('nounderline');
        $$('#show_by a').removeClass('bold');
        this.set('alt', 'active');
        this.addClass('nounderline');
        this.addClass('bold');
        show_resultes(event);
    });
    $$('#order_by a').addEvent('click', function(event) {
        $$('#order_by a').set('alt', '');
        $$('#order_by a').removeClass('nounderline');
        $$('#order_by a').removeClass('bold');
        this.set('alt', 'active');
        this.addClass('nounderline');
        this.addClass('bold');
        show_resultes(event);
    });
});

