$(document).ready(function(){
	var i = 1;
	var a;
	rotate = function(){
		$('.stripe' + i).fadeOut(2000);
		if(i==3){i=0;}
		i++;
		$('.stripe' + i).fadeIn(2000);
	};

	BlackStripes = function(){
		play = setInterval(function(){rotate();}, 6000);
	};

	BlackStripes();
			
	/* ODPOCET */
	var cofday = 7616;
	var kgday = 54.4;

	var timestamp = "1329942838";
	var beginning = "983232001"; // a second after midnight of that day
	var date = new Date();
	var day = 86400;
	var secondsleft = timestamp - beginning;
	var daysLeft = secondsleft;
	daysLeft = Math.floor(daysLeft/day);

	counting = function(){
		var i = parseInt($('.coffees').text());
		i++;
		$('.coffees').html(i);
	};

	Counter = function(){
		play = setInterval(function(){counting();}, 5672);
	};
		resultDays = function(days, amount){
		return Math.round(days * amount);
	};

	var hour = date.getHours();
	if(hour<8) {
		$('.coffees').html(resultDays(daysLeft, cofday));
		$('.kilos').html(resultDays(daysLeft, kgday));
	}
	else if(hour>20) {
		$('.coffees').html(resultDays(daysLeft + 1, cofday));
		$('.kilos').html(resultDays(daysLeft + 1, kgday));
	}
	else {
		var tempcof = resultDays(daysLeft, cofday);
		var tempkg = resultDays(daysLeft, kgday);
		var temp2 = daysLeft*day;
		temp2 = secondsleft - temp2 - 8 * 60 * 60;

		tempcof = tempcof + (cofday / (12 * 60 * 60)) * temp2;
		tempkg = tempkg + (kgday / (12 * 60 * 60)) * temp2;
		$('.coffees').html(Math.floor(tempcof));
		$('.kilos').html(Math.floor(tempkg));

		Counter();
	}

	/* end of ODPOCET */
});
