$(document).ready(function()
{

	/*
	 *	MORRISS, CHART
	 */

	// aktywność

	if (exists('#graph_activity'))
	{
		var graph_activity = Morris.Line({
			resize: true,
			element: 'graph_activity',
			data: null,
			xkey: 'day',
			ykeys: ['visit', 'comment', 'register', 'avg'],
			labels: ['Visit', 'Comments', 'Register', 'avg'],
			lineColors: ['orange', 'blue', 'green', 'silver', 'navy']
		});

		// WYKRES

		$.ajax({
			type: "GET",
			dataType: 'json',
			url: base_url + 'dashboard/dashboard_ajax/stats_daily/' + $('#CrDate_open').val() + '/' + $('#CrDate_close').val()
		})
				.done(function(data) {
					if (data)
					{
						$('#graph_activity_container').removeClass('hidden');
						graph_activity.setData(data);
					}
				});
	}

	// toop read

	if (exists('#graph_top_read'))
	{
		var graph_top_read = Morris.Line({
			resize: true,
			element: 'graph_top_read',
			data: null,
			xkey: 'day',
			ykeys: ['value', 'avg'],
			labels: ['Time', 'Avg'],
			lineColors: ['orange', 'silver']
		});

		// WYKRES

		$.ajax({
			type: "GET",
			dataType: 'json',
			url: base_url + 'dashboard/dashboard_ajax/top_read_daily/' + $('#CrDate_open').val() + '/' + $('#CrDate_close').val()
		})
				.done(function(data) {
					if (data)
					{
						$('#graph_top_read_container').removeClass('hidden');
						graph_top_read.setData(data);
					}
				});
	}

	// top refererrs

	if (exists('#chart_top_referrers'))
	{
		var graph = Morris.Donut({
			resize: true,
			element: 'chart_top_referrers',
			data: [{}]
		});

		// WYKRES

		$.ajax({
			type: "GET",
			dataType: 'json',
			url: base_url + 'dashboard/dashboard_ajax/top_referrers/' + $('#CrDate_open').val() + '/' + $('#CrDate_close').val()
		})
				.done(function(data) {
					if (data)
					{
						$('#chart_top_referrers_container').removeClass('hidden');
						graph.setData(data);
					}
				});
	}

	// top refererrs countries

	if (exists('#chart_top_countries'))
	{
		var graph2 = Morris.Bar({
			resize: true,
			element: 'chart_top_countries',
			data: null,
			xkey: 'country',
			ykeys: ['count'],
			labels: ['Count']
		});


		// WYKRES

		$.ajax({
			type: "GET",
			dataType: 'json',
			url: base_url + 'dashboard/dashboard_ajax/top_countries/' + $('#CrDate_open').val() + '/' + $('#CrDate_close').val()
		})
				.done(function(data) {
					if (data)
					{
						$('#chart_top_countries').removeClass('hidden');
						graph2.setData(data);
					}
				});
	}

	// top refererrs cities

	if (exists('#chart_top_cities'))
	{
		var graph3 = Morris.Bar({
			resize: true,
			element: 'chart_top_cities',
			data: null,
			xkey: 'city',
			ykeys: ['count'],
			labels: ['Count']
		});

		// WYKRES

		$.ajax({
			type: "GET",
			dataType: 'json',
			url: base_url + 'dashboard/dashboard_ajax/top_cities/' + $('#CrDate_open').val() + '/' + $('#CrDate_close').val() + '/' + $('#country').val()
		})
				.done(function(data) {
					if (data)
					{
						$('#chart_top_cities').removeClass('hidden');
						graph3.setData(data);
					}
				});
	}

	// słupki popularność

	if (exists('#graph_popularity'))
	{
		var graph_popularity = Morris.Line({
			resize: true,
			element: 'graph_popularity',
			data: null,
			xkey: 'month',
			ykeys: ['visit'],
			labels: ['Visit']
		});

		// WYKRES

		$.ajax({
			type: "GET",
			dataType: 'json',
			url: base_url + 'dashboard/dashboard_ajax/stats_monthly'
		})
				.done(function(data) {
					graph_popularity.setData(data);
				});
	}
});

