(function($) {
    $.fn.liveTable = function(targetIds) {
        for(var i=0; i < targetIds.length; i++) {
            // Allow the current target ID to be available in the following functions 
            var targetID = targetIds[i];

            // Bind all anchors
            $('div#'+targetID+' a').live('click', function() {
                // Call load table with the given ID and href of THIS anchor
                loadTable($('div#'+targetID), this.href + "&" + getTsQs());
                return false;
            });

            // Bind all TRs that have a partner row
            $('div#'+targetID+' tbody tr.hasFullview').live('click', function(event) {
                // Stop this event if a checkbox contained in the li is clicked
                if($(event.target).is('input:checkbox')) {
                    ajaxToggleExcludeTableItem(event.target);
                    return;
                }
                // Find out if THIS rows partner row is hidden
                var hidden = $(this).next().is(":hidden");
                // hide all other 'fullview' table rows
                //$(this).siblings("tr.fullview").hide();
                //$(this).siblings("tr.hasFullview").removeClass("up").attr("title","Show job summary");
                // If THIS rows partner row was hidden, now show it
                if(hidden) {
                    $(this).next().show();
                } else {
                    $(this).next().hide();
                }
                //To toggle show/hide arrow and its title attr
                $(this).find("td div.arrow").toggleClass("up");
                $(this).find("td div.arrow").attr("title","Show job summary");
                $(this).find("td div.up").attr("title","Hide job summary");
            });

            // Bind the partner rows
            $('div#'+targetID+' tbody tr.fullview').live('click', function(){
                // Hide THIS row (you can only click on it if it is already shown)
                $(this).toggle();
                //To toggle show/hide arrow and its title attr
                $(this).prev().find("td div.arrow").toggleClass("up");
                $(this).prev().find("td div.arrow").attr("title","Show job summary");
                $(this).prev().find("td div.up").attr("title","Hide job summary");
            });

        }
    };
})(jQuery);    
