function SmallTermometr (term_date, term_month, term_year, term_hour, term_minute, cdate, cmonth, cyear, chour, cminute, city, env) {
	/* Time */
	var termDayDate = new Date (term_year, term_month - 1, term_date, 0, 0, 0);
	var termDayStamp = termDayDate.getTime();
		
	this.cdate = cdate;
	this.cmonth = cmonth;
	this.cyear = cyear;
	this.chour = chour;
	this.cminute = cminute;
	this.city = city;
	var cDayDate =  new Date (cyear, cmonth - 1, cdate, chour, cminute, 0);
	var cStamp = cDayDate.getTime();
	stzmanim.latitude = city.latitude;
	stzmanim.longitude = city.longitude;
	stzmanim.timezone = city.gmt + city.swtime;
	stzmanim.set_knissat(city.shabatAdj);
	var doys = getDoys (term_date, term_month, term_year);
	stzmanim.day_of_year = doys[0];
	stzmanim.day_of_year_prev = doys[1];
	stzmanim.day_of_year_next = doys[2];
	stzmanim.set_zmanim();
		
	// Change by hatzot
	var hatzot2 = stzmanim.zmanim[stzmanim.get_zman_key_by_keyword ("hatzot2")];
	var hatzot1 = stzmanim.zmanim[stzmanim.get_zman_key_by_keyword ("hatzot1")];
			
	if (hatzot2.time < 24) {
		if (cStamp > termDayStamp + Math.ceil(hatzot2.time*3600000)) {
				termDayStamp += 24*60*60*1000;
				var newTermDate = new Date (termDayStamp);
				term_date = newTermDate.getDate();
				term_month = newTermDate.getMonth() + 1;
				term_year = newTermDate.getFullYear();
				term_hour -= 24; 
				doys = getDoys (term_date, term_month, term_year);
				stzmanim.day_of_year = doys[0];
				stzmanim.day_of_year_prev = doys[1];
				stzmanim.day_of_year_next = doys[2];
				stzmanim.set_zmanim();
		}
	} else if (hatzot1.time < 12) {
		if (cStamp < termDayStamp + Math.ceil(hatzot1.time*3600000)) {
				termDayStamp -= 24*60*60*1000;
				var newTermDate = new Date (termDayStamp);
				term_date = newTermDate.getDate();
				term_month = newTermDate.getMonth() + 1;
				term_year = newTermDate.getFullYear();
				term_hour += 24; 
				doys = getDoys (term_date, term_month, term_year);
				stzmanim.day_of_year = doys[0];
				stzmanim.day_of_year_prev = doys[1];
				stzmanim.day_of_year_next = doys[2];
				stzmanim.set_zmanim();
		}
	}
	
	this.term_date = term_date;
	this.term_month = term_month;
	this.term_year = term_year;
	this.term_hour = term_hour;
	this.term_minute = term_minute;
	var	hDate = getHebFromCiv(this.term_date, this.term_month, this.term_year);
	this.hdate = hDate.date;
	this.hmonth = hDate.month;
	this.hyear = hDate.year;
	
	var termDate = new Date (term_year, term_month - 1, term_date, 1, 1, 1);
	var termStamp = termDate.getTime();
		
	this.term_dow =  termDate.getDay();
		
	var prevTermDate = new Date(termStamp - 24*60*60*1000);
	this.prev_term_date = prevTermDate.getDate();
	this.prev_term_month = prevTermDate.getMonth() + 1;
	this.prev_term_year = prevTermDate.getFullYear();
	this.prev_term_dow = this.term_dow - 1 < 0 ? 6 : this.term_dow - 1;
	var	prevhDate = getHebFromCiv(this.prev_term_date, this.prev_term_month, this.prev_term_year);
	this.prevhdate = prevhDate.date;
	this.prevhmonth = prevhDate.month;
	this.prevhyear = prevhDate.year;
		
	var nextTermDate = new Date(termStamp + 24*60*60*1000);
	this.next_term_date = nextTermDate.getDate();
	this.next_term_month = nextTermDate.getMonth() + 1;
	this.next_term_year = nextTermDate.getFullYear();
	this.next_term_dow = this.term_dow + 1 > 6 ? 0 : this.term_dow + 1;
	var	nexthDate = getHebFromCiv(this.next_term_date, this.next_term_month, this.next_term_year);
	this.nexthdate = nexthDate.date;
	this.nexthmonth = nexthDate.month;
	this.nexthyear = nexthDate.year;
			
	this.mercury_pos = this.term_hour + this.term_minute/60;
	this.mercury_width = 0;
	this.beforeMercuryZman = null;
	this.afterMercuryZman = null;
		
	this.yesterday_moadim = new Array();
	this.tomorrow_moadim = new Array();
	this.today_moadim = new Array();
		
	this.today_moadim = moadim.get_current_moadim (this.term_date, this.term_month, this.term_year, city.galut);
	this.tomorrow_moadim = moadim.get_current_moadim (this.next_term_date, this.next_term_month, this.next_term_year, city.galut);
	this.yesterday_moadim = moadim.get_current_moadim (this.prev_term_date, this.prev_term_month, this.prev_term_year, city.galut);
	this.setup_zmanim ();	
}

function SmallTermometr_setup_zmanim () {
	today_moadim_is_jom_tov = moadim.moadim_is_jom_tov (this.today_moadim, this.term_date, this.term_month, this.term_year);
	tomorrow_moadim_is_jom_tov = moadim.moadim_is_jom_tov (this.tomorrow_moadim, this.next_term_date, this.next_term_month, this.next_term_year);
	stzmanim.zmanim[stzmanim.get_zman_key_by_keyword ("knissat")].visible = false;
	stzmanim.zmanim[stzmanim.get_zman_key_by_keyword ("motzei_tov")].visible = false;
	stzmanim.zmanim[stzmanim.get_zman_key_by_keyword ("motzei")].visible = false;
	stzmanim.zmanim[stzmanim.get_zman_key_by_keyword ("tzeit")].visible = true;
	$('#sttzeit').removeClass('nereg');
	
	if (this.term_dow == 5 || (today_moadim_is_jom_tov  == false && tomorrow_moadim_is_jom_tov  == true)) {
		var knissat = stzmanim.zmanim[stzmanim.get_zman_key_by_keyword ("knissat")];
		knissat.visible = true;
		knissat.offset = -1;
		var sunset = stzmanim.zmanim[stzmanim.get_zman_key_by_keyword ("sunset")];
		sunset.offset = 1;
		var tzeit = stzmanim.zmanim[stzmanim.get_zman_key_by_keyword ("tzeit")];
		tzeit.offset = 0;
	} 
	
	if (this.term_dow == 6) {
		var motzei =  stzmanim.zmanim[stzmanim.get_zman_key_by_keyword ("motzei")];
		motzei.visible = true;
		motzei.offset = 2;
		var tzeit = stzmanim.zmanim[stzmanim.get_zman_key_by_keyword ("tzeit")];
		tzeit.visible = false;
		var sunset = stzmanim.zmanim[stzmanim.get_zman_key_by_keyword ("sunset")];
		sunset.offset = 0;			
	} else if (today_moadim_is_jom_tov == true && tomorrow_moadim_is_jom_tov == false && this.term_dow != 5) {
		var motzei =  stzmanim.zmanim[stzmanim.get_zman_key_by_keyword ("motzei_tov")];
		motzei.visible = true;
		motzei.offset = 2;
		var tzeit = stzmanim.zmanim[stzmanim.get_zman_key_by_keyword ("tzeit")];
		tzeit.visible = false;
		var sunset = stzmanim.zmanim[stzmanim.get_zman_key_by_keyword ("sunset")];
		sunset.offset = 0;			
	} else if (today_moadim_is_jom_tov == true && tomorrow_moadim_is_jom_tov == true && this.term_dow != 5) {
		var tzeit = stzmanim.zmanim[stzmanim.get_zman_key_by_keyword ("tzeit")];
		tzeit.nereg = true;
		$('#sttzeit').addClass('nereg');
	}
}
SmallTermometr.prototype.setup_zmanim = SmallTermometr_setup_zmanim;

function SmallTermometr_setup_zmanim () {
	var zwidth = 0;
	for (index in stzmanim.zmanim) {
		if (stzmanim.zmanim[index].visible == true && stzmanim.zmanim[index].exist == true) {
			var zmandiv = $('#st'+stzmanim.zmanim[index].keyword);
			zwidth = zmandiv.outerWidth();
			stzmanim.zmanim[index].width = zwidth;
			zmandiv.children('.ter_time').text(timeadj(stzmanim.zmanim[index].time, this.city.ampm, stzmanim.zmanim[index].roundup));
		}
	}
}
SmallTermometr.prototype.setup_zmanim = SmallTermometr_setup_zmanim;

function SmallTermometr_show_zmanim (i1, i2) {
	for (index in stzmanim.zmanim) {
		var zmandiv = $('#st'+stzmanim.zmanim[index].keyword);		
		if (index == i1 || index == i2) {
			zmandiv.show();
		} else {
			zmandiv.hide();
		}
	}
}
SmallTermometr.prototype.show_zmanim = SmallTermometr_show_zmanim;

function SmallTermometr_adjustMercury () {
	afterMercuryZman_index = 0;
	beforeMercuryZman_index = 0;
	for (index in stzmanim.zmanim) {
		if (stzmanim.zmanim[index].visible == true && stzmanim.zmanim[index].exist == true) {
			if (stzmanim.zmanim[index].time < this.mercury_pos) {
				beforeMercuryZman_index = index;
			} else {
				afterMercuryZman_index = index;
				break;
			}
		}
	}
	
	if (this.afterMercuryZman == null || this.afterMercuryZman.time < this.mercury_pos || this.beforeMercuryZman.time > this.mercury_pos) {
		this.afterMercuryZman = stzmanim.zmanim[afterMercuryZman_index];
		this.beforeMercuryZman = stzmanim.zmanim[beforeMercuryZman_index];
		$('#st'+stzmanim.zmanim[beforeMercuryZman_index].keyword).css('left', "-7px");
		$('#st'+stzmanim.zmanim[beforeMercuryZman_index].keyword).children('div').each(function(){ $(this).css('text-align','left'); });
		$('#st'+stzmanim.zmanim[afterMercuryZman_index].keyword).css('left', (parseInt(STscaleWidth, 10) + 7 - this.afterMercuryZman.width) + "px");
		$('#st'+stzmanim.zmanim[afterMercuryZman_index].keyword).children('div').each(function(){ $(this).css('text-align','right'); });
		this.show_zmanim (beforeMercuryZman_index, afterMercuryZman_index);
	}
	
	var k1 = STscaleWidth;
	var k2 = (this.mercury_pos - this.beforeMercuryZman.time)/(this.afterMercuryZman.time - this.beforeMercuryZman.time);
	this.mercury_width = Math.ceil(k1*k2 +3);
		
	$('#stmercury').css('width', this.mercury_width + 'px');
}
SmallTermometr.prototype.adjustMercury = SmallTermometr_adjustMercury;

function SmallTermometr_moveMercury() {
	this.mercury_pos = this.term_hour + this.term_minute/60;
	if (this.checkChangeParam() == true) 
		return;
	this.adjustMercury();
}
SmallTermometr.prototype.moveMercury = SmallTermometr_moveMercury;

function SmallTermometr_checkChangeParam() {
	if (this.mercury_pos > stzmanim.zmanim[stzmanim.get_zman_key_by_keyword ("hatzot2")].time) {
			//alert (this.mercury_pos +'/'+ stzmanim.zmanim[stzmanim.get_zman_key_by_keyword ("hatzot2")].time)
			var TermDate = new Date (this.term_year, this.term_month - 1, this.term_date, 1, 1, 1);
			var NewDate = new Date (TermDate.getTime() + 24*60*60*1000);
			this.term_hour -=24;
			RenewSmTerm(this.city, NewDate.getDate(), NewDate.getMonth() + 1, NewDate.getFullYear());
			return true;
	} else if (this.mercury_pos < stzmanim.zmanim[stzmanim.get_zman_key_by_keyword ("hatzot1")].time) {
			//alert (this.mercury_pos +'/'+ stzmanim.zmanim[stzmanim.get_zman_key_by_keyword ("hatzot1")].time)
			var TermDate = new Date (this.term_year, this.term_month - 1, this.term_date, 1, 1, 1);
			var NewDate = new Date (TermDate.getTime() - 24*60*60*1000);
			this.term_hour +=24;
			RenewSmTerm(this.city, NewDate.getDate(), NewDate.getMonth() + 1, NewDate.getFullYear());
			return true;
	}
	return false;
}
SmallTermometr.prototype.checkChangeParam = SmallTermometr_checkChangeParam;
