var rinka_myList_ids = new Array();
var myList_url = '/lt/ajax/myAnn/remove?ids=';

function myList_select(o, id) {
    var checked = o.src.match(/empty\.gif$/);
    if (checked) {
        o.src = o.src.replace(/empty\.gif$/, 'checked.gif');
    }
    else {
        o.src = o.src.replace(/checked\.gif$/, 'empty.gif');
    }
    
    myList_mark(id, checked);
}

// add == true it adds to the array, else it removes the value
function myList_mark(id, add) {
    if(add) {
        rinka_myList_ids.push( id );
    }
    else {
        var len = rinka_myList_ids.length;
        for(i = 0; i < len; i++) {
            if( rinka_myList_ids[i] == id ) {
                rinka_myList_ids.splice(i, 1);
                return;
            }
        }
    }
}

function myList_remove_selected() {
    if(rinka_myList_ids.length == 0) {
        alert('Pasirinkite bent vieną skelbimą, kurį norėsite pašalinti.');
    }
    else {
        var url = myList_url + rinka_myList_ids.join(',');
        window.location = url;
    }
}

function myList_remove_all() {
    var c = confirm('Ar tikrai norite pašalinti visus pažymėjimus?');
    if(c) {
        var url = myList_url + 'all';
        window.location = url;
    }
}


// Opens announcement details window
function ann_details(id, evt, comments) {
    if(!evt)
        evt = window.event;
/*    Event.stop(evt); */
    var url = '/lt/details/'+id;
    if(comments)
        url += '#comments';
    window.open(url, 'details_'+id, 'width=800,menubar=no,toolbar=no,location=no,scrollbars=yes');
}

function ann_subscribe(fid) {
    document.announcement_filter_f.action = '/lt/subscribe/announcements/'+fid;
    document.announcement_filter_f.submit();
}

function alist_item_over(o) {
    $('#'+o.id+' > .alist-body').css('backgroundColor', '#E5EAEE');
    
    /*
    var header = $('#'+o.id+' > .alist-body');
    if (header.size() > 0) {
        header.first().setStyle({backgroundColor: '#E5EAEE'});
    }
    */
}

function alist_item_out(o) {
    $('#'+o.id+' > .alist-body').css('backgroundColor', '#F1F0F5');
    
    /*
    var header = $('#'+o.id+' > .alist-body');
    if (header.size() > 0) {
        header.first().setStyle({backgroundColor: '#F1F0F5'});
    }
    */
}

function alist_select(o, id) {
    var checked = $(o).hasClass('checked');
    var url = '/lt/ajax/announcement/';
    if (checked) {
        $(o).toggleClass('checked');
        url += 'deselect/';
    }
    else {
        $(o).toggleClass('checked');
        url += 'select/';
    }
    
    /* new Ajax.Request(url + id); */
    $.post(url+id);
}

function alist_showhide_filetr() {
    if ('none' == $('#alist-filter-block').css('display')) {
        $('#alist-filter-block').css({display: 'block'});
    }
    else {
        $('#alist-filter-block').css({display: 'none'});
    }
}


$(document).ready(function() {
    /* if (Prototype.Browser.IE) { */
        var m = navigator.userAgent.match(/MSIE ([^;]*)/);
        if (m && m.length == 2 && parseFloat(m[1]) < 7) {
            $('input[type=button]', 'input[type=submit]').each(function(o) {
                o.addClass('noriu-button');
            });
        }
    /* } */
});


$(document).ready(function(){

    $('#alist-filter-block ul li').hover(
        function() {
            $(this).find('ul:first').show();
        },
        function(){
            $(this).find('ul:first').hide();
        }
    );

});


