var defaultProject   = $('#project').prop("outerHTML");
var defaultExecution = $('#execution').prop("outerHTML");

$(function()
{
    var $showdata = $('#showdata');
    $showdata.load($showdata.data('url') + ' #dataWrapper', function()
    {
        if($.fn.datatable)
        {
            $showdata.find('table#datatable').datatable({fixedLeftWidth: 200, scrollPos: 'out', customizable: false, sortable: false, mergeRows: true, fixedHeader:true,
                ready:function()
                {
                    $('div.table-footer').css('width', $('#datatable-datatable').width());
                    fixScroll();
                    setTimeout(function()
                    {
                        $('.bar').css('left', '0px');
                        $('.datatable-wrapper .table-datatable').css('left', '0px');
                        $('.iframe').modalTrigger();
                    }, 100);
                }
            });
        }

        if(parseInt($('#product').val()) > 0)
        {
            $('#product').trigger('change');
        }
        else if($('#project') && parseInt($('#project').val()) > 0)
        {
            $('#project').trigger('change');
        }
    });

    var dateVal = $('#featurebar ul.nav li #date').val();
    $('#date').focus(function(){$(this).val('').datetimepicker('update');}).blur(function(){$(this).val(dateVal)});
    if($('#showAll').prop('checked'))
    {
        $('.side #user').attr('disabled', true);
        $('.side #user').trigger("chosen:updated");
    }
    $('#showAll').change(function()
    {
        if($(this).prop('checked'))
        {
            $('.side #user').attr('disabled', true);
        }
        else
        {
            $('.side #user').removeAttr('disabled');
        }
        $('.side #user').trigger("chosen:updated");
    });
    flushWidth('#sidebar .detail');
});

$(window).resize(function()
{
    $('div.table-footer').css('width', $('#datatable-datatable').width());
    $('div.datatable-rows .fixed-left tr').each(function(index)
    {
        var leftHeight  = $(this)[0].getBoundingClientRect().height;
        var rightHeight = $('div.datatable-rows .flexarea tr').eq(index)[0].getBoundingClientRect().height;

        if(leftHeight < rightHeight) $(this).height(rightHeight);
        if(leftHeight > rightHeight) $('div.datatable-rows .flexarea tr').eq(index).height(leftHeight);
    });
})
