/**
 * Handle: charts script    
 * Version: 0.0.1
 * Deps: $jq
 * Enqueue: true
 */

(function($) {
	
	$.fn.drawChart = function(data1,data2,labels,legende,seriesnum) {	
		
		var holder = $(this).attr("id");
		var figures;
	
		var r = Raphael(holder, 442, 200);
		if (seriesnum == "1") figures = [data1];
		else figures = [data1,data2];
		
		var chart = r.g.barchart(20, 10, 402, 160, figures, {stacked: false, type: "soft"}); 		
		
		chart.label([labels], true);

		chart.hover(function() {
        // Create a popup element on top of the bar
        this.flag = r.g.popup(this.bar.x, this.bar.y, (this.bar.value || "0") + " " + legende).insertBefore(this);
    	}, function() {
        // hide the popup element with an animation and remove the popup element at the end
        this.flag.animate({opacity: 0}, 300, function () {this.remove();});
    	});
		
		for (var i = 0; i < chart.bars[0].length; i++) {
       		var bar = chart.bars[0][i];
        	// if the value of the bar is greater or equals to 15 we change the color to red
            bar.attr("fill","#1094bf");
			bar.attr("stroke","#1094bf");
        }
		
		if (seriesnum != "1") {
			for (var i = 0; i < chart.bars[1].length; i++) {
				var bar = chart.bars[1][i];
				// if the value of the bar is greater or equals to 15 we change the color to red
		   
				bar.attr("fill","#cd071e");
				bar.attr("stroke","#cd071e");    
			}
		}
	}	
}) (jQuery);


	
	
	
