jQuery(document).ready(function ($) {
    previousPoint = null;

   $('.pos').each(function() {
		$(this).parent('td').parent('tr').next('tr.history').hide();
        
		$(this).click(function() {
			con = $(this).parent('td').parent('tr').next('tr.history');

            if ($(con).is(":visible")) {
                $(con).children('td').children('div').slideUp(function() {
                    $(con).hide();
                });
                $(this).html('+');
                
            } else {
                $(this).html('-');
                $(con).show();
                $(con).children('td').children('div').slideDown();
            
                span = $(this)
                
    			var t = new Date().getTime();
    			$.ajax({
    				url: path + '/?feed=lhist&team=' + $(span).attr('id') + '&comp=' + $(span).attr('comp') + '&d=' + t,
    				type: 'GET',
    				dataType: 'xml',
    				timeout: 1000,
    				
    				success: function(xml){
                        $(con).children('td').html('<div class="chart" style="width:570px;height:120px;"></div>');
                        
                        data = [];
        				$(xml).find('match').each(function(i){
                            data.push([i,parseInt($(this).text())]);
        				});
                        plot(data,$(con).children('td').children('div.chart'))
    				}
    			});
            
            }
		
		});
	});
});

function plot(data, holder) {
    var options = {
        points: { show: false },
        lines: { show: true },
        grid: {
            borderWidth: 0,
        },
        xaxis: {
            tickSize: 5,
            tickDecimals: 0
        },
        yaxis: {
            tickDecimals: 0
        },        
    }
    
    $.plot($(holder), [data], options);
}

