/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

$(function() {
    $('.tb_listagem .comparacao').live('click',function() {
       $Clone = $(this).parents('tr').clone(true).attr({ 'id':'temp_'+$('.tb_listagem tr[class!=selected]').index($(this).parents('tr')) });
       
       if($('tr[id^="temp_"]').length > 0) {
           $($Clone).insertAfter('tr[id^="temp_"]:last');
       }
       else {
           $($Clone).insertBefore($('.tb_listagem tr:has(td)').eq(0));   
       }
       $(this).parents('tr').hide();
       $cInput = $Clone.find('.comparacao');
       $('<div class="excluir_comparacao" style="cursor:pointer;" onclick="removeComparacao( $(this).parents(\'tr\').attr(\'id\') )">[x]</div>').insertBefore($cInput);
       $Clone.addClass('selected').find('.comparacao').hide();
       return false;
    });
    
});
function removeComparacao(Id) {
    $('.tb_listagem #'+Id).remove();
    nId = parseInt(Id.replace('temp_', ''));
    $('.tb_listagem tr[class!=selected]').eq(nId).show();
    
}