var _PlotInfo = [];
var trn  = 'rgba(0,0,0,0)';
var plotopts = {
		grid:{drawGridLines:false, gridLineColor:trn,background:trn,borderColor:trn,shadow:false},
		seriesDefaults:{color: '#FFFFFF',lineWidth: 6,markerOptions: {size: 18,color: '#ec9a2c'}},
		series:[{breakOnNull: true}],
		axes: { xaxis: {show:false,showTicks:false,numberTicks: 22,max:21,min:0,pad:1}, yaxis:{show:false,showTicks:false,numberTicks: 24,max:1,min:24,pad:1}}
};

function handleToolTip(ev, gridpos, datapos, neighbor, plot) {
	if (neighbor == null) {
		$('#PlotToolTip').hide('fast',function(){ $('#PlotToolTip .text').empty(); });
		isShowing = false;
	}
	if (neighbor != null) {
		if(_PlotInfo[neighbor.pointIndex]!=undefined)
		{
			if ($('#PlotToolTip').is(':hidden')) {
				
				var html = "";
				if(lang == 'ru')
				{
				 html = "<b>"+_PlotInfo[neighbor.pointIndex].title
							+"</b><br /><b>"+_PlotInfo[neighbor.pointIndex].pos+"-е место,</b> быстрейший круг: "+_PlotInfo[neighbor.pointIndex].besttime
							+"<br />Квалификация: "+_PlotInfo[neighbor.pointIndex].qualpos+"-е место, "+_PlotInfo[neighbor.pointIndex].qualtime;
				}else{
				 html = "<b>"+_PlotInfo[neighbor.pointIndex].title_en
							+"</b><br /><b>"+_PlotInfo[neighbor.pointIndex].pos+" position,</b> faster lap: "+_PlotInfo[neighbor.pointIndex].besttime
							+"<br />Qualification: "+_PlotInfo[neighbor.pointIndex].qualpos+" position, "+_PlotInfo[neighbor.pointIndex].qualtime;
				}
				$('#PlotToolTip .text').html(html);
				$('#PlotToolTip').css({left:gridpos.x+20, top:gridpos.y-35}).show('fast');
			}
		}
	}
}

function paintPlot(id,data)
{
	$.jqplot.eventListenerHooks.push(['jqplotMouseMove', handleToolTip]);	
	_PlotInfo = data;
	var graph = [];
	$.each(_PlotInfo,function(k,v){ graph.push(v.pos);});
	$.jqplot(id,  [graph],	plotopts);	
}

function initPlot(div,json)
{
	if($.browser.msie)
	{
		$.getScript('/sites/all/themes/vpetrov/lib/plot/excanvas.js',function(){ $.getJSON(json,function(data){ paintPlot(div,data.info);}); });
	}else{
		$.getJSON(json,function(data){ paintPlot(div,data.info);});
	}
	$('#'+div).append('<div id="PlotToolTip"><div class="text"></div></div>');	
}
