function preloadImage(path)
{
	Img = new Image;
	Img.src = path;
}


// интересно, а я единственный в мире человек,
// которого волнует порядок загрузки изображений?
preloadImage('/i/bg.jpg');
preloadImage('/i/sky.jpg');


preloadImage('/i/menu-1-bot.jpg');
preloadImage('/i/menu-2-bot.jpg');
preloadImage('/i/menu-3-bot.jpg');




var imgPath = '/images/';
var inStop = [];
var outStop = [];
var selected = '';
var auto = 1;



function showReflection(id)
{
	bg = document.getElementById('ref'+id);
	bg.style.backgroundImage = 'url(\'' + '/i/menu-'+id+'-bot.jpg' + '\')';
}

function hideReflection(id)
{
	bg = document.getElementById('ref'+id);
	bg.style.backgroundImage = '';
}



function chillin(layerID, mcall)
{
		if (inStop[layerID])
		{
			inStop[layerID] = 0;
		}
		else if (document.getElementById(layerID).filters) if (document.getElementById(layerID).filters.alpha)
		{
			if (navigator.appVersion.indexOf('MSIE 6.0') > 0)
			{
				if (document.getElementById(layerID).filters.alpha.opacity < 100)
				{
					document.getElementById(layerID).filters.alpha.opacity += 15;
					setTimeout('chillin(\''+layerID+'\', 0)', 1);
				} else { outStop[layerID] = 0; }
			} else if (mcall) document.getElementById(layerID).style.filter = 'alpha(opaticy=100)';
		}
}

function chillout(layerID, mcall)
{
		if (outStop[layerID])
		{
			outStop[layerID] = 0;
		}
		else if (document.getElementById(layerID).filters) if (document.getElementById(layerID).filters.alpha)
		{
			if (navigator.appVersion.indexOf('MSIE 6.0') > 0)
			{
				if (document.getElementById(layerID).filters.alpha.opacity >= 50)
				{
					document.getElementById(layerID).filters.alpha.opacity -= 10;
					setTimeout('chillout(\''+layerID+'\', 0)', 5);
				} else { inStop[layerID] = 0; }
			}
		}
}

function imgClick(obj, forceCall)
{
	if (!forceCall) auto = 0;
	if (selected != obj.id)
	{
		if (navigator.appName == 'Microsoft Internet Explorer') obj.style.cursor = 'default';
		if (selected) chillout(selected);
		if (obj.filters) if (obj.filters.alpha)
		{
			if (navigator.appVersion.indexOf('MSIE 6.0') > 0) obj.filters.alpha.opacity = '100';
			else chillin(obj.id, 1);
		}
		selected = obj.id;
		document.getElementById('view').src = imgPath+obj.id+'.jpg';
	}
	return false;
}

function imgOver(obj)
{
	if (selected != obj.id) if (navigator.appName == 'Microsoft Internet Explorer') obj.style.cursor = 'hand';
	outStop[obj.id] = 1;
	inStop[obj.id] = 0;
	chillin(obj.id, 0);
}

function imgOut(obj)
{
	if (navigator.appName == 'Microsoft Internet Explorer') obj.style.cursor = 'default';
	outStop[obj.id] = 0;
	inStop[obj.id] = 1;
	if (obj.id != selected) chillout(obj.id, 0);
}

function autoGallery(id)
{
	if (id > imgcount) id = 1;
	if (auto)
	{
		if (id) imgClick(document.getElementById('img'+id), 1);
		else id = 1;
		setTimeout('autoGallery('+(id+1)+')', 10000);
		preloadImage(imgPath+'img'+(id+1)+'.jpg');
	}
}

var curI;


function ShowPhoto(path,width,height)
{
	for (i=1; i<=fnames.length; i++)
	{
		if (fnames[i]==path) curI=i;
	}
	
	tl = document.getElementById('ToLeft');
	tr = document.getElementById('ToRight');
	tli = document.getElementById('ToLeftImg');
	tri = document.getElementById('ToRightImg');
	
	if ((curI-1)!=0)
	{	
	tli.innerHTML = '<img src="/img/.gif" width="17" height="33" onMouseOver=ActiveArrow("l",1) onMouseOut=ActiveArrow("l",0) onclick=ShowPhoto("'+fnames[(curI-1)]+'",'+fwidths[(curI-1)]+','+fheights[(curI-1)]+')>';
	tl.style.marginLeft = -(Math.round(width/2)+40)+'px';
	tli.style.marginLeft = -(Math.round(width/2)+40)+'px';
	tl.style.display = 'block';
	tl.style.marginTop = -26 + document.documentElement.scrollTop + 'px';
	tli.style.display = 'block';
	tli.style.marginTop = -26 + document.documentElement.scrollTop + 'px';
	} else
		{
			tl.style.display = 'none';
			tli.style.display = 'none';
		}
	
	if ((curI+1)<fnames.length)
	{
	tri.innerHTML = '<img src="/img/.gif" width="17" height="33"  onMouseOver=ActiveArrow("r",1) onMouseOut=ActiveArrow("r",0) onclick=ShowPhoto("'+fnames[(curI+1)]+'",'+fwidths[(curI+1)]+','+fheights[(curI+1)]+')>';
	tr.style.marginLeft = (Math.round(width/2)+75)+'px';
	tri.style.marginLeft = (Math.round(width/2)+75)+'px';
	tr.style.display = 'block';
	tr.style.marginTop = -16 + document.documentElement.scrollTop + 'px';
	tri.style.display = 'block';
	tri.style.marginTop = -16 + document.documentElement.scrollTop + 'px';
	} else
		{
			tr.style.display = 'none';
			tri.style.display = 'none';
		}
	
				
	view = document.getElementById('ViewPhoto');
	vd = document.getElementById('Vdiv');
	foto = document.getElementById('Fotka');
	foto.innerHTML = '<img src="'+path+'" onclick="HidePhoto();">';
	view.style.width = width + 'px';
	vd.style.width = width + 'px';
	view.style.height = height + 30 + 'px';
	view.style.marginLeft = -Math.round(width/2) + 'px';
	view.style.marginTop = -Math.round(height/2) - 35 + document.documentElement.scrollTop + 'px';
	view.style.display = 'block';
}

function HidePhoto()
{
	tl = document.getElementById('ToLeft');
	tr = document.getElementById('ToRight');
	tr.style.display = 'none';
	tl.style.display = 'none';
	tli = document.getElementById('ToLeftImg');
	tri = document.getElementById('ToRightImg');
	tri.style.display = 'none';
	tli.style.display = 'none';
	view = document.getElementById('ViewPhoto');
	view.style.display = 'none';
}


function checkEmpty (val){
	if (val=="" || val.search(/[^\s]+/)==-1) {
		return false;
	}
	return true;
}

function RestoreColor()
	{
	document.MessageForm.name.style.background="#F7F3F7";	
	document.MessageForm.content.style.background="#F7F3F7";	
	}

function SubmitMessage()
{
	sm=true;
	if (!checkEmpty(document.MessageForm.name.value)) 
		{
	document.MessageForm.name.style.background="#FE8CAE";
	sm=false;	
		}
	if (!checkEmpty(document.MessageForm.content.value)) 
		{
	document.MessageForm.content.style.background="#FE8CAE";
	sm=false;	
		}
	if (sm==true) {document.MessageForm.submit();}		
}

function RestoreColor1()
	{
	document.MessageForm.name.style.background="#F7F3F7";	
	document.MessageForm.phone.style.background="#F7F3F7";	
	}

function SubmitMessage1()
{
	sm=true;
	if (!checkEmpty(document.MessageForm.name.value)) 
		{
	document.MessageForm.name.style.background="#FE8CAE";
	sm=false;	
		}
	if (!checkEmpty(document.MessageForm.phone.value)) 
		{
	document.MessageForm.phone.style.background="#FE8CAE";
	sm=false;	
		}
	if (sm==true) {document.MessageForm.submit();}		
}

function ActiveArrow(a,on)
	{
	}
