// JavaScript Document

function ImgChange (imId, imgSrc){

	if (document.images){
		var img = document.images[imId].src = imgSrc;
	}
	else document.getElementById(imId).src = imgSrc;
}

function BigImg(name,x,y) {
	var win = window.open('','_blank',"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width="+x+",height="+y);
	win.document.open("text/html");
	with (win.document) {
	    write("<html><head><title>Домовой</title><script language='JavaScript'>self.focus()</script></head><body bgcolor='#FFFFFF' leftmargin=0 topmargin=0 marginheight=0 marginwidth=0><a href='#' onclick='window.close()'><img src='images/shems/big/"+name+"'");
	    write(" alt='закрыть' border='0'></a></body></html>");
	    close();
 }
}

//date functions 
var myDate=20;
var myMonth=5;
var myHour = 10;
var myMin = 0;
var mySec = 0;
var month1;
var data1;

function myFunction1(){
	if (date<=myDate) month1=12-(month-myMonth);
	else month1=11-(month-myMonth);
}

function myFunction2(){
	if (date>myDate) month1=(myMonth-month-1)
	else month1=(myMonth-month);
}

function myFunction3(){
	if (date<=myDate) month1=0;
	else month1=11;
}

function myFunction4(){

	switch (month) {
		case 2 : 
			date1 = (28-date+myDate);
			break;
		case 4, 6, 9, 11 : 
			date1 = (30-date+myDate);
			break;
		default : 
			date1=31-date+myDate;
	} 
}

function ShowTime(){
	dateObj = new Date();
	date = dateObj.getDate();
	month = dateObj.getMonth() + 1;
	hour = dateObj.getHours();
	minutes = dateObj.getMinutes();
	sec = dateObj.getSeconds();

	if (month>myMonth) myFunction1();
	else if (month<myMonth) myFunction2();
	else myFunction3();

	if (date<=myDate) 
		date1=(myDate-date)
	else myFunction4();

	var insec = hour*60*60 + minutes*60 + sec;
	var myInsec = myHour*60*60 + myMin*60 + mySec;

	if(insec > myInsec){
		date1--;
		insec1 = (24*3600 + myInsec) - insec;
	}
	else insec1 = myInsec - insec;

	hour1 = Math.floor(insec1/3600);
	min1 = Math.floor((insec1 - 3600*hour1)/60);
	sec1 = insec1 - 3600*hour1 - 60*min1;

	monthtxt=("месяцы");

	datetxt=("сутки");

	document.getElementById('timer').innerHTML = '';

	//if (month1>0) document.getElementById('timer').innerHTML += monthtxt + " " + month1 + "<br>";
	//else document.getElementById('timer').innerHTML += "";

	if (date1>0) document.getElementById('timer').innerHTML += datetxt + " " + date1 + "<br>";
	else document.getElementById('timer').innerHTML += "";

	if(hour1 < 10) hour1 = '0' + hour1;
	if(min1 < 10) min1 = '0' + min1;
	if(sec1 < 10) sec1 = '0' + sec1;
	
	hourTxt = "часы";
	minTxt = "минуты";
	secTxt = "секунды";

	document.getElementById('timer').innerHTML += hourTxt + ': ' + hour1 + '<br>';
	document.getElementById('timer').innerHTML += minTxt + ': ' + min1 + '<br>';
	document.getElementById('timer').innerHTML += secTxt + ': ' + sec1;

	setTimeout("ShowTime()",1000);

}

/*var dateObj = (new Date()).getDate();
var date = dateObj.getDate();
var month = dateObj.getMonth() + 1;
var hour = dateObj.getHours();
var minutes = dateObj.getMinutes();
var sec = dateObj.getSeconds();*/
