//Requires the following libraries: jquery, highcharts.
function draw_small_index_data(indexid, containerid, periodicity, sourceDataUrl, years, type)
{
	if ($("#" + containerid).length == 0)
		return;
	
	var chart1; // globally available
	var chartColor = $('#' + containerid).css('color');
	var tickInterval = 180 * 24 * 3600 * 1000; // six months
	if(years != null && years > 3)
		tickInterval *= 2;
	
	var options = {
		chart: {
					renderTo: containerid,
					defaultSeriesType: 'line'
 		},
 		credits: {enabled: false},
 		title: {text: ''},
 		legend:{ enabled: false },
 		plotOptions: {series: {color: chartColor, marker:{enabled:false}}},
 		xAxis: {
 			type: 'datetime',//,
 			tickInterval: tickInterval,
 			lineWidth: 2
 		},
 		yAxis: {
 			title: {text: ''},
 			startOnTick: false,
 			endOnTick: false
 		},
 		series: [{
 			//pointStart: Date.UTC(2010, 0, 1),
 	        //pointInterval: 24 * 3600 * 1000, // one day
 			point: {
                events: {
                    mouseOver: function() {
                        reporting.html('x: '+ this.x +', y: '+ this.y);
                    }
                }
            },
 			name: indexid,
    		animation: true
 		}]
	};
	
	url = 'reports_indexes/indexdata/';
	if(sourceDataUrl != null)
		url = sourceDataUrl + '/';
	
	url += indexid;
	
	if(years != null){
		url += '/' + years;
	
		if(type != null)
			url += '/' + type;
	}
	
	jQuery.getJSON(url, function(data){
		if(data.length > 0){
			//Find minimum and maximum values
			var min = data[0][1];
			var max = data[0][1];
			if(data.length > 1){
				for(var i=1; i<data.length; i++){
					var value = data[i][1];
					
					if(value > max)
						max = value;
					if(value < min)
						min = value;
				}
				
				//Calculate proper tick interval for y axis
				if (max <= 1)
					options.yAxis.tickInterval = 0.5;
				else
					options.yAxis.tickInterval = Math.round((max - min)/2.5);
				
			}
		}
		
		options.series[0].data = data;
		chart1 = new Highcharts.Chart(options);
	});
}
