$(document).ready(function()
    {
        var plus = '/images/design/icon-table-open.gif';
        var minus = '/images/design/icon-table-close.gif';
        $('.expandable').click(function()
        {
            var k = $(this).hasClass('expanded');

            if(k == 1)
            {
                //needs to collapse
               
                $(this).removeClass('expanded').parent().parent().removeClass('tbl-row-open').next().hide();
                if($(this).parent().parent().next().next().hasClass('tbl-row-first'))
                {
                    $(this).parent().parent().next().next().removeClass('tbl-row-first');
                }
                $(this).children('img').attr('src', plus).attr('alt', 'Close');
                $(this).parent().parent().removeClass('tbl-row-open-first');
                var z = $(this).parent().parent().next().next().hasClass('tbl-row-open-first');
                if(z)
                {
                    $(this).parent().parent().next().next().removeClass('tbl-row-open-first');
                }
            }
            else
            {
                //needs to expand

                $(this).addClass('expanded');

                //OK, change the class of this row and open the info panel
                $(this).parent().parent().addClass('tbl-row-open').next().show();

                //OK, now check the next row to see if it has the class of first. if so, steal it and put it on this row
                var test = $(this).parent().parent().next().next().hasClass('tbl-row-first');
                if(!test)
                {
                    $(this).parent().parent().next().next().addClass('tbl-row-first');
                }
                $(this).children('img').attr('src', minus).attr('alt', 'Expand');

                var o = $(this).parent().parent().prev().prev().children().children('a').hasClass('expanded');
                if(o)
                {
                    $(this).parent().parent().addClass('tbl-row-open-first');
                }
                var c = $(this).parent().parent().next().next().children().children('a').hasClass('expanded');
                var t = $(this).parent().parent().next().next().hasClass('tbl-row-open-first');
                if(c && !t)
                {
                    $(this).parent().parent().next().next().addClass('tbl-row-open-first');
                }

                var jeff = $(".data-tbl tr:eq(1)").children().children('a').hasClass('expanded')
                if(jeff)
                {
                    $(".data-tbl tr:eq(1)").addClass('tbl-row-open-first')
                }

            }
            return false;
        });
    });
function updateExpanded(el){
    var plus = '/images/design/icon-table-open.gif';
    var minus = '/images/design/icon-table-close.gif';
    var k = $(el).hasClass('tbl-row-open');

    if(k == 1)
    {
        $(el).removeClass('tbl-row-open-first');
        //needs to expand
        //OK, now check the next row to see if it has the class of first. if so, steal it and put it on el row
        var test = $(el).next().next().hasClass('tbl-row-first');
        if(!test)
        {
            $(el).next().next().addClass('tbl-row-first');
        }
        var o = $(el).prev().prev().children().children('a').hasClass('expanded');
        if(o)
        {
            $(el).addClass('tbl-row-open-first');
        }
        var c = $(el).next().next().children().children('a').hasClass('expanded');
        var t = $(el).next().next().hasClass('tbl-row-open-first');
        if(c && !t)
        {
            $(el).next().next().addClass('tbl-row-open-first');
        }

        var jeff = $(".data-tbl tr:eq(1)").children().children('a').hasClass('expanded')
        if(jeff)
        {
            $(".data-tbl tr:eq(1)").addClass('tbl-row-open-first')
        }
    }else{
         $(el).removeClass('tbl-row-first');
         $(el).removeClass('tbl-row-open-first');
    }
    
}
