var weekday=0;
var hour=10;
var minute=30;

var lengthminutes=90;
var previewminutes=5;

function getTimeLeft() {
	var now = new Date();
	var left = ((weekday+7) - now.getDay()) * 24 * 60 * 60;
	left += (hour - now.getHours()) * 60 * 60;
	left += (minute - now.getMinutes()) * 60;
	left += (0 - now.getSeconds());
	left += lengthminutes * 60;
	left %= 7 * 24 * 60 * 60;
	left -= lengthminutes * 60;
	if(left < 0) {
		return 0;
	} else {
		return left;
	}
}

$.fn.updateTimeLeft = function() {
	var timeLeft = getTimeLeft();
	if(timeLeft <= 60 * previewminutes) {
		$('.waiting',this).hide();
		$('.active',this).show();
		//
	} else {
		$('.waiting',this).show();
		$('.active',this).hide();
		$('.days',this).text(Math.floor(timeLeft / (60 * 60 * 24)));
		$('.hours',this).text(Math.floor(timeLeft / (60 * 60)) % 24);
		$('.minutes',this).text(Math.floor(timeLeft / 60) % 60);
		$('.seconds',this).text(timeLeft % 60);
	}
};
