/* pulldown filter functions */
var currentFilter = null;

function toggle_filter(fid) {
    var fobj, flist, fpopout;

    if (currentFilter) {
        id = '#' + currentFilter.attr('id');
        if (id != fid) {
            currentFilter.find('.Popout').css('display', 'none');
        }
    }

    fobj = $(fid);
    currentFilter = fobj;

    fpopout = fobj.find('.Popout');
    flist = fpopout.find('.Content > ul');
        
    if(fpopout.css('display') == 'block') {
        fpopout.css('display', 'none');
    } else {
        fpopout.css('display', 'block');

        if (flist.height() > 200) {
            //if on the ipad, don't show any scrollbars
            var isiPad = navigator.userAgent.match(/iPad/i) != null;
            if (!isiPad) {
                flist.css('height', '200px');
                flist.jScrollPane({scrollbarWidth:5});
            }
        }
        $(document).bind("click", function (e) {
            if (!e) {
                var e = window.event; // IE compatibility
            }
            var eobj = e.srcElement;
            if (!eobj) {
                eobj = e.target;
            }
            var tmp = $(eobj).attr('id');
            if (!tmp || !fobj.find('#' + tmp) || tmp == "pagination") {
                fpopout.css('display', 'none');
                $(document).unbind('click');
            }
        });
    }
}

